Internal: Flatten IndicesModule and add tests
The IndicesModule was made up of two submodules, one which handled registering queries, and the other for registering hunspell dictionaries. This change moves those into IndicesModule. It also adds a new extension point type, InstanceMap. This is simply a Map<K,V>, where K and V are actual objects, not classes like most other extension points. I also added a test method to help testing instance map extensions. This was particularly painful because of how guice binds the key and value as separate bindings, and then reconstitutes them into a Map at injection time. In order to gain access to the object which links the key and value, I had to tweak our guice copy to not use an anonymous inner class for the Provider. Note that I also renamed the existing extension point types, since they were very redundant. For example, ExtensionPoint.MapExtensionPoint is now ExtensionPoint.ClassMap. See #12783.
This commit is contained in:
parent
754c1b44e7
commit
2450e3ccc8
|
@ -125,9 +125,9 @@ public class ClusterModule extends AbstractModule {
|
|||
private final Settings settings;
|
||||
private final DynamicSettings.Builder clusterDynamicSettings = new DynamicSettings.Builder();
|
||||
private final DynamicSettings.Builder indexDynamicSettings = new DynamicSettings.Builder();
|
||||
private final ExtensionPoint.TypeExtensionPoint<ShardsAllocator> shardsAllocators = new ExtensionPoint.TypeExtensionPoint<>("shards_allocator", ShardsAllocator.class);
|
||||
private final ExtensionPoint.SetExtensionPoint<AllocationDecider> allocationDeciders = new ExtensionPoint.SetExtensionPoint<>("allocation_decider", AllocationDecider.class, AllocationDeciders.class);
|
||||
private final ExtensionPoint.SetExtensionPoint<IndexTemplateFilter> indexTemplateFilters = new ExtensionPoint.SetExtensionPoint<>("index_template_filter", IndexTemplateFilter.class);
|
||||
private final ExtensionPoint.SelectedType<ShardsAllocator> shardsAllocators = new ExtensionPoint.SelectedType<>("shards_allocator", ShardsAllocator.class);
|
||||
private final ExtensionPoint.ClassSet<AllocationDecider> allocationDeciders = new ExtensionPoint.ClassSet<>("allocation_decider", AllocationDecider.class, AllocationDeciders.class);
|
||||
private final ExtensionPoint.ClassSet<IndexTemplateFilter> indexTemplateFilters = new ExtensionPoint.ClassSet<>("index_template_filter", IndexTemplateFilter.class);
|
||||
|
||||
// pkg private so tests can mock
|
||||
Class<? extends ClusterInfoService> clusterInfoServiceImpl = InternalClusterInfoService.class;
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.common.geo;
|
||||
|
||||
import org.elasticsearch.common.Classes;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ShapesAvailability {
|
||||
|
@ -48,8 +46,5 @@ public class ShapesAvailability {
|
|||
JTS_AVAILABLE = xJTS_AVAILABLE;
|
||||
}
|
||||
|
||||
|
||||
private ShapesAvailability() {
|
||||
|
||||
}
|
||||
private ShapesAvailability() {}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,31 @@ import static com.google.common.base.Preconditions.checkState;
|
|||
* @since 2.0
|
||||
*/
|
||||
public final class ProviderLookup<T> implements Element {
|
||||
|
||||
// NOTE: this class is not part of guice and was added so the provder lookup's key can be acessible for tests
|
||||
public static class ProviderImpl<T> implements Provider<T> {
|
||||
private ProviderLookup<T> lookup;
|
||||
|
||||
private ProviderImpl(ProviderLookup<T> lookup) {
|
||||
this.lookup = lookup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
checkState(lookup.delegate != null,
|
||||
"This Provider cannot be used until the Injector has been created.");
|
||||
return lookup.delegate.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Provider<" + lookup.key.getTypeLiteral() + ">";
|
||||
}
|
||||
|
||||
public Key<T> getKey() {
|
||||
return lookup.getKey();
|
||||
}
|
||||
}
|
||||
private final Object source;
|
||||
private final Key<T> key;
|
||||
private Provider<T> delegate;
|
||||
|
@ -86,18 +111,6 @@ public final class ProviderLookup<T> implements Element {
|
|||
* IllegalStateException} if you try to use it beforehand.
|
||||
*/
|
||||
public Provider<T> getProvider() {
|
||||
return new Provider<T>() {
|
||||
@Override
|
||||
public T get() {
|
||||
checkState(delegate != null,
|
||||
"This Provider cannot be used until the Injector has been created.");
|
||||
return delegate.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Provider<" + key.getTypeLiteral() + ">";
|
||||
}
|
||||
};
|
||||
return new ProviderImpl<>(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,21 +31,18 @@ import java.util.*;
|
|||
* all extensions by a single name and ensures that extensions are not registered
|
||||
* more than once.
|
||||
*/
|
||||
public abstract class ExtensionPoint<T> {
|
||||
public abstract class ExtensionPoint {
|
||||
protected final String name;
|
||||
protected final Class<T> extensionClass;
|
||||
protected final Class<?>[] singletons;
|
||||
|
||||
/**
|
||||
* Creates a new extension point
|
||||
*
|
||||
* @param name the human readable underscore case name of the extension point. This is used in error messages etc.
|
||||
* @param extensionClass the base class that should be extended
|
||||
* @param singletons a list of singletons to bind with this extension point - these are bound in {@link #bind(Binder)}
|
||||
*/
|
||||
public ExtensionPoint(String name, Class<T> extensionClass, Class<?>... singletons) {
|
||||
public ExtensionPoint(String name, Class<?>... singletons) {
|
||||
this.name = name;
|
||||
this.extensionClass = extensionClass;
|
||||
this.singletons = singletons;
|
||||
}
|
||||
|
||||
|
@ -62,29 +59,30 @@ public abstract class ExtensionPoint<T> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Subclasses can bind their type, map or set exentions here.
|
||||
* Subclasses can bind their type, map or set extensions here.
|
||||
*/
|
||||
protected abstract void bindExtensions(Binder binder);
|
||||
|
||||
/**
|
||||
* A map based extension point which allows to register keyed implementations ie. parsers or some kind of strategies.
|
||||
*/
|
||||
public static class MapExtensionPoint<T> extends ExtensionPoint<T> {
|
||||
public static class ClassMap<T> extends ExtensionPoint {
|
||||
protected final Class<T> extensionClass;
|
||||
private final Map<String, Class<? extends T>> extensions = new HashMap<>();
|
||||
private final Set<String> reservedKeys;
|
||||
|
||||
/**
|
||||
* Creates a new {@link org.elasticsearch.common.util.ExtensionPoint.MapExtensionPoint}
|
||||
* Creates a new {@link ClassMap}
|
||||
*
|
||||
* @param name the human readable underscore case name of the extension poing. This is used in error messages etc.
|
||||
* @param extensionClass the base class that should be extended
|
||||
* @param singletons a list of singletons to bind with this extension point - these are bound in {@link #bind(Binder)}
|
||||
* @param reservedKeys a set of reserved keys by internal implementations
|
||||
*/
|
||||
public MapExtensionPoint(String name, Class<T> extensionClass, Set<String> reservedKeys, Class<?>... singletons) {
|
||||
super(name, extensionClass, singletons);
|
||||
public ClassMap(String name, Class<T> extensionClass, Set<String> reservedKeys, Class<?>... singletons) {
|
||||
super(name, singletons);
|
||||
this.extensionClass = extensionClass;
|
||||
this.reservedKeys = reservedKeys;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,13 +116,13 @@ public abstract class ExtensionPoint<T> {
|
|||
}
|
||||
|
||||
/**
|
||||
* A Type extension point which basically allows to registerd keyed extensions like {@link org.elasticsearch.common.util.ExtensionPoint.MapExtensionPoint}
|
||||
* A Type extension point which basically allows to registerd keyed extensions like {@link ClassMap}
|
||||
* but doesn't instantiate and bind all the registered key value pairs but instead replace a singleton based on a given setting via {@link #bindType(Binder, Settings, String, String)}
|
||||
* Note: {@link #bind(Binder)} is not supported by this class
|
||||
*/
|
||||
public static final class TypeExtensionPoint<T> extends MapExtensionPoint<T> {
|
||||
public static final class SelectedType<T> extends ClassMap<T> {
|
||||
|
||||
public TypeExtensionPoint(String name, Class<T> extensionClass) {
|
||||
public SelectedType(String name, Class<T> extensionClass) {
|
||||
super(name, extensionClass, Collections.EMPTY_SET);
|
||||
}
|
||||
|
||||
|
@ -153,18 +151,20 @@ public abstract class ExtensionPoint<T> {
|
|||
/**
|
||||
* A set based extension point which allows to register extended classes that might be used to chain additional functionality etc.
|
||||
*/
|
||||
public final static class SetExtensionPoint<T> extends ExtensionPoint<T> {
|
||||
public final static class ClassSet<T> extends ExtensionPoint {
|
||||
protected final Class<T> extensionClass;
|
||||
private final Set<Class<? extends T>> extensions = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Creates a new {@link org.elasticsearch.common.util.ExtensionPoint.SetExtensionPoint}
|
||||
* Creates a new {@link ClassSet}
|
||||
*
|
||||
* @param name the human readable underscore case name of the extension poing. This is used in error messages etc.
|
||||
* @param extensionClass the base class that should be extended
|
||||
* @param singletons a list of singletons to bind with this extension point - these are bound in {@link #bind(Binder)}
|
||||
*/
|
||||
public SetExtensionPoint(String name, Class<T> extensionClass, Class<?>... singletons) {
|
||||
super(name, extensionClass, singletons);
|
||||
public ClassSet(String name, Class<T> extensionClass, Class<?>... singletons) {
|
||||
super(name, singletons);
|
||||
this.extensionClass = extensionClass;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,4 +188,46 @@ public abstract class ExtensionPoint<T> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A an instance of a map, mapping one instance value to another. Both key and value are instances, not classes
|
||||
* like with other extension points.
|
||||
*/
|
||||
public final static class InstanceMap<K, V> extends ExtensionPoint {
|
||||
private final Map<K, V> map = new HashMap<>();
|
||||
private final Class<K> keyType;
|
||||
private final Class<V> valueType;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ClassSet}
|
||||
*
|
||||
* @param name the human readable underscore case name of the extension point. This is used in error messages.
|
||||
* @param singletons a list of singletons to bind with this extension point - these are bound in {@link #bind(Binder)}
|
||||
*/
|
||||
public InstanceMap(String name, Class<K> keyType, Class<V> valueType, Class<?>... singletons) {
|
||||
super(name, singletons);
|
||||
this.keyType = keyType;
|
||||
this.valueType = valueType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a mapping from {@param key} to {@param value}
|
||||
*
|
||||
* @throws IllegalArgumentException iff the key is already registered
|
||||
*/
|
||||
public final void registerExtension(K key, V value) {
|
||||
V old = map.put(key, value);
|
||||
if (old != null) {
|
||||
throw new IllegalArgumentException("Cannot register [" + this.name + "] with key [" + key + "] to [" + value + "], already registered to [" + old + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindExtensions(Binder binder) {
|
||||
MapBinder<K, V> mapBinder = MapBinder.newMapBinder(binder, keyType, valueType);
|
||||
for (Map.Entry<K, V> entry : map.entrySet()) {
|
||||
mapBinder.addBinding(entry.getKey()).toInstance(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,15 +19,18 @@
|
|||
|
||||
package org.elasticsearch.indices;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.apache.lucene.analysis.hunspell.Dictionary;
|
||||
import org.elasticsearch.action.update.UpdateHelper;
|
||||
import org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService;
|
||||
import org.elasticsearch.common.geo.ShapesAvailability;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.inject.SpawnModules;
|
||||
import org.elasticsearch.common.inject.multibindings.MapBinder;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.common.util.ExtensionPoint;
|
||||
import org.elasticsearch.index.query.*;
|
||||
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryParser;
|
||||
import org.elasticsearch.indices.analysis.HunspellService;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.indices.cache.query.IndicesQueryCache;
|
||||
import org.elasticsearch.indices.cache.request.IndicesRequestCache;
|
||||
import org.elasticsearch.indices.cluster.IndicesClusterStateService;
|
||||
|
@ -35,7 +38,6 @@ import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
|
|||
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCacheListener;
|
||||
import org.elasticsearch.indices.flush.SyncedFlushService;
|
||||
import org.elasticsearch.indices.memory.IndexingMemoryController;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesModule;
|
||||
import org.elasticsearch.indices.recovery.RecoverySettings;
|
||||
import org.elasticsearch.indices.recovery.RecoverySource;
|
||||
import org.elasticsearch.indices.recovery.RecoveryTarget;
|
||||
|
@ -43,28 +45,100 @@ import org.elasticsearch.indices.store.IndicesStore;
|
|||
import org.elasticsearch.indices.store.TransportNodesListShardStoreMetaData;
|
||||
import org.elasticsearch.indices.ttl.IndicesTTLService;
|
||||
|
||||
import java.security.cert.Extension;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* Configures classes and services that are shared by indices on each node.
|
||||
*/
|
||||
public class IndicesModule extends AbstractModule implements SpawnModules {
|
||||
public class IndicesModule extends AbstractModule {
|
||||
|
||||
private final Settings settings;
|
||||
|
||||
private final ExtensionPoint.ClassSet<QueryParser> queryParsers
|
||||
= new ExtensionPoint.ClassSet<>("query_parser", QueryParser.class);
|
||||
private final ExtensionPoint.InstanceMap<String, Dictionary> hunspellDictionaries
|
||||
= new ExtensionPoint.InstanceMap<>("hunspell_dictionary", String.class, Dictionary.class);
|
||||
|
||||
public IndicesModule(Settings settings) {
|
||||
this.settings = settings;
|
||||
registerBuiltinQueryParsers();
|
||||
}
|
||||
|
||||
private void registerBuiltinQueryParsers() {
|
||||
registerQueryParser(MatchQueryParser.class);
|
||||
registerQueryParser(MultiMatchQueryParser.class);
|
||||
registerQueryParser(NestedQueryParser.class);
|
||||
registerQueryParser(HasChildQueryParser.class);
|
||||
registerQueryParser(HasParentQueryParser.class);
|
||||
registerQueryParser(DisMaxQueryParser.class);
|
||||
registerQueryParser(IdsQueryParser.class);
|
||||
registerQueryParser(MatchAllQueryParser.class);
|
||||
registerQueryParser(QueryStringQueryParser.class);
|
||||
registerQueryParser(BoostingQueryParser.class);
|
||||
registerQueryParser(BoolQueryParser.class);
|
||||
registerQueryParser(TermQueryParser.class);
|
||||
registerQueryParser(TermsQueryParser.class);
|
||||
registerQueryParser(FuzzyQueryParser.class);
|
||||
registerQueryParser(RegexpQueryParser.class);
|
||||
registerQueryParser(RangeQueryParser.class);
|
||||
registerQueryParser(PrefixQueryParser.class);
|
||||
registerQueryParser(WildcardQueryParser.class);
|
||||
registerQueryParser(FilteredQueryParser.class);
|
||||
registerQueryParser(ConstantScoreQueryParser.class);
|
||||
registerQueryParser(SpanTermQueryParser.class);
|
||||
registerQueryParser(SpanNotQueryParser.class);
|
||||
registerQueryParser(SpanWithinQueryParser.class);
|
||||
registerQueryParser(SpanContainingQueryParser.class);
|
||||
registerQueryParser(FieldMaskingSpanQueryParser.class);
|
||||
registerQueryParser(SpanFirstQueryParser.class);
|
||||
registerQueryParser(SpanNearQueryParser.class);
|
||||
registerQueryParser(SpanOrQueryParser.class);
|
||||
registerQueryParser(MoreLikeThisQueryParser.class);
|
||||
registerQueryParser(WrapperQueryParser.class);
|
||||
registerQueryParser(IndicesQueryParser.class);
|
||||
registerQueryParser(CommonTermsQueryParser.class);
|
||||
registerQueryParser(SpanMultiTermQueryParser.class);
|
||||
registerQueryParser(FunctionScoreQueryParser.class);
|
||||
registerQueryParser(SimpleQueryStringParser.class);
|
||||
registerQueryParser(TemplateQueryParser.class);
|
||||
registerQueryParser(TypeQueryParser.class);
|
||||
registerQueryParser(LimitQueryParser.class);
|
||||
registerQueryParser(ScriptQueryParser.class);
|
||||
registerQueryParser(GeoDistanceQueryParser.class);
|
||||
registerQueryParser(GeoDistanceRangeQueryParser.class);
|
||||
registerQueryParser(GeoBoundingBoxQueryParser.class);
|
||||
registerQueryParser(GeohashCellQuery.Parser.class);
|
||||
registerQueryParser(GeoPolygonQueryParser.class);
|
||||
registerQueryParser(QueryFilterParser.class);
|
||||
registerQueryParser(FQueryFilterParser.class);
|
||||
registerQueryParser(AndQueryParser.class);
|
||||
registerQueryParser(OrQueryParser.class);
|
||||
registerQueryParser(NotQueryParser.class);
|
||||
registerQueryParser(ExistsQueryParser.class);
|
||||
registerQueryParser(MissingQueryParser.class);
|
||||
|
||||
if (ShapesAvailability.JTS_AVAILABLE) {
|
||||
registerQueryParser(GeoShapeQueryParser.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends Module> spawnModules() {
|
||||
return ImmutableList.of(new IndicesQueriesModule(), new IndicesAnalysisModule());
|
||||
public void registerQueryParser(Class<? extends QueryParser> queryParser) {
|
||||
queryParsers.registerExtension(queryParser);
|
||||
}
|
||||
|
||||
public void registerHunspellDictionary(String name, Dictionary dictionary) {
|
||||
hunspellDictionaries.registerExtension(name, dictionary);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindQueryParsersExtension();
|
||||
bindHunspellExtension();
|
||||
|
||||
bind(IndicesLifecycle.class).to(InternalIndicesLifecycle.class).asEagerSingleton();
|
||||
|
||||
bind(IndicesService.class).asEagerSingleton();
|
||||
|
||||
bind(RecoverySettings.class).asEagerSingleton();
|
||||
bind(RecoveryTarget.class).asEagerSingleton();
|
||||
bind(RecoverySource.class).asEagerSingleton();
|
||||
|
@ -80,7 +154,16 @@ public class IndicesModule extends AbstractModule implements SpawnModules {
|
|||
bind(IndicesWarmer.class).asEagerSingleton();
|
||||
bind(UpdateHelper.class).asEagerSingleton();
|
||||
bind(MetaDataIndexUpgradeService.class).asEagerSingleton();
|
||||
|
||||
bind(IndicesFieldDataCacheListener.class).asEagerSingleton();
|
||||
}
|
||||
|
||||
protected void bindQueryParsersExtension() {
|
||||
queryParsers.bind(binder());
|
||||
}
|
||||
|
||||
protected void bindHunspellExtension() {
|
||||
hunspellDictionaries.bind(binder());
|
||||
bind(HunspellService.class).asEagerSingleton();
|
||||
bind(IndicesAnalysisService.class).asEagerSingleton();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.indices.analysis;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.apache.lucene.analysis.hunspell.Dictionary;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.multibindings.MapBinder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class IndicesAnalysisModule extends AbstractModule {
|
||||
|
||||
private final Map<String, Dictionary> hunspellDictionaries = Maps.newHashMap();
|
||||
|
||||
public void addHunspellDictionary(String lang, Dictionary dictionary) {
|
||||
hunspellDictionaries.put(lang, dictionary);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(IndicesAnalysisService.class).asEagerSingleton();
|
||||
|
||||
MapBinder<String, Dictionary> dictionariesBinder = MapBinder.newMapBinder(binder(), String.class, Dictionary.class);
|
||||
for (Map.Entry<String, Dictionary> entry : hunspellDictionaries.entrySet()) {
|
||||
dictionariesBinder.addBinding(entry.getKey()).toInstance(entry.getValue());
|
||||
}
|
||||
bind(HunspellService.class).asEagerSingleton();
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.indices.query;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.common.geo.ShapesAvailability;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.multibindings.Multibinder;
|
||||
import org.elasticsearch.index.query.*;
|
||||
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryParser;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class IndicesQueriesModule extends AbstractModule {
|
||||
|
||||
private Set<Class<? extends QueryParser>> queryParsersClasses = Sets.newHashSet();
|
||||
|
||||
public synchronized IndicesQueriesModule addQuery(Class<? extends QueryParser> queryParser) {
|
||||
queryParsersClasses.add(queryParser);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(IndicesQueriesRegistry.class).asEagerSingleton();
|
||||
|
||||
Multibinder<QueryParser> qpBinders = Multibinder.newSetBinder(binder(), QueryParser.class);
|
||||
for (Class<? extends QueryParser> queryParser : queryParsersClasses) {
|
||||
qpBinders.addBinding().to(queryParser).asEagerSingleton();
|
||||
}
|
||||
qpBinders.addBinding().to(MatchQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(MultiMatchQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(NestedQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(HasChildQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(HasParentQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(DisMaxQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(IdsQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(MatchAllQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(QueryStringQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(BoostingQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(BoolQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(TermQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(TermsQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(FuzzyQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(RegexpQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(RangeQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(PrefixQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(WildcardQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(FilteredQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(ConstantScoreQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(SpanTermQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(SpanNotQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(SpanWithinQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(SpanContainingQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(FieldMaskingSpanQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(SpanFirstQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(SpanNearQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(SpanOrQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(MoreLikeThisQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(WrapperQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(IndicesQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(CommonTermsQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(SpanMultiTermQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(FunctionScoreQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(SimpleQueryStringParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(TemplateQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(TypeQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(LimitQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(TermsQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(ScriptQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(GeoDistanceQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(GeoDistanceRangeQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(GeoBoundingBoxQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(GeohashCellQuery.Parser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(GeoPolygonQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(QueryFilterParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(FQueryFilterParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(AndQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(OrQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(NotQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(ExistsQueryParser.class).asEagerSingleton();
|
||||
qpBinders.addBinding().to(MissingQueryParser.class).asEagerSingleton();
|
||||
|
||||
if (ShapesAvailability.JTS_AVAILABLE) {
|
||||
qpBinders.addBinding().to(GeoShapeQueryParser.class).asEagerSingleton();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ import java.util.*;
|
|||
/**
|
||||
* An extensions point and registry for all the highlighters a node supports.
|
||||
*/
|
||||
public class Highlighters extends ExtensionPoint.MapExtensionPoint<Highlighter> {
|
||||
public class Highlighters extends ExtensionPoint.ClassMap<Highlighter> {
|
||||
|
||||
@Deprecated // remove in 3.0
|
||||
private static final String FAST_VECTOR_HIGHLIGHTER = "fast-vector-highlighter";
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.elasticsearch.search.suggest;
|
||||
|
||||
import org.elasticsearch.common.inject.Binder;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.util.ExtensionPoint;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
|
@ -31,7 +30,7 @@ import java.util.*;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public final class Suggesters extends ExtensionPoint.MapExtensionPoint<Suggester> {
|
||||
public final class Suggesters extends ExtensionPoint.ClassMap<Suggester> {
|
||||
private final Map<String, Suggester> parsers;
|
||||
|
||||
public Suggesters() {
|
||||
|
|
|
@ -24,12 +24,15 @@ import org.elasticsearch.common.inject.spi.Elements;
|
|||
import org.elasticsearch.common.inject.spi.InstanceBinding;
|
||||
import org.elasticsearch.common.inject.spi.LinkedKeyBinding;
|
||||
import org.elasticsearch.common.inject.spi.ProviderInstanceBinding;
|
||||
import org.elasticsearch.common.inject.spi.ProviderLookup;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -77,7 +80,7 @@ public abstract class ModuleTestCase extends ESTestCase {
|
|||
|
||||
/**
|
||||
* Configures the module and checks a Map<String, Class> of the "to" class
|
||||
* is bound to "theClas".
|
||||
* is bound to "theClass".
|
||||
*/
|
||||
public void assertMapMultiBinding(Module module, Class to, Class theClass) {
|
||||
List<Element> elements = Elements.getElements(module);
|
||||
|
@ -138,10 +141,18 @@ public abstract class ModuleTestCase extends ESTestCase {
|
|||
assertTrue("Did not find provider for set of " + to.getName(), providerFound);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the module, and ensures an instance is bound to the "to" class, and the
|
||||
* provided tester returns true on the instance.
|
||||
*/
|
||||
public <T> void assertInstanceBinding(Module module, Class<T> to, Predicate<T> tester) {
|
||||
assertInstanceBindingWithAnnotation(module, to, tester, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link #assertInstanceBinding(Module, Class, Predicate)}, but filters the
|
||||
* classes checked by the given annotation.
|
||||
*/
|
||||
public <T> void assertInstanceBindingWithAnnotation(Module module, Class<T> to, Predicate<T> tester, Class<? extends Annotation> annotation) {
|
||||
List<Element> elements = Elements.getElements(module);
|
||||
for (Element element : elements) {
|
||||
|
@ -161,4 +172,39 @@ public abstract class ModuleTestCase extends ESTestCase {
|
|||
}
|
||||
fail("Did not find any instance binding to " + to.getName() + ". Found these bindings:\n" + s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the module, and ensures a map exists between the "keyType" and "valueType",
|
||||
* and that all of the "expected" values are bound.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <K,V> void assertMapInstanceBinding(Module module, Class<K> keyType, Class<V> valueType, Map<K,V> expected) throws Exception {
|
||||
// this method is insane because java type erasure makes it incredibly difficult...
|
||||
Map<K,Key> keys = new HashMap<>();
|
||||
Map<Key,V> values = new HashMap<>();
|
||||
List<Element> elements = Elements.getElements(module);
|
||||
for (Element element : elements) {
|
||||
if (element instanceof InstanceBinding) {
|
||||
InstanceBinding binding = (InstanceBinding) element;
|
||||
if (binding.getKey().getRawType().equals(valueType)) {
|
||||
values.put(binding.getKey(), (V)binding.getInstance());
|
||||
} else if (binding.getInstance() instanceof Map.Entry) {
|
||||
Map.Entry entry = (Map.Entry)binding.getInstance();
|
||||
Object key = entry.getKey();
|
||||
Object providerValue = entry.getValue();
|
||||
if (key.getClass().equals(keyType) && providerValue instanceof ProviderLookup.ProviderImpl) {
|
||||
ProviderLookup.ProviderImpl provider = (ProviderLookup.ProviderImpl)providerValue;
|
||||
keys.put((K)key, provider.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Map.Entry<K, V> entry : expected.entrySet()) {
|
||||
Key valueKey = keys.get(entry.getKey());
|
||||
assertNotNull("Could not find binding for key [" + entry.getKey() + "], found these keys:\n" + keys.keySet(), valueKey);
|
||||
V value = values.get(valueKey);
|
||||
assertNotNull("Could not find value for instance key [" + valueKey + "], found these bindings:\n" + elements);
|
||||
assertEquals(entry.getValue(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ import org.elasticsearch.index.Index;
|
|||
import org.elasticsearch.index.IndexNameModule;
|
||||
import org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
|
@ -55,7 +54,9 @@ import java.nio.file.Path;
|
|||
import java.util.Set;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -66,7 +67,7 @@ public class AnalysisModuleTests extends ESTestCase {
|
|||
|
||||
public AnalysisService getAnalysisService(Settings settings) {
|
||||
Index index = new Index("test");
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector();
|
||||
AnalysisModule analysisModule = new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class));
|
||||
analysisModule.addTokenFilter("myfilter", MyFilterTokenFilterFactory.class);
|
||||
injector = new ModulesBuilder().add(
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.elasticsearch.env.EnvironmentModule;
|
|||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.IndexNameModule;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.indices.IndicesModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
@ -52,8 +52,15 @@ public class AnalysisTestsHelper {
|
|||
if (settings.get(IndexMetaData.SETTING_VERSION_CREATED) == null) {
|
||||
settings = Settings.builder().put(settings).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
|
||||
}
|
||||
IndicesModule indicesModule = new IndicesModule(settings) {
|
||||
@Override
|
||||
public void configure() {
|
||||
// skip services
|
||||
bindHunspellExtension();
|
||||
}
|
||||
};
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings),
|
||||
new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
|
||||
new EnvironmentModule(new Environment(settings)), indicesModule).createInjector();
|
||||
|
||||
AnalysisModule analysisModule = new AnalysisModule(settings,
|
||||
parentInjector.getInstance(IndicesAnalysisService.class));
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.elasticsearch.env.EnvironmentModule;
|
|||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.IndexNameModule;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.test.ESTokenStreamTestCase;
|
||||
import org.junit.Test;
|
||||
|
@ -51,7 +50,7 @@ public class CharFilterTests extends ESTokenStreamTestCase {
|
|||
.putArray("index.analysis.analyzer.custom_with_char_filter.char_filter", "my_mapping")
|
||||
.put("path.home", createTempDir().toString())
|
||||
.build();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector();
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
new IndexSettingsModule(index, settings),
|
||||
new IndexNameModule(index),
|
||||
|
@ -77,7 +76,7 @@ public class CharFilterTests extends ESTokenStreamTestCase {
|
|||
.putArray("index.analysis.analyzer.custom_with_char_filter.char_filter", "html_strip")
|
||||
.put("path.home", createTempDir().toString())
|
||||
.build();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector();
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
new IndexSettingsModule(index, settings),
|
||||
new IndexNameModule(index),
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.elasticsearch.index.IndexNameModule;
|
|||
import org.elasticsearch.index.analysis.compound.DictionaryCompoundWordTokenFilterFactory;
|
||||
import org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
|
@ -48,7 +47,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -58,7 +59,7 @@ public class CompoundAnalysisTests extends ESTestCase {
|
|||
public void testDefaultsCompoundAnalysis() throws Exception {
|
||||
Index index = new Index("test");
|
||||
Settings settings = getJsonSettings();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector();
|
||||
AnalysisModule analysisModule = new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class));
|
||||
analysisModule.addTokenFilter("myfilter", MyFilterTokenFilterFactory.class);
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
|
@ -85,7 +86,7 @@ public class CompoundAnalysisTests extends ESTestCase {
|
|||
|
||||
private List<String> analyze(Settings settings, String analyzerName, String text) throws IOException {
|
||||
Index index = new Index("test");
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector();
|
||||
AnalysisModule analysisModule = new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class));
|
||||
analysisModule.addTokenFilter("myfilter", MyFilterTokenFilterFactory.class);
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.elasticsearch.env.EnvironmentModule;
|
|||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.IndexNameModule;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.test.ESTokenStreamTestCase;
|
||||
import org.junit.Test;
|
||||
|
@ -48,7 +47,7 @@ public class PatternCaptureTokenFilterTests extends ESTokenStreamTestCase {
|
|||
.loadFromStream(json, getClass().getResourceAsStream(json))
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.build();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector();
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
new IndexSettingsModule(index, settings),
|
||||
new IndexNameModule(index),
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.elasticsearch.env.EnvironmentModule;
|
|||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.IndexNameModule;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.test.ESTokenStreamTestCase;
|
||||
import org.junit.Test;
|
||||
|
@ -48,7 +47,7 @@ public class StopAnalyzerTests extends ESTokenStreamTestCase {
|
|||
.put("path.home", createTempDir().toString())
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.build();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector();
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
new IndexSettingsModule(index, settings),
|
||||
new IndexNameModule(index),
|
||||
|
|
|
@ -39,7 +39,6 @@ import org.elasticsearch.index.IndexNameModule;
|
|||
import org.elasticsearch.index.analysis.AnalysisModule;
|
||||
import org.elasticsearch.index.analysis.AnalysisService;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
|
@ -80,8 +79,7 @@ public class SynonymsAnalysisTest extends ESTestCase {
|
|||
|
||||
Injector parentInjector = new ModulesBuilder().add(
|
||||
new SettingsModule(settings),
|
||||
new EnvironmentModule(new Environment(settings)),
|
||||
new IndicesAnalysisModule())
|
||||
new EnvironmentModule(new Environment(settings)))
|
||||
.createInjector();
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
new IndexSettingsModule(index, settings),
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.index.query;
|
|||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionModule;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
|
@ -39,15 +40,13 @@ import org.elasticsearch.index.IndexNameModule;
|
|||
import org.elasticsearch.index.analysis.AnalysisModule;
|
||||
import org.elasticsearch.index.cache.IndexCacheModule;
|
||||
import org.elasticsearch.index.query.functionscore.ScoreFunctionParser;
|
||||
import org.elasticsearch.index.query.functionscore.ScoreFunctionParserMapper;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.index.similarity.SimilarityModule;
|
||||
import org.elasticsearch.indices.IndicesModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
||||
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesModule;
|
||||
import org.elasticsearch.script.ScriptModule;
|
||||
import org.elasticsearch.search.SearchModule;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.threadpool.ThreadPoolModule;
|
||||
|
@ -80,7 +79,13 @@ public class TemplateQueryParserTest extends ESTestCase {
|
|||
new EnvironmentModule(new Environment(settings)),
|
||||
new SettingsModule(settings),
|
||||
new ThreadPoolModule(new ThreadPool(settings)),
|
||||
new IndicesQueriesModule(),
|
||||
new IndicesModule(settings) {
|
||||
@Override
|
||||
public void configure() {
|
||||
// skip services
|
||||
bindQueryParsersExtension();
|
||||
}
|
||||
},
|
||||
new ScriptModule(settings),
|
||||
new IndexSettingsModule(index, settings),
|
||||
new IndexCacheModule(settings),
|
||||
|
|
|
@ -23,15 +23,13 @@ import org.apache.lucene.search.IndexSearcher;
|
|||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.Weight;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.query.QueryParser;
|
||||
import org.elasticsearch.index.query.QueryParsingException;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesModule;
|
||||
import org.elasticsearch.indices.IndicesModule;
|
||||
import org.elasticsearch.plugins.AbstractPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -48,16 +46,8 @@ public class DummyQueryParserPlugin extends AbstractPlugin {
|
|||
return "dummy query";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processModule(Module module) {
|
||||
if (module instanceof IndicesQueriesModule) {
|
||||
IndicesQueriesModule indicesQueriesModule = (IndicesQueriesModule) module;
|
||||
indicesQueriesModule.addQuery(DummyQueryParser.class);
|
||||
}
|
||||
}
|
||||
|
||||
public Settings settings() {
|
||||
return Settings.EMPTY;
|
||||
public void onModule(IndicesModule module) {
|
||||
module.registerQueryParser(DummyQueryParser.class);
|
||||
}
|
||||
|
||||
public static class DummyQueryBuilder extends QueryBuilder {
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.indices;
|
||||
|
||||
import org.apache.lucene.analysis.hunspell.Dictionary;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.common.inject.ModuleTestCase;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.query.QueryParser;
|
||||
import org.elasticsearch.index.query.QueryParsingException;
|
||||
import org.elasticsearch.index.query.TermQueryParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
|
||||
public class IndicesModuleTests extends ModuleTestCase {
|
||||
|
||||
static class FakeQueryParser implements QueryParser {
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[] {"fake-query-parser"};
|
||||
}
|
||||
@Override
|
||||
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void testRegisterQueryParser() {
|
||||
IndicesModule module = new IndicesModule(Settings.EMPTY);
|
||||
module.registerQueryParser(FakeQueryParser.class);
|
||||
assertSetMultiBinding(module, QueryParser.class, FakeQueryParser.class);
|
||||
}
|
||||
|
||||
public void testRegisterQueryParserDuplicate() {
|
||||
IndicesModule module = new IndicesModule(Settings.EMPTY);
|
||||
try {
|
||||
module.registerQueryParser(TermQueryParser.class);
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals(e.getMessage(), "Can't register the same [query_parser] more than once for [" + TermQueryParser.class.getName() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public void testRegisterHunspellDictionary() throws Exception {
|
||||
IndicesModule module = new IndicesModule(Settings.EMPTY);
|
||||
InputStream aff = getClass().getResourceAsStream("/indices/analyze/conf_dir/hunspell/en_US/en_US.aff");
|
||||
InputStream dic = getClass().getResourceAsStream("/indices/analyze/conf_dir/hunspell/en_US/en_US.dic");
|
||||
Dictionary dictionary = new Dictionary(aff, dic);
|
||||
module.registerHunspellDictionary("foo", dictionary);
|
||||
assertMapInstanceBinding(module, String.class, Dictionary.class, Collections.singletonMap("foo", dictionary));
|
||||
}
|
||||
|
||||
public void testRegisterHunspellDictionaryDuplicate() {
|
||||
IndicesModule module = new IndicesModule(Settings.EMPTY);
|
||||
try {
|
||||
module.registerQueryParser(TermQueryParser.class);
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals(e.getMessage(), "Can't register the same [query_parser] more than once for [" + TermQueryParser.class.getName() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -30,7 +30,6 @@ import org.elasticsearch.env.EnvironmentModule;
|
|||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.IndexNameModule;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
|
@ -42,7 +41,7 @@ public class AnalysisTestUtils {
|
|||
Settings indexSettings = settingsBuilder().put(settings)
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.build();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector();
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
new IndexSettingsModule(index, indexSettings),
|
||||
new IndexNameModule(index),
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.elasticsearch.env.EnvironmentModule;
|
|||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.IndexNameModule;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.plugin.analysis.kuromoji.AnalysisKuromojiPlugin;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -48,7 +47,10 @@ import java.io.StringReader;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -211,8 +213,7 @@ public class KuromojiAnalysisTests extends ESTestCase {
|
|||
Index index = new Index("test");
|
||||
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings),
|
||||
new EnvironmentModule(new Environment(settings)),
|
||||
new IndicesAnalysisModule())
|
||||
new EnvironmentModule(new Environment(settings)))
|
||||
.createInjector();
|
||||
|
||||
AnalysisModule analysisModule = new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class));
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.elasticsearch.env.EnvironmentModule;
|
|||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.IndexNameModule;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
|
@ -59,8 +58,7 @@ public class SimplePhoneticAnalysisTests extends ESTestCase {
|
|||
Index index = new Index("test");
|
||||
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings),
|
||||
new EnvironmentModule(new Environment(settings)),
|
||||
new IndicesAnalysisModule()).createInjector();
|
||||
new EnvironmentModule(new Environment(settings))).createInjector();
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
new IndexSettingsModule(index, settings),
|
||||
new IndexNameModule(index),
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.elasticsearch.env.EnvironmentModule;
|
|||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.IndexNameModule;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
|
@ -51,7 +50,7 @@ public class SimpleSmartChineseAnalysisTests extends ESTestCase {
|
|||
.put("path.home", createTempDir())
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.build();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(EMPTY_SETTINGS), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(EMPTY_SETTINGS), new EnvironmentModule(new Environment(settings))).createInjector();
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
new IndexSettingsModule(index, settings),
|
||||
new IndexNameModule(index),
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.elasticsearch.index.IndexNameModule;
|
|||
import org.elasticsearch.index.analysis.pl.PolishAnalysisBinderProcessor;
|
||||
import org.elasticsearch.index.analysis.pl.PolishStemTokenFilterFactory;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
|
@ -56,7 +55,7 @@ public class PolishAnalysisTests extends ESTestCase {
|
|||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.build();
|
||||
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(EMPTY_SETTINGS), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(EMPTY_SETTINGS), new EnvironmentModule(new Environment(settings))).createInjector();
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
new IndexSettingsModule(index, settings),
|
||||
new IndexNameModule(index),
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.elasticsearch.index.Index;
|
|||
import org.elasticsearch.index.IndexNameModule;
|
||||
import org.elasticsearch.index.analysis.pl.PolishAnalysisBinderProcessor;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
|
||||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Test;
|
||||
|
@ -102,7 +101,7 @@ public class SimplePolishTokenFilterTests extends ESTestCase {
|
|||
}
|
||||
|
||||
private AnalysisService createAnalysisService(Index index, Settings settings) {
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
|
||||
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector();
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
new IndexSettingsModule(index, settings),
|
||||
new IndexNameModule(index),
|
||||
|
|
Loading…
Reference in New Issue