Incorrect torch results with special characters in the facet field

I implemented Solr Search and Faceting for e-commerce stores and addressed a problem with a facet filter facet. This happens only when we have a special character (i.e., a Bracket) in the face field, otherwise everything works fine.

I implemented this using SolrNet. I checked the execution of raw requests in Solr directly and found that this problem could be in Solr itself and not related to SolrNet.

Example:

I have a number of products and filters, for example:

RAM (GB) 2 GB 4 GB 8 GB Memory (GB) 4 GB 8 GB 16 GB 

Each of the facet options has some products in it, so the problem is not that facet.min is being calculated. And I also applied tagging.

Now, one of these aspects works fine, while the other doesn't seem to work with a bracket in the face field.

Here is my diagram where I define facet fields.

 <dynamicField name="f_*" type="string" indexed="true" stored="true" multiValued="true" required="false" /> <dynamicField name="pa_*" type="string" indexed="true" stored="true" multiValued="true" required="false" /> 

Facet works fine when I request a field starting with pa_ but not f_.

The request I am making in Solr is:

 ../select?indent=on&wt=json&facet.field={!ex%3Dpa_RAM(GB)}pa_RAM(GB)&fq={!tag%3Dpa_RAM\(GB\)}pa_RAM\(GB\):2%2BGB&q=CategoryID:(1+OR+2+OR+3+OR+4)&start=0&rows=10&defType=edismax&facet.mincount=1&facet=true&spellcheck.collate=true 

Image1 enter image description here

This works fine as expected.

Another request:

 ../select?indent=on&wt=json&facet.field={!ex%3Df_Memory(GB)}f_Memory(GB)&fq={!tag%3Df_Memory\(GB\)}f_Memory\(GB\):4%2BGB&q=CategoryID:(1+OR+2+OR+3+OR+4)&start=0&rows=10&defType=edismax&facet.mincount=1&facet=true&spellcheck.collate=true 

It gives the following result:

Image 2 enter image description here

This does not work. However, if I remove the special character from the queries and indexed data, this works fine.

In addition, the returned facet option is the one on which I added the filter tag. All other facet options are not returned by Solr.

I can’t understand why this is happening and how to fix it.

Any clue \ idea will be great!

Please refer to this request and images (this is not the right way or ideal solution)

 ../select?indent=on&wt=json&facet.field={!ex%3Df_Memory(GB)}f_Memory(GB)&fq={!tag%3Df_Memory(GB)}f_Memory\(GB\):4%2BGB&q=CategoryID:(1+OR+2+OR+3+OR+4)&start=0&rows=10&defType=edismax&facet.mincount=1&facet=true&spellcheck.collate=true&fl=Id,Name,f_Memory(GB) 

enter image description here

Link Link: Local parameters for the fighting game

Please help me!

+5
source share
1 answer
  • Special characters in SOLR queries ( q and fq ) must be escaped if you need to search for them literally, otherwise queryParser will take on their special meaning. (See "Resetting Special Characters" in the SOLR Documentation

    In the + example, the character is not escaped in fq :

     {!tag=f_Memory\(GB\)}f_Memory\(GB\):4+GB 
  • These screening rules do not apply to local parameters , i.e. all between {! and } .

    In this example, you escaped ( and ) in the tag label. Thus, the label defined as {!tag=f_Memory\(GB\)} in the filter differs from the label specified in {!ex=f_Memory+(GB)} in the face field, so the filter is not excluded during cutting, and for face creation uses only relevant documents.

You should write a filter like:

 {!tag=f_Memory(GB)}f_Memory\(GB\):4\+GB 

and facet like

 {!ex=f_Memory+(GB)}f_Memory+(GB) 

to get what you are looking for.

An example of a complete valid query:

 ../select?indent=on&wt=json&facet.field={!ex%3Df_Memory(GB)}f_Memory(GB)&fq={!tag%3Df_Memory(GB)}f_Memory\(GB\):4\%2BGB&q=CategoryID:(1+OR+2+OR+3+OR+4)&start=0&rows=10&defType=edismax&facet.mincount=1&facet=true&spellcheck.collate=true 

A simple real example that I tested locally:

This is the data in the kernel:

Request:

  http://localhost:8983/solr/test/select?q=*%3A*&fl=id%2Cf_*%2Cpa_*&wt=json&indent=true 

Answer:

 { "responseHeader": { "status": 0, "QTime": 1, "params": { "q": "*:*", "indent": "true", "fl": "id,f_*,pa_*", "wt": "json", "_": "1474529614808" } }, "response": { "numFound": 2, "start": 0, "docs": [ { "id": "1", "f_Memory(GB)": [ "4+GB" ], "pa_RAM(GB)": [ "2+GB", "4GB", "8GB" ] }, { "id": "2", "f_Memory(GB)": [ "8+GB" ], "pa_RAM(GB)": [ "4GB" ] } ] } } 

Work cut:

Request:

 http://localhost:8983/solr/test/select?q=*%3A*&fq=%7B!tag%3Df_Memory(GB)%7Df_Memory%5C(GB%5C)%3A4%5C%2BGB&fl=id%2Cf_*%2Cpa_*&wt=json&indent=true&facet=true&facet.field=%7B!ex%3Df_Memory(GB)%7Df_Memory(GB) 

Answer:

 { "responseHeader": { "status": 0, "QTime": 2, "params": { "q": "*:*", "facet.field": "{!ex=f_Memory(GB)}f_Memory(GB)", "indent": "true", "fl": "id,f_*,pa_*", "fq": "{!tag=f_Memory(GB)}f_Memory\\(GB\\):4\\+GB", "wt": "json", "facet": "true", "_": "1474530054207" } }, "response": { "numFound": 1, "start": 0, "docs": [ { "id": "1", "f_Memory(GB)": [ "4+GB" ], "pa_RAM(GB)": [ "2+GB", "4GB", "8GB" ] } ] }, "facet_counts": { "facet_queries": {}, "facet_fields": { "f_Memory(GB)": [ "4+GB", 1, "8+GB", 1 ] }, "facet_dates": {}, "facet_ranges": {}, "facet_intervals": {}, "facet_heatmaps": {} } } 
0
source

All Articles