Search code examples
solrfacetfaceted-search

Solr 7.5 Limiting Facet with certain terms can not order by count?


I would like to facet location.authorIds field on Solr table authors, but also limit facet with certain terms.

I did this, just like in the Solr 7.5 tutorials, http://lucene.apache.org/solr/guide/7_5/faceting.html, but the results returned from Solr did not sort on count, does anyone knows why?

Here is my Solr query:

http://127.0.0.1:8080/solr/authors/select?q=*:*&fl=handle&fq=search.resourcetype:2&start=0&rows=0&facet.field={!terms=27J001,J027,J132,J107,J225,J141,J092,J191,J224,J198,J062,J051,J143,J208,J119,J031,J057,J030,J134,J144,J158,J058,J181,J222,J153,J002,J203,J012,J045,J014,J186,J011,J064,J065,J147,J112,J192,J167,J066,J135,J096,J082,J075,J009,J193,J217,J168,J121,J059,J034,J213,J148,J169,J133,J013,J161,J093,J097,J162,J021,J170,J171,J083,J187,J178,J077,J194,J078,J098,J067,J047,J052,J172,J005,J113,J079,J099,J114,J100,J115,J068,J173,J084,J214,J101,J060,J025,J122,J195,J188,J196,J116,J102,J159,J197,J029,J094,J123,J053,J043,J189,J124,J015,J085,J174,J004,J044,J182,J088,J007}location.authorIds&facet=true&facet.sort=count

Here is the results, you can see it is not sorted by count.

enter image description here


Solution

  • After I did a testing and debugging the code, I could clearly see, that it’s a bug in the code.

    org.apache.solr.request.SimpleFacets#getListedTermCounts
    
    for (String term : terms) {    
          int count = searcher.numDocs(ft.getFieldQuery(null, sf, term), parsed.docs);
          res.add(term, count);
    }
    

    Which is clearly wrong, since it’s just iterate over the list and providing counts in exact order of what you specified in the query parameters.

    I’ve created a Solr issue - https://issues.apache.org/jira/browse/SOLR-13156 - and provided the patch. It was committed and will be available in Solr soon