Recently I have started using Lucene. However, after few days I’ve spotted that queries provided by me in form of Strings are converted by Lucene to more general ones.
Example:
MY QUERY: "want to go" (including " as I'm searching whole phrases)
QUERY OBJECT created from my query (.toString): text:"want ? go"
NUMBER OF RESULTS for texts:
I want to go out today -> 1 result - correct
I want sdfto go out today -> 1 result - incorrect, should be 0
I wanted to match execly phrase “want to go” and not “want whatever go”. I noticed that only words “to” and “a” are replaced with “?”.
My question is why Lucene is changing queries provided by me, and how to force Lucene to ask my queries (unchanged)?
Moreover, I’m using StandardAnayzer (indexing and quering).
tois a stop word, meaning it is not indexed and not searched by some analyzers [including StandardAnalyzer], because it is usually not useful for searching. if you don’t want it to be ‘stopped’ you will need to use a different analyzer [both for indexing and searching], but it will probably have worth results.You can also remove the word ‘to’ from the field STOP_WORDS
IMPORTANT: your indexing analyzer and searching analyzer should be consistent, including the STOP_WORDS field!