Hi Timo!
There is no built-in way in Lucene to achieve this. I have done a simple
implementation with a patched FuzzyQuery for each term. A new method
(bestOrderRewrite) returns a ordered list of all fuzzy terms that indeed exist in
index. There is no guarantee that the suggested term is spelled correct though...
Basically this works best when search is done on one term only.
Search code is something like this:
// on no_hits
cquery = cquery.rewrite(reader);
if (cquery instanceof TermQuery) {
// if search contained only one term this is a TermQuery instance
FuzzyQuery fquery = new FuzzyQuery(new Term("contents",
cquery.toString("contents")));
TermQuery[] terms = fquery.bestOrderRewrite(reader);
if (terms.length > 0) {
StringBuffer alts = new StringBuffer();
alts.append("Did you mean ").append(terms[0].getTerm().text());
}
} else if (cquery instanceof BooleanQuery) {
// split queries
// <snip>
BooleanClause[] clauses = ((BooleanQuery)cquery).getClauses();
// get suggestion for each term
if (clauses[i].required) {
FuzzyQuery fquery = new FuzzyQuery(new Term("contents",
clauses[i].query.toString("contents")));
TermQuery[] terms = fquery.bestOrderRewrite(reader);
// ...
}
// </snip>
} // and so on...
Regards,
Ronnie
>On Thursday 12 February 2004 00:15, Matt Tucker wrote:
>> We implemented that type of system using a spelling engine by Wintertree:
>>
>> http://www.wintertree-software.com
>>
>> There are some free Java spelling packages out there too that you could
>> likely use.
>
>But this does not ensure that the word really exists in the index. The word
>google does propose however to exist.
>
>Regards
>Timo
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]