Hi Hardy,
I have been trying and I got something,
this is my analyzer definition:
Code:
@AnalyzerDef(name = "synonymFilter",
charFilters = {
@CharFilterDef(factory = MappingCharFilterFactory.class, params = { @Parameter(name = "mapping", value = "mapping-chars.properties") }) },
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = StopFilterFactory.class, params = {
@Parameter(name = "words", value = "stoplist.properties"),
@Parameter(name = "ignoreCase", value = "true")
}
),
@TokenFilterDef(factory = SynonymFilterFactory.class, params = {
@Parameter(name = "synonyms", value = "synonyms.txt"),
@Parameter(name = "ignoreCase", value = "true")
})
}
)
And, as you said my query is like this one. Basically, i use the synonym analyzer to parse the terms.
Code:
Analyzer analyzer = Search.getFullTextSession(session).getSearchFactory().getAnalyzer("synonymFilter");
BooleanQuery[] Querys = new BooleanQuery[campos.length];
int cont = 0;
while(cont < fields.length)
{
BooleanQuery andQuery = new BooleanQuery();
TokenStream tokenStream = analyzer.tokenStream(campos[cont], new StringReader(q));
CharTermAttribute charTermAttribute = tokenStream.getAttribute(CharTermAttribute.class);
while (tokenStream.incrementToken())
{
String term = charTermAttribute.toString();
andQuery.add(new TermQuery(new Term(campos[cont], term)), Occur.MUST);
}
Querys[cont] = andQuery;
cont++;
}
Next point, I have in my synonyms.txt the next line
Code:
#Equivalent synonyms may be separated with commas and give
#no explicit mapping. In this case the mapping behavior will
#be taken from the expand parameter in the schema. This allows
#the same synonym file to be used in different synonym handling strategies.
#Examples:
ipod, i-pod, i pod
foozball , foosball, lobos
And it creates a query like this one:
(+titulo.titulo:foozball +titulo.titulo:foosball +titulo.titulo:lobos)
(AND operator)But what i really need is this (titulo.titulo:foozball titulo.titulo:foosball titulo.titulo:lobos)
(OR operator)Any ideas?
PD:I just want to show how the synonym query works in case anybody does not know how to implement it :)
Edited: I have changed the parameter expand = true/false and i need expand = true but it keeps using AND operator...
Edited 2: I have changed my query using should instead of must and now it seems to be working fine
Thanks in advance!