简体   繁体   中英

How can I maintain the row mapping after sorting on facets? If I sort on 1 facet, other column values don't get sorted accordingly

I am new to SOLR and am trying to write a Query that contains some facets that are supposed to be linked together even after sorting.

For instance, my database contains id and name fields (along with other attributes). I have added 2 facetfields in my code as

sq.setFacet(true);
sq.setFacetMinCount(1);
sq.addFacetField(ID);
sq.addFacetField(NAME);

I need to do a sort on ID along with NAME. Currently, when I sort my query, it sorts ID and NAME separately in ascending order. I tried sorting on COUNT and INDEX but both sorts the fields separately.

My database table looks something like:

ID      NAME
1002    Spring
1001    Winter
1003    Summer

Results I get:

   BLOCK [1001(1),1002(1),1003(1)]
   BLOCK [Spring,Summer,Winter]

But as we see, the mapping between fields in the result is lost even though the sort works individually. I expect something like:

BLOCK[1001:Winter,1002:Spring,1003:Summer]

This will help me fetch the correct ID for respective NAME (and keep the proper row mapping for each entry in the table).

Is there a way I can maintain the row mapping even after sorting?

Thank you in advance!

Every facet order it's independent of others, so if you store the id and the name in separated fields, you can't assume that both are going to be in the same row. By count it will be the case only if the result number is different for each one. (so if you have 3 from summer, 2 for winter and 1 for spring, it will eventually have the same order in the 2 facets).

In your case I usually made one of these 2 things, store only the Id and get the name from the database, or actually, a hashtable cached in my app. The other one is to index the facet as the fields concatenated ex:WINTER|ID (Spring|1002) and spliting by "|" once again in the solr client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM