I am trying to support synonyms on the query side by doing
For example, the query "open webpage" can be expanded if the following
things are synonyms:
"open" | "go to"
This becomes the following: (I'm using both the stop word filter and the
Notice that "go to" became just "go", because apparently "to" is removed
by the stop word filter.
Interestingly, if you turn "go to webpage" into a phrase, you get "go ?
webpage", but if you turn "go to" into a phrase, you just get "go",
because apparently a trailing stop word in a PhraseQuery gets dropped.
(there would actually be no way to represent the gap currently because
it represents gaps implicitly via the position of the phrase tokens, and
if there is no second token, there's no way to implicitly indicate that
there is a gap there)
The above query then fails to match "go to webpage", because "go to
webpage" in the index tokenizes as "go _ webpage", and the query,
because it lost its gap, tried to only match "go webpage".
To try and work around that, I represent "go to" not as a phrase, but as
a SpanNearQuery, like this:
However, when I run that query, I get the following:
... and when I look up that GapSpans class in SpanNearQuery.java, I see:
I asked this question on the mailing list on May 14 and was directed to submit a bug here.
This issue is of relatively high priority for us, since this represents the most promising technique we have for supporting synonyms on top of Lucene. (since the SynonymFilter suffers serious issues wrt multi-word synonyms)