SOLR 'facet.prefix' is not working as expected

16 views Asked by At

I'm using facet.prefix feature in my solr query. but it seems not working as expected. my sample solr facet.prefix line as 'f. storeStockLevelSizes_string_mv.facet.prefix=123' and i'm anticipating that response inside the 'storeStockLevelSizes' facet should only contains the data which starts with 186 alone. But i'm seeing other data too which is not 123. any help is much appreciated.

sample query is like below

yq=*:*&yab=...&q={!boost}(%2B{!lucene+v%3D$yq}+{!func+v%3D$yab})&fq=..&expand=true&expand.field=groupId_string&expand.rows=1000&
start=0&rows=36&json.facet.storeStockLevelSizes_string_mv{"type":"terms","field":"storeStockLevelSizes_string_mv","limit":-1,"mincount":1,"facet":{"groupCount":"unique(groupId_string)"},"domain":{"excludeTags":"fc"}}&json.facet.length_string_mv={"type":"terms","field":"length_string_mv","limit":100,"mincount":1,"facet":{"groupCount":"unique(groupId_string)"},"domain":{"excludeTags":"fc"}}&
json.facet.waist_string_mv={"type":"terms","field":"waist_string_mv","limit":100,"mincount":1,"facet":{"groupCount":"unique(groupId_string)"},"domain":{"excludeTags":"fc"}}&
facet.limit=500&
f.storeStockLevelSizes_string_mv.facet.limit=-1&
f.storeStockLevelSizes_string_mv.facet.prefix=123&
fl=score,code_string&wt=xml

the response should contains only the facet value which are starting with 123 with in the 'storeStockLevelSizes' facet. But i'm seeing other values too. My SOLR version is 8.11.3

1

There are 1 answers

0
Uday On

With JSONFacets are in place, we need to use the prefix and limit values with in the JSON facet itself like below

json.facet.storeStockLevelSizes_string_mv={"type":"terms","field":"storeStockLevelSizes_string_mv","limit":-1,"mincount":1,"domain":{"excludeTags":"fc"},"prefix":"123"}&

f.storeStockLevelSizes_string_mv.facet.prefix=123 works with traditional facet API based query creation, but not with JSONFacet API which is the latest version.

while adding the solr facet fields to solrquery, we need to make sure to add prefix also as one of the parameter. The implementation is not available with Out of the box class (FacetSearchQueryFacetsPopulator). Either you override the class and add your implementation or find other way to intercept and add the prefix piece.

refer SOLR API documentation for reference. https://solr.apache.org/guide/solr/latest/query-guide/json-facet-api.html