Reputation: 763
I'm working with lucene 6.4.1 and get an exception with an input which is containing an equals sign "=":
Caused by: INVALID_SYNTAX_CANNOT_PARSE: Syntax Error, cannot parse =:
at org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser.generateParseException(StandardSyntaxParser.java:1030)
at org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser.jj_consume_token(StandardSyntaxParser.java:912)
at org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser.Clause(StandardSyntaxParser.java:462)
at org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser.ModClause(StandardSyntaxParser.java:279)
at org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser.ConjQuery(StandardSyntaxParser.java:210)
at org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser.DisjQuery(StandardSyntaxParser.java:180)
at org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser.Query(StandardSyntaxParser.java:133)
at org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser.TopLevelQuery(StandardSyntaxParser.java:114)
at org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser.parse(StandardSyntaxParser.java:62)
at org.apache.lucene.queryparser.flexible.core.QueryParserHelper.parse(QueryParserHelper.java:245)
at org.apache.lucene.queryparser.flexible.standard.StandardQueryParser.parse(StandardQueryParser.java:159)
I know there is a was to escape lucene special characters with
QueryParser.escape(...)
but why not the equal sign? I'm looking for a flexible way to not escape it by any self written code.
Upvotes: 2
Views: 1030
Reputation: 33351
You are using the flexible StandardQueryParser (org.apache.lucene.queryparser.flexible.standard.StandardQueryParser), but are escaping using the classic QueryParser (org.apache.lucene.queryparser.classic.QueryParser). The equal sign is not part of the classic QueryParser syntax, and so is not escaped by QueryParser.escape
Upvotes: 2