How to look for a negative number in solr?

In solr, I want to find a single field with a negative number, for example nodeId: -1. in schema.xml, I defined it as follows: <field name = "nodeId" type = "int" indexed = "true" stored = "true" / ">

solr throws an error when using "nodeId: -1" to search as follows: org.apache.lucene.queryParser.ParseException: cannot parse "storeId: -1": encountered "-" "-" "on line 1, column 8 . One of the expected: "(" ... "*" ............... "[" ... "{" ......

I have to search with storeId: \ - 1 or storeId: "- 1" to get an answer.

Now the question is: Can I change any solr configuration files to search without any escape characters? Or another way to solve this problem without changing the Java code. Thanks.

+7
source share
2 answers

"-" is a special character for the query analyzer, which is used to designate some articles as prohibited. If you do not want to hide this character, you need to change your query parser.

You might want to try the raw parser : q={!raw f=nodeId}-1 , but it does not have any of the default query parser functions. In fact, the raw query parser allows you to run only simple queries.

+2
source

I personally think that it is better to escape inside your Java code - the best way. ClientUtils.escapeQueryChars will be the selected method.

+3
source

All Articles