如何在lucene.net上使用lucene-gosen分析仪?

时间:2014-11-28 14:29:59

标签: lucene lucene.net analyzer

请指导我如何使用日本分析仪(lucene-gosen)与Lucene.net。并且还建议我为Lucene.net提供一些支持日语的好分析器。

1 个答案:

答案 0 :(得分:1)

Lucene-Gosen分析仪似乎没有移植到Lucene.Net。您可以在github page上提出请求,也可以通过移植并提交拉取请求来帮助他们。

一旦该分析器存在并使用文章here - 使用他们的基本代码,只需更改分析器:

string strIndexDir = @"D:\Index";
Lucene.Net.Store.Directory indexDir = Lucene.Net.Store.FSDirectory.Open(new System.IO.DirectoryInfo(strIndexDir));
Analyzer std = new JapaneseAnalyzer(Lucene.Net.Util.Version.LUCENE_29); //Version parameter is used for backward compatibility. Stop words can also be passed to avoid indexing certain words
IndexWriter idxw = new IndexWriter(indexDir, std, true, IndexWriter.MaxFieldLength.UNLIMITED);     

//Create an Index writer object.
Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
Lucene.Net.Documents.Field fldText = new Lucene.Net.Documents.Field("text", System.IO.File.ReadAllText(@"d:\test.txt"), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED, Lucene.Net.Documents.Field.TermVector.YES);
doc.Add(fldText);

//write the document to the index
idxw.AddDocument(doc);

//optimize and close the writer
idxw.Optimize();
idxw.Close();
Response.Write("Indexing Done");