I'm trying to use this analyzer using annotations as suggested in Hibernate Search in action.
The problem is that the lucene query I obtain from hitory (e.g. a mispell of history) is
Code:
title:hitory authors:hitory subject:hitory isbn:hitory publisher:hitory titleNGram:"hit ito tor ory"
to work properly (and it does, as testing it in luke proved) should be:
Code:
title:hitory authors:hitory subject:hitory isbn:hitory publisher:hitory titleNGram:hit ito tor ory
without the
".
this is the Analyzer definition:
Code:
@AnalyzerDef(
name=Book.NGRAM_ANALYZER,
tokenizer=@TokenizerDef(factory=StandardTokenizerFactory.class),
filters={
@TokenFilterDef(factory=NGramFilterFactory.class,
params={
@Parameter(name="minGramSize",value="3"),
@Parameter(name="maxGramSize",value="3")
}),
@TokenFilterDef(factory=StandardFilterFactory.class),
@TokenFilterDef(factory=LowerCaseFilterFactory.class)
// @TokenFilterDef(factory=StopFilterFactory.class,
// params={
// @Parameter(name="words",value="stopwords.txt"),
// @Parameter(name="ignoreCase", value="true")
// }),
})
This is the query code.
Code:
public List<Book> fullTextSearchBooks(String searchQuery){
FullTextSession ftSession = Search.getFullTextSession(hibernateTemplate.getSessionFactory().getCurrentSession());
String[] productFields = {"title", "authors","subject","isbn","publisher","titleNGram"};
Analyzer analyzer = ftSession.getSearchFactory().getAnalyzer(Book.class);
QueryParser parser = new MultiFieldQueryParser(
productFields,
analyzer);
org.apache.lucene.search.Query luceneQuery;
try {
luceneQuery = parser.parse(searchQuery);
}
catch (ParseException e) {
throw new RuntimeException("Unable to parse query: " + searchQuery, e);
}
return (List<Book>)ftSession.createFullTextQuery(luceneQuery, Book.class).list();
}
How should I do to obtain the correct query?