lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Earwin Burrfoot <ear...@gmail.com>
Subject Re: Synonym filter with support for phrases?
Date Wed, 22 Apr 2009 09:12:37 GMT
> Hello everyone,
>
> I'm looking for feedback and thoughts on the following problem (it's more of
> development than user-centered problem, hope the dev list is appropriate):
>
> - a token stream is given,
>
> - a set of "synonyms" is given, where synonyms are token sequences to be
> matched and token sequences to be added as synonyms.
>
> An example to make things clearer (apologies for lame synonyms). Given a set
> of synonyms like this:
>
> {"new", "york"} -> {
>        {"big", "apple"}},
>
> {"restaurant"}  -> {
>        {"diner"},
>        {"food", "place"},
>        {"full", "belly"}}
> }
>
> a token stream (I try to indicate positional information here):
>
> 0 | 1   | 2          | 3  | 4   | 5
> a | new | restaurant | in | new | york
>
> would be enriched to an index of (note overlapping tokens on the same
> positions):
>
> 0 | 1   | 2          | 3     | 4   | 5
> a | new | restaurant | in    | new | york
>  |     | diner      |       | big | apple
>  |     | food       | place |     |
>  |     | full       | belly |     |
>
> The point is for phrase queries to work for synonyms and for the original
> text (of course multi-word synonyms longer than the original phrase would
> overlap with the text, but this shouldn't be much of a worry).
>
> In the current Lucene's trunk there is a synonym filter, but its
> implementation is not really suitable for achieving the above. I wrote a
> token filter that implements the above functionality, but then I thought
> that synonyms would be something frequently dealt with so my questions are:
>
> a) are there any thoughts on how the above could be implemented using
> existing Lucene infrastructure (perhaps I missed something obvious),
>
> b) if (a) is not applicable, would such a token filter constitute a useful
> addition to Lucene?
Your synonyms will break if you try searching for phrases.
Building on your example, "food place in new york" will find nothing,
because 'place' and 'in' share the same position.

I've implemented multiword synonyms on my project, it works, but is
really hairy.
While building the index, I inject synonym group ids instead of actual
words, then I detect synonyms in queries and replace them with group
ids too. Hard part comes after that, you have to adjust
positionIncrements on syngroup id tokens, with respect to the longest
synonym contained in that group, then you have to treat overlapping
synonyms. When query rewrite is finished, I end up with a mixture of
Term/Phrase/MultiPhrase/SpanQueries :)

More correct approach is to index as-is and expand queries with actual
synonym phrases instead of ids, but then queries become really
humongous if you have any decent synonym dictionary (I have 20+ phrase
groups).

-- 
Kirill Zakharenko/Кирилл Захаренко (earwin@gmail.com)
Home / Mobile: +7 (495) 683-567-4 / +7 (903) 5-888-423
ICQ: 104465785

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message