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!
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.
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.
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).
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With