Question

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

Was it helpful?

Solution

Instead of

Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_29);

you can use

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

That way, behind the scenes you will be using English Stemmer. Remember to use the same analyzer during index time and search time to avoid confusions. When you use stemmer, in Lucene index you will have stored not the exact input words, but stemmed ones.

See Javadoc here for 2.9. In newer versions of Lucene, you have per-language analyzers like EnglishAnalyzer (better type safety, as you don't pass in the String, but the class name rather).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top