healthonnet/hon-lucene-synonyms — pull request #30 by softwaredoug (2013-09-26 19:24:20+00:00)
Title: Add synonyms.bag option

Synonyms.bag is an alternate, simpler form of query expansion using the synonyms generated from the analysis chain. Instead of taking the query "dog bite" and expanding it to:

> dog chomp
> hound bite
> hound chomp
canine familiaris chomp
canine familiaris bite

The synonyms simply get appended to the dismax query, and the generated synonym queries become

> chomp
hound
bite
canine familiaris

when "constructPhraseQueries" is set to true, the generated synonym queries become

> "chomp"
"hound"
"bite"
"canine familiaris"

which is desirable when synonyms expansion results in multiword phrases.

The advantage to synonyms.bag is improved performance. In some cases, with large queries and many synonyms, the default query expansion can grow extremely complex resulting in performance problems. Synonyms.bag simplifies this expansion dramatically.

The drawback is loss of positional information in the query string. Features such as pf2, pf3, etc that try parts of the query as phrases won't function as expected. By simply appending generated synonyms, position information within the query is not a useful indicator of phrases that were actually searched for.

Synonyms.bag is ideal for identifying entities/tags within queries and searching against tag-like fields. Positional information is not meaningful in these contexts, so simply searching a "bag" of synonyms makes a lot of sense.