lucene.net语音过滤器

时间:2012-09-21 10:52:58

标签: c# lucene.net phonetics

我正在尝试将文本数据存储到lucene。

搜索应该是拼音!

我应该在哪里添加语音过滤器?

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)

此致,Ingo

1 个答案:

答案 0 :(得分:2)

一种方法是实现将Analyzer添加到TokenStream链中,或直接使用TokenStream。

即:

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

PhoneticFilter替换为您实施的TokenFilter,并在搜索和索引时使用此功能。