Lucene.Net/SpellChecker - multi-word/phrase based auto-suggest

前端 未结 3 929
小鲜肉
小鲜肉 2021-02-04 22:18

I\'ve implemented Lucenet.NET on my site, using it to index my products which are theatre shows, tours and attractions around London.

I want to implement a \"Did you mea

3条回答
  •  执笔经年
    2021-02-04 23:04

    i've just recently implemented a phrase autosuggest system in lucene.net.

    basically, the java version of lucene has a shinglefilter in one of the contrib folders which breaks down a sentence into all possible phrase combinations. Unfortunately lucene.nets contrib filters aren't quite there yet and so we don't have a shingle filter.

    but, a lucene index written in java can be read by lucene.net as long as the versions are the same. so what i did was the following :

    created a spell index in lucene.net using the spellcheck.IndexDictionary method as laid out in the "did you mean" section of jake scotts link. please note that only creates a spelling index of single words, not phrases.

    i then created a java app that uses the shingle filter to create phrases of the text i'm searching and saves it in a temporary index.

    i then wrote another method in dotnet to open this temporary index and add each of the phrases as a line or document into my spelling index that already contains the single words. the trick is to make sure the documents you're adding have the same form as the rest of the spell documents, so i ripped out the methods used in the spellchecker code in the lucene.net project and edited those.

    once you've done that you can call the spellcheck.suggestsimilar method and pass it a misspelled phrase and it will return you a valid suggestion.

提交回复
热议问题