Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Special characters in Solr filter fq

I'm trying to filter with fq for fields having special characters, particularly parentheses. For example, given the document:

<result name="response" numFound="1" start="0">
  <doc>
    <arr name="town_snc">
      <str>Hartford (Connecticut)</str>
    </arr>
  </doc>
</result>

I want to do e.g. ?fq:town_snc=Hartford (Connecticut)

I'm not getting any results; I presume that the parentheses need to be escaped, but I was not able to find the escaping method.

Thank you!

like image 971
yitznewton Avatar asked Mar 10 '11 19:03

yitznewton


People also ask

What is FQ in Solr query?

The fq (Filter Query) ParameterThe fq parameter defines a query that can be used to restrict the superset of documents that can be returned, without influencing score. It can be very useful for speeding up complex queries, since the queries specified with fq are cached independently of the main query.

How do I find special characters in Solr?

xml file and find the solr. TextField that you are using. Ensure that you use WhitespaceTokenizerFactory as the tokenizer as shown above. \# => ALPHA @ => ALPHA \u0023 => ALPHA ie:- pointing to ALPHA only.

What is the difference between Q and FQ in Solr?

Standard solr queries use the "q" parameter in a request. Filter queries use the "fq" parameter. The primary difference is that filtered queries do not affect relevance scores; the query functions purely as a filter (docset intersection, essentially).

How do you escape special characters in Solr?

Solr queries require escaping special characters that are part of the query syntax. Special characters are: +, -, &&, ||, !, (, ), ", ~, *, ?, and : . To escape these characters, use a slash ( \ ) before the character to escape.


1 Answers

Using the "field" qparser allows you to not have to do any escaping:

fq={!field f=town_snc}Hartford (Connecticut)

Or you can use the normal lucene query parser and use double quotes (but then you must still escape some things like quotes)

fq=town_snc:"Hartford (Connecticut)"

Or you could use backslash escaping too (just remember to also escape the space).

http://wiki.apache.org/solr/SolrQuerySyntax

like image 76
Yonik Avatar answered Oct 04 '22 09:10

Yonik