2
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_29);
IndexSearcher indexSearcher;
File file = new File("/sdcard/index/");
Directory indexDir = FSDirectory.open(file);
indexSearcher = new IndexSearcher(indexDir, true);
QueryParser parser = new QueryParser(Version.LUCENE_29, "DIG", analyzer);
Query query = parser.parse(mEdit.getText().toString());
ScoreDoc[] hits = indexSearcher.search(query, null, 1000).scoreDocs;    

Hi this is my code for lucene text searching in version 2.9.2. I want to write code for lucene snowball 2.9.2 so that if I will search text " game" then it will search document which contain "game" also it will search document for "games". Please tell me how to write the code for this. I'm able to search text in Lucene but I want do it for lucene snowball 2.9.2

4

1 回答 1

0

代替

Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_29);

您可以使用

Analyzer analyzer = new SnowballAnalyzer(Version.LUCENE_29, "English");

这样,您将在幕后使用English Stemmer。请记住在索引时间和搜索时间使用相同的分析器以避免混淆。当您使用词干分析器时,在 Lucene 索引中您将存储的不是确切的输入词,而是词干化词。

有关 2.9,请参见此处的 Javadoc。在较新版本的 Lucene 中,您拥有每种语言的分析器,例如EnglishAnalyzer(更好的类型安全性,因为您不传入String,而是传入类名)。

于 2011-12-15T15:27:32.753 回答