Instance of ResourceWatcherService


(Tobsucht) #1

I dont' get it: How do I get an instance of the ResourceWatcherService without using the @Inject annotation? I'm trying to implement updateable search-time synonyms and need an instance for the service. How can I obtain a reference before getAnalyzers() within the Plugin class is called, so that I can pass it to one of my custom analyzers.


(Ryan Ernst) #2

You can override the createComponents method on Plugin to get this. I recommend creating a service object which will handle the updates, and your synonym token filter and use the currently parsed synonyms from your service (letting the service update these in the background through the resource watcher). So you would have something like this:


private SetOnce<YourSynonymService> synonymService = new SetOnce<>();

@Override
public Collection<Object> createComponents(..., ResourceWatcherService resourceWatcherService, ...) {
    synonymService.set(new YourSynonymService(resourceWatcherService));
    return Collections.singleton(synonymService.get());
}

@Override  
public Map<String, AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
    // note the SetOnce is passed here because analysis is initialized before createComponents is called
    return Collections.singletonMap("my-synonym-filter", new MyTokenFilterProvider(synonymService));
}

(Tobsucht) #3

Well, that saved me a lot of time. Thanks a lot!


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.