7
votes

In solr I want to search one field with negative number like nodeId:-1. in schema.xml, I defined it like this: <field name="nodeId" type="int" indexed="true" stored="true" />

solr throws error when use "nodeId:-1" to search like this: org.apache.lucene.queryParser.ParseException: Cannot parse 'storeId:-1': Encountered " "-" "- "" at line 1, column 8. Was expecting one of: "(" ... "*" ... ... ... ... ... "[" ... "{" ... ...

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

now the question is : Can I modify any solr configration files to search without any escape characters? Or another way to resolve this problem without modify java code. Thanks.

2

2 Answers

3
votes

I personally think escaping properly inside your Java code is the better way. ClientUtils.escapeQueryChars would be the method of choice.

2
votes

"-" is a special character for the query parser, which is used to mark some clauses as prohibited. If you don't want to escape this character, you need to change your query parser.

You may want to give a try to the raw query parser: q={!raw f=nodeId}-1 but it has none of the features of the default query parser. Actually, the raw query parser only allows you to run pure term queries.