|
You can inject an actual Analyzer instance through CompassSettings, by the way. You need to use the LocalCompasBean and not use the schema based configuration (it should be possible to add this to the schema based configuration as well, injection of instances to settings as references).
For example, LocalCompasBeans has a setSettings method, which accepts a Map<String, Object>. You can inject there a key with compass.engine.analyzer.myAnalyzer.type, and the value can be the actual Analyzer instance. Really the actual instance? I guess that means the analyzer has to be thread-safe then.
I'll give it a try, thanks Yea, this has been added as a feature and most components can be passed as actual instances to Compass using CompassSettings. Analyzers, in any case, must be thread safe.
This is actually a very nice feature and one that probably means you can close this issue.
Is it documented/blogged? But it does have limitations, eg, say I want to override the default analyzer with a StandardAnalyzer with no stop words and a synonym token-filter. In that case must I go back to compass XML or settings? I think I blogged about it. I am not sure about the documentation, I need to check, if it is not, I will document it. Compelx analyzers construction can always be done by injecting a LuceneAnalyzerFactory implementation for the default analyzer, and providing the filter yourself. The key under which you can inject and instance of the factory (or a class name): compass.engine.analyzer.default.factory.
|
A low-tech way might be: if the Compass instance is created by a Spring FactoryBean initially, then store the Spring app-context in Compass's CompassSettings, then in the custom analyzer implement CompassConfigurable and have the CompassSettings passed in when created. The analyzer then fetches the stored spring app-context and finds the beans it needs. Would that work?
A more Spring friendly way would be to be able to declare the analyzer as a spring bean (prototype scope, so it is created each time) with its dependencies injected by Spring and Compass gets it from Spring directly. This approach could of course be generalised so that Compass is not tied to spring - the analyzer-lookup strategy itself would need to be configurable.