Main Overview Wiki Issues Forum Build Fisheye
Issue Details (XML | Word | Printable)

Key: CMP-460
Type: Improvement Improvement
Status: Open Open
Priority: Minor Minor
Assignee: Shay Banon
Reporter: janekk
Votes: 0
Watchers: 1

If you were logged in you would be able to see more operations.

Spring bean injection into Compass configured analyzer

Created: 19/Sep/07 05:28 PM   Updated: 22/Nov/08 01:56 PM
Component/s: Compass::Spring
Affects Version/s: None
Fix Version/s: None

 Description  « Hide
Currently it is hard to put Spring bean into Compass configured analyzer. A Spring bean injection into Compass configured analyzer would be usefull feature.

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Maurice Nicholson added a comment - 19/Nov/08 11:56 AM
I'd like to do this too.

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.

Shay Banon added a comment - 19/Nov/08 07:00 PM
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.

Maurice Nicholson added a comment - 20/Nov/08 03:51 AM
Really the actual instance? I guess that means the analyzer has to be thread-safe then.

I'll give it a try, thanks

Shay Banon added a comment - 20/Nov/08 04:28 AM
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.

Maurice Nicholson added a comment - 22/Nov/08 03:00 AM
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?

Shay Banon added a comment - 22/Nov/08 01:56 PM
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.