سؤال

I have a query that's something like this:

field1:"stuff" AND field2:"other"

When it's ran with lower case and it produces different results. So this query:

field1:"stuff" and field2:"other"

Where the 'and' is lowercase. I'm parsing the query with the classic QueryParser, and it doesn't complain (throw an exception) when parsing the lower cased 'and', but it does produce 'more' results. It's as if the 'and' might be a token that it's looking for, and so there are more results than the normal query with 2 clauses would produce?

How is Lucene syntax with 'and' cased wrong interpreted?

FYI, using Lucene 4.4 on Java 7 and Java 8.

هل كانت مفيدة؟

المحلول

The AND operator must be uppercase. A lowercase and will just be interpreted to be a search term, so the resulting query will be:

field1:"stuff" defaultfield:and field2:"other"

And if you are using StandardAnalyzer, the term and will be eliminated from the search as a stop word, so your effective query is:

field:"stuff" field2:"other"

which is equivalent to combining the two with an OR, instead of an AND.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top