0

I have a javascript variable (facet field 'source') is defined as

var source = {
    'www.abc.com/1/'  : 'ABC',
    'www.def.com/1/'  : 'DEF',
    'www.ghi.com/1/'  :'GHI',       
};

In the above example, ABC, DEF and GHI are used for displaying facet field values. So, urls such as www.abc.com will all be grouped under 'ABC' facet value, urls with www.def.com will all be grouped under 'DEF' facet value under facet field named "Source".

Actual problem: Now I have two urls which I want to be included under a single facet value 'GHI' like the one shown below

var source = {
    'www.abc.com/1/'  : 'ABC',
    'www.def.com/1/'  : 'DEF',
    'www.ghi.com/1/'  :'GHI', 
    'www.ghi.com/2/'  :'GHI',   //trying to add this    
};

The problem with the above is, it creates two facet values with same name 'GHI' under facet field 'Source'. I want urls of both forms 'www.ghi.com/1/' and 'www.ghi.com/2/' to be under a single facet value 'GHI'. So ideally on the front-end, there should be only one 'GHI' and when I click on that, it should list both urls 'www.ghi.com/1/' and 'www.ghi.com/2/'

0

1 Answer 1

2

I think that you are looking for a Map, which in JavaScript should be done like that:

var source = ['ABC', 'DEF', 'GHI'];

var urls = {};
urls['ABC'] = new Array();
urls['DEF'] = new Array();
urls['GHI'] = new Array();
urls['ABC'].push('www.abc.com/1/');
urls['DEF'].push('www.def.com/1/');
urls['GHI'].push('www.ghi.com/1/');
urls['GHI'].push('www.ghi.com/2/');

So, to get all URLS matching 'ABC', you would have:

var arrayOfABC = urls['ABC'];

To get the first entry of the array:

var url = urls['ABC'][0];
Sign up to request clarification or add additional context in comments.

10 Comments

Thanks for your response Jalayn. I still have the same problem. With the approach you mentioned it still creates two 'GHI' facet values - when i click on the first one it lists 'www.ghi.com/1/' and when i click on the second one, it lists 'www.ghi.com/2/'
is there any way to mention something like this in javascript? source ['www.ghi.com/1/', 'www.ghi.com/2/'] = 'GHI';
Check out my edit, is that what you want ? Now, in source['GHI'] you have an array of URLs
no, it did not work! it completely ignored 'GHI', under the facet field "Source", the two urls are directly displayed as 'www.ghi.com/1/' and 'www.ghi.com/2/' instead of 'GHI'
Glad to help, I'm sorry though, but I don't know apache solr or ajax/solr, maybe you could ask another question more specific to solr ? I'm sure somebody can answer this as there is a "solr" tag in Stack Overflow.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.