|
19 | 19 |
|
20 | 20 | package org.elasticsearch.index;
|
21 | 21 |
|
| 22 | +import org.apache.lucene.search.similarities.Similarity; |
| 23 | +import org.apache.lucene.search.similarities.BM25Similarity; |
22 | 24 | import org.apache.lucene.util.SetOnce;
|
| 25 | +import org.elasticsearch.Version; |
23 | 26 | import org.elasticsearch.client.Client;
|
24 | 27 | import org.elasticsearch.common.Strings;
|
| 28 | +import org.elasticsearch.common.TriFunction; |
25 | 29 | import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
26 | 30 | import org.elasticsearch.common.settings.Setting;
|
27 | 31 | import org.elasticsearch.common.settings.Setting.Property;
|
|
39 | 43 | import org.elasticsearch.index.shard.IndexSearcherWrapper;
|
40 | 44 | import org.elasticsearch.index.shard.IndexingOperationListener;
|
41 | 45 | import org.elasticsearch.index.shard.SearchOperationListener;
|
42 |
| -import org.elasticsearch.index.shard.ShardId; |
43 |
| -import org.elasticsearch.index.similarity.BM25SimilarityProvider; |
44 |
| -import org.elasticsearch.index.similarity.SimilarityProvider; |
45 | 46 | import org.elasticsearch.index.similarity.SimilarityService;
|
46 | 47 | import org.elasticsearch.index.store.IndexStore;
|
47 | 48 | import org.elasticsearch.indices.IndicesQueryCache;
|
|
68 | 69 | /**
|
69 | 70 | * IndexModule represents the central extension point for index level custom implementations like:
|
70 | 71 | * <ul>
|
71 |
| - * <li>{@link SimilarityProvider} - New {@link SimilarityProvider} implementations can be registered through |
72 |
| - * {@link #addSimilarity(String, SimilarityProvider.Factory)} while existing Providers can be referenced through Settings under the |
| 72 | + * <li>{@link Similarity} - New {@link Similarity} implementations can be registered through |
| 73 | + * {@link #addSimilarity(String, TriFunction)} while existing Providers can be referenced through Settings under the |
73 | 74 | * {@link IndexModule#SIMILARITY_SETTINGS_PREFIX} prefix along with the "type" value. For example, to reference the
|
74 |
| - * {@link BM25SimilarityProvider}, the configuration <tt>"index.similarity.my_similarity.type : "BM25"</tt> can be used.</li> |
| 75 | + * {@link BM25Similarity}, the configuration <tt>"index.similarity.my_similarity.type : "BM25"</tt> can be used.</li> |
75 | 76 | * <li>{@link IndexStore} - Custom {@link IndexStore} instances can be registered via {@link #addIndexStore(String, Function)}</li>
|
76 | 77 | * <li>{@link IndexEventListener} - Custom {@link IndexEventListener} instances can be registered via
|
77 | 78 | * {@link #addIndexEventListener(IndexEventListener)}</li>
|
@@ -107,7 +108,7 @@ public final class IndexModule {
|
107 | 108 | final SetOnce<EngineFactory> engineFactory = new SetOnce<>();
|
108 | 109 | private SetOnce<IndexSearcherWrapperFactory> indexSearcherWrapper = new SetOnce<>();
|
109 | 110 | private final Set<IndexEventListener> indexEventListeners = new HashSet<>();
|
110 |
| - private final Map<String, SimilarityProvider.Factory> similarities = new HashMap<>(); |
| 111 | + private final Map<String, TriFunction<Settings, Version, ScriptService, Similarity>> similarities = new HashMap<>(); |
111 | 112 | private final Map<String, Function<IndexSettings, IndexStore>> storeTypes = new HashMap<>();
|
112 | 113 | private final SetOnce<BiFunction<IndexSettings, IndicesQueryCache, QueryCache>> forceQueryCacheProvider = new SetOnce<>();
|
113 | 114 | private final List<SearchOperationListener> searchOperationListeners = new ArrayList<>();
|
@@ -246,12 +247,17 @@ public void addIndexStore(String type, Function<IndexSettings, IndexStore> provi
|
246 | 247 |
|
247 | 248 |
|
248 | 249 | /**
|
249 |
| - * Registers the given {@link SimilarityProvider} with the given name |
| 250 | + * Registers the given {@link Similarity} with the given name. |
| 251 | + * The function takes as parameters:<ul> |
| 252 | + * <li>settings for this similarity |
| 253 | + * <li>version of Elasticsearch when the index was created |
| 254 | + * <li>ScriptService, for script-based similarities |
| 255 | + * </ul> |
250 | 256 | *
|
251 | 257 | * @param name Name of the SimilarityProvider
|
252 | 258 | * @param similarity SimilarityProvider to register
|
253 | 259 | */
|
254 |
| - public void addSimilarity(String name, SimilarityProvider.Factory similarity) { |
| 260 | + public void addSimilarity(String name, TriFunction<Settings, Version, ScriptService, Similarity> similarity) { |
255 | 261 | ensureNotFrozen();
|
256 | 262 | if (similarities.containsKey(name) || SimilarityService.BUILT_IN.containsKey(name)) {
|
257 | 263 | throw new IllegalArgumentException("similarity for name: [" + name + " is already registered");
|
|
0 commit comments