Search code examples
luceneanalysisstemming

Is there any example of how to do Post analysis stemming in lucene (version 8)


I am using Java and I have already analyzed my documents with a standardAnalyzer.

How can I stem the words that I get from textField with EnglishAnalyzer? (post analysis stemming)

For example if I type "Burger" or "Burgers" in the textField, I want to get results even if "Burger" as a term isn't indexed at all, but "Burgers" is.

This is an example of a field that I indexed with standardAnalyzer

name=(String)jsonObject.get("name");
doc.add(new TextField("name",name,  Field.Store.YES));

This is how i builded the query

indexdirectory = FSDirectory.open(indexDir);
indexreader = DirectoryReader.open(indexdirectory);

analyzer = new StandardAnalyzer();
indexsearcher = new IndexSearcher(indexreader);

QueryParser nameParser = new QueryParser("name", analyzer);
nameQuery = nameParser.parse(textField.getText().toLowerCase());

TopDocs topdocs = null;
topdocs = indexsearcher.search(nameQuery, 50);


Solution

  • I got it working by Analyzing my Documents with EnglishAnalyzer in the Indexing process (Pre analysis stemming) . In other words you have to use EnglishAnalyzer while you index your documents and while you are creating your Queries.