lucene.net phonetic filter

蓝咒 提交于 2020-01-15 04:32:26

问题


I am trying to store text data to lucene.

The search should be with phonetic!

Where should I add a phonetic filter?

Lucene.Net.Store.Directory dir =
FSDirectory.Open(new DirectoryInfo(Application.StartupPath + "\\Index"));

IndexReader indexReader = IndexReader.Open(dir, true);
Searcher indexSearch = new IndexSearcher(indexReader);
//IndexReader indexReader = IndexReader.Open(dir, true);
//Searcher indexSearch = new IndexSearcher(indexReader);
Analyzer analyzer = new Lucene.Net.Analysis.De.GermanAnalyzer();

//Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
var queryParser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29,"content", analyzer);
var query = queryParser.Parse(textBox1.Text+"~0.8");

Console.WriteLine("Searching for: " + query.ToString());
TopDocs resultDocs = indexSearch.Search(query, indexReader.MaxDoc());

Console.WriteLine("Results Found: " + resultDocs.TotalHits)

Regards, Ingo


回答1:


One way is to implement an Analyzer that adds it to the TokenStream chain, or use a TokenStream directly.

ie:

System.IO.TextReader someText = ....;
TokenStream phonetics = new PhoneticFilter(new LowerCaseFilter(new WhitespaceTokenizer(someText )));

Replace PhoneticFilter with the TokenFilter you implemented, and use this both at search and index time.



来源:https://stackoverflow.com/questions/12529126/lucene-net-phonetic-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!