Hi,
To use the mentioned
PerFieldAnalyzerWrapper approach you would have to build your analyzers progammatically. That's maybe not so nice. Thinking about it there is a even better solution using
@AnalyzerDiscriminator. Check the online documentation for this annotation. This annotation is only available since the lastest release of Search though.
Using this annotation you would your Photo entity would look like this:
Code:
@Indexed
@AnalyzerDef(name="analyzer",
tokenizer = @TokenizerDef(factory= StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = ISOLatin1AccentFilterFactory.class),
@TokenFilterDef(factory = StandardFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = {
@Parameter(name="language", value="English")
})
}
)
@ClassBridge(impl = TranslatingBridge.class, store=Store.YES, analyzer=@Analyzer(definition="analyzer"))
@AnalyzerDiscriminator(impl = MyDiscriminator.class)
@Entity
public class Photo {
...
}
In the implementation of the descriminator could look like this:
Code:
public class LanguageDiscriminator implements Discriminator {
public String getAnanyzerDefinitionName(Object value, Object entity, String field) {
if ( "titleEng".equals(field)) {
return "analyzer";
} else {
return null;
}
}
}
I think that would be the niceset solution. Give it a go and let us know if it works.
BTW, using a @PrePersist should work for the translation.
--Hardy