Hi!
I'm trying to use a SynonymFilterFactory together with a NGramFilterFactory (while indexing). During search I only use NGramFilterFactory in my analyzer. Here are my definitions:
Code:
@AnalyzerDef(
name="ngramanalyzer",
tokenizer = @TokenizerDef(factory=StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory=StandardFilterFactory.class),
@TokenFilterDef(factory=LowerCaseFilterFactory.class),
@TokenFilterDef(factory=ISOLatin1AccentFilterFactory.class),
@TokenFilterDef(factory=StopFilterFactory.class,
params = @Parameter(name="words",value="germanstopword.txt")),
@TokenFilterDef(factory=NGramFilterFactory.class,
params = { @Parameter(name="minGramSize", value="3"),
@Parameter(name="maxGramSize", value="3")})
}
),
@AnalyzerDef(
name="ngramanalyzer_index",
tokenizer = @TokenizerDef(factory=StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory=StandardFilterFactory.class),
@TokenFilterDef(factory=LowerCaseFilterFactory.class),
@TokenFilterDef(factory=ISOLatin1AccentFilterFactory.class),
@TokenFilterDef(factory=StopFilterFactory.class,
params = @Parameter(name="words",value="germanstopword.txt")),
@TokenFilterDef(factory=SynonymFilterFactory.class,
params = { @Parameter(name="synonyms", value="synonyms.txt"),
@Parameter(name="ignoreCase", value="true"),
@Parameter(name="expand", value="true")}
),
@TokenFilterDef(factory=NGramFilterFactory.class,
params = { @Parameter(name="minGramSize", value="3"),
@Parameter(name="maxGramSize", value="3")})
}
),
...
...
@Column(name = "prodname")
@Fields( {
@Field(index = Index.TOKENIZED),
@Field(index = Index.TOKENIZED,
name = "name_ngram",
store=Store.YES,
analyzer = @Analyzer(definition = "ngramanalyzer_index"))
})
private String name;
Indexing seems to work fine. When I define synonyms like "mikrowelle,microwelle" I got "cro|ell|ell|icr|ikr|kro|lle|lle|mic|mik|owe|row|row|wel|wel" in my index. But during query, I only get Entitys containing "mikrowelle".
Code:
ftem = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
Analyzer entityScopedAnalyzer = ftem.getSearchFactory().getAnalyzer("ngramanalyzer");
final QueryParser ngramParser = new QueryParser("name_ngram", entityScopedAnalyzer);
try {
Query ngramQuery = parser.parse(query.trim());
FullTextQuery hibQuery = ftem.createFullTextQuery(ngramQuery, SearchResult.class);
resultList = hibQuery.getResultList();
ngramQuery.toString() returns
Code:
name_ngram:"mik ikr kro row owe wel ell lle"
Any suggestions what goes wrong? Thanks in advance!
--
Titus