diff --git a/.eclipseformat.xml b/.eclipseformat.xml
new file mode 100644
index 00000000..6e93f9b2
--- /dev/null
+++ b/.eclipseformat.xml
@@ -0,0 +1,362 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
index c07e1002..cc9ec9b6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,7 +15,7 @@ __pycache__/
RankLib.jar
tmdb.json
model.txt
-
+.DS_Store
.idea/
.gradle/
diff --git a/licenses/httpclient5-5.3.1.jar.sha1 b/licenses/httpclient5-5.3.1.jar.sha1
new file mode 100644
index 00000000..c8f32c1e
--- /dev/null
+++ b/licenses/httpclient5-5.3.1.jar.sha1
@@ -0,0 +1 @@
+56b53c8f4bcdaada801d311cf2ff8a24d6d96883
\ No newline at end of file
diff --git a/licenses/httpcore5-5.3.jar.sha1 b/licenses/httpcore5-5.3.jar.sha1
new file mode 100644
index 00000000..1721b75f
--- /dev/null
+++ b/licenses/httpcore5-5.3.jar.sha1
@@ -0,0 +1 @@
+a30e0b837732ac0e034c196dbdfcd8208d347a72
\ No newline at end of file
diff --git a/src/javaRestTest/java/com/o19s/es/ltr/NodeSettingsIT.java b/src/javaRestTest/java/com/o19s/es/ltr/NodeSettingsIT.java
index 3e4baba1..f60f6535 100644
--- a/src/javaRestTest/java/com/o19s/es/ltr/NodeSettingsIT.java
+++ b/src/javaRestTest/java/com/o19s/es/ltr/NodeSettingsIT.java
@@ -16,38 +16,41 @@
package com.o19s.es.ltr;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.lessThan;
+
+import java.io.IOException;
+
+import org.apache.lucene.util.Accountable;
+import org.opensearch.common.settings.Settings;
+import org.opensearch.core.common.unit.ByteSizeUnit;
+import org.opensearch.core.common.unit.ByteSizeValue;
+
import com.o19s.es.ltr.action.BaseIntegrationTest;
import com.o19s.es.ltr.feature.store.CompiledLtrModel;
import com.o19s.es.ltr.feature.store.MemStore;
import com.o19s.es.ltr.feature.store.index.CachedFeatureStore;
import com.o19s.es.ltr.feature.store.index.Caches;
import com.o19s.es.ltr.ranker.LtrRanker;
-import org.apache.lucene.util.Accountable;
-import org.opensearch.common.settings.Settings;
-import org.opensearch.core.common.unit.ByteSizeUnit;
-import org.opensearch.core.common.unit.ByteSizeValue;
-
-import java.io.IOException;
-
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.greaterThanOrEqualTo;
-import static org.hamcrest.Matchers.lessThan;
public class NodeSettingsIT extends BaseIntegrationTest {
private final MemStore memStore = new MemStore();
private final int memSize = 1024;
private final int expireAfterRead = 100;
- private final int expireAfterWrite = expireAfterRead*4;
+ private final int expireAfterWrite = expireAfterRead * 4;
@Override
protected Settings nodeSettings() {
Settings settings = super.nodeSettings();
- return Settings.builder().put(settings)
- .put(Caches.LTR_CACHE_MEM_SETTING.getKey(), memSize + "kb")
- .put(Caches.LTR_CACHE_EXPIRE_AFTER_READ.getKey(), expireAfterRead + "ms")
- .put(Caches.LTR_CACHE_EXPIRE_AFTER_WRITE.getKey(), expireAfterWrite + "ms")
- .build();
+ return Settings
+ .builder()
+ .put(settings)
+ .put(Caches.LTR_CACHE_MEM_SETTING.getKey(), memSize + "kb")
+ .put(Caches.LTR_CACHE_EXPIRE_AFTER_READ.getKey(), expireAfterRead + "ms")
+ .put(Caches.LTR_CACHE_EXPIRE_AFTER_WRITE.getKey(), expireAfterWrite + "ms")
+ .build();
}
public void testCacheSettings() throws IOException, InterruptedException {
@@ -67,14 +70,14 @@ public void testCacheSettings() throws IOException, InterruptedException {
} while (totalAdded < maxMemSize);
assertThat(totalAdded, greaterThan(maxMemSize));
assertThat(caches.modelCache().weight(), greaterThan(0L));
- Thread.sleep(expireAfterWrite*2);
+ Thread.sleep(expireAfterWrite * 2);
caches.modelCache().refresh();
assertEquals(0, caches.modelCache().weight());
cached.loadModel("test0");
// Second load for accessTime
cached.loadModel("test0");
assertThat(caches.modelCache().weight(), greaterThan(0L));
- Thread.sleep(expireAfterRead*2);
+ Thread.sleep(expireAfterRead * 2);
caches.modelCache().refresh();
assertEquals(0, caches.modelCache().weight());
}
diff --git a/src/javaRestTest/java/com/o19s/es/ltr/action/AddFeaturesToSetActionIT.java b/src/javaRestTest/java/com/o19s/es/ltr/action/AddFeaturesToSetActionIT.java
index 83415554..4fa336e6 100644
--- a/src/javaRestTest/java/com/o19s/es/ltr/action/AddFeaturesToSetActionIT.java
+++ b/src/javaRestTest/java/com/o19s/es/ltr/action/AddFeaturesToSetActionIT.java
@@ -16,22 +16,23 @@
package com.o19s.es.ltr.action;
-import com.o19s.es.ltr.action.AddFeaturesToSetAction.AddFeaturesToSetRequestBuilder;
-import com.o19s.es.ltr.action.AddFeaturesToSetAction.AddFeaturesToSetResponse;
-import com.o19s.es.ltr.feature.store.StoredFeature;
-import com.o19s.es.ltr.feature.store.StoredFeatureSet;
-import com.o19s.es.ltr.feature.store.index.IndexFeatureStore;
-import org.opensearch.action.DocWriteResponse;
+import static com.o19s.es.ltr.LtrTestUtils.randomFeature;
+import static java.util.Arrays.asList;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.opensearch.ExceptionsHelper.unwrap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
-import static com.o19s.es.ltr.LtrTestUtils.randomFeature;
-import static java.util.Arrays.asList;
-import static org.opensearch.ExceptionsHelper.unwrap;
-import static org.hamcrest.CoreMatchers.containsString;
+import org.opensearch.action.DocWriteResponse;
+
+import com.o19s.es.ltr.action.AddFeaturesToSetAction.AddFeaturesToSetRequestBuilder;
+import com.o19s.es.ltr.action.AddFeaturesToSetAction.AddFeaturesToSetResponse;
+import com.o19s.es.ltr.feature.store.StoredFeature;
+import com.o19s.es.ltr.feature.store.StoredFeatureSet;
+import com.o19s.es.ltr.feature.store.index.IndexFeatureStore;
public class AddFeaturesToSetActionIT extends BaseIntegrationTest {
public void testAddToSetWithQuery() throws Exception {
@@ -100,7 +101,7 @@ public void testAddToSetWithList() throws Exception {
assertEquals(2, resp.getResponse().getVersion());
assertEquals(DocWriteResponse.Result.UPDATED, resp.getResponse().getResult());
set = getElement(StoredFeatureSet.class, StoredFeatureSet.TYPE, "new_feature_set");
- assertEquals(features.size()+1, set.size());
+ assertEquals(features.size() + 1, set.size());
assertTrue(set.hasFeature("another_feature"));
}
@@ -109,8 +110,7 @@ public void testFailuresWhenEmpty() throws Exception {
builder.request().setFeatureSet("new_broken_set");
builder.request().setFeatureNameQuery("doesnotexist*");
builder.request().setStore(IndexFeatureStore.DEFAULT_STORE);
- Throwable iae = unwrap(expectThrows(ExecutionException.class, () -> builder.execute().get()),
- IllegalArgumentException.class);
+ Throwable iae = unwrap(expectThrows(ExecutionException.class, () -> builder.execute().get()), IllegalArgumentException.class);
assertNotNull(iae);
assertThat(iae.getMessage(), containsString("returned no features"));
}
@@ -127,14 +127,12 @@ public void testFailuresOnDuplicates() throws Exception {
assertEquals(DocWriteResponse.Result.CREATED, resp.getResponse().getResult());
assertEquals(1, resp.getResponse().getVersion());
-
- AddFeaturesToSetRequestBuilder builder2= new AddFeaturesToSetRequestBuilder(client());
+ AddFeaturesToSetRequestBuilder builder2 = new AddFeaturesToSetRequestBuilder(client());
builder2.request().setFeatureSet("duplicated_set");
builder2.request().setFeatureNameQuery("duplicated");
builder2.request().setStore(IndexFeatureStore.DEFAULT_STORE);
- Throwable iae = unwrap(expectThrows(ExecutionException.class, () -> builder2.execute().get()),
- IllegalArgumentException.class);
+ Throwable iae = unwrap(expectThrows(ExecutionException.class, () -> builder2.execute().get()), IllegalArgumentException.class);
assertNotNull(iae);
assertThat(iae.getMessage(), containsString("defined twice in this set"));
}
@@ -143,7 +141,7 @@ public void testMergeWithQuery() throws Exception {
addElement(randomFeature("duplicated"));
addElement(randomFeature("new_feature"));
- AddFeaturesToSetRequestBuilder builder= new AddFeaturesToSetRequestBuilder(client());
+ AddFeaturesToSetRequestBuilder builder = new AddFeaturesToSetRequestBuilder(client());
builder.request().setFeatureSet("merged_set");
builder.request().setFeatureNameQuery("duplicated*");
builder.request().setStore(IndexFeatureStore.DEFAULT_STORE);
@@ -153,7 +151,7 @@ public void testMergeWithQuery() throws Exception {
assertEquals(DocWriteResponse.Result.CREATED, resp.getResponse().getResult());
assertEquals(1, resp.getResponse().getVersion());
- builder= new AddFeaturesToSetRequestBuilder(client());
+ builder = new AddFeaturesToSetRequestBuilder(client());
builder.request().setFeatureSet("merged_set");
builder.request().setFeatureNameQuery("*");
builder.request().setStore(IndexFeatureStore.DEFAULT_STORE);
@@ -176,7 +174,7 @@ public void testMergeWithList() throws Exception {
features.add(feat);
}
- AddFeaturesToSetRequestBuilder builder= new AddFeaturesToSetRequestBuilder(client());
+ AddFeaturesToSetRequestBuilder builder = new AddFeaturesToSetRequestBuilder(client());
builder.request().setFeatureSet("new_feature_set");
builder.request().setFeatures(features);
builder.request().setMerge(true);
@@ -191,7 +189,7 @@ public void testMergeWithList() throws Exception {
assertEquals(features.size(), set.size());
assertTrue(features.stream().map(StoredFeature::name).allMatch(set::hasFeature));
- builder= new AddFeaturesToSetRequestBuilder(client());
+ builder = new AddFeaturesToSetRequestBuilder(client());
builder.request().setFeatureSet("new_feature_set");
builder.request().setFeatures(asList(randomFeature("another_feature"), randomFeature("feature0")));
builder.request().setMerge(true);
@@ -200,7 +198,7 @@ public void testMergeWithList() throws Exception {
assertEquals(2, resp.getResponse().getVersion());
assertEquals(DocWriteResponse.Result.UPDATED, resp.getResponse().getResult());
set = getElement(StoredFeatureSet.class, StoredFeatureSet.TYPE, "new_feature_set");
- assertEquals(features.size()+1, set.size());
+ assertEquals(features.size() + 1, set.size());
assertTrue(set.hasFeature("another_feature"));
assertEquals(0, set.featureOrdinal("feature0"));
}
diff --git a/src/javaRestTest/java/com/o19s/es/ltr/action/BaseIntegrationTest.java b/src/javaRestTest/java/com/o19s/es/ltr/action/BaseIntegrationTest.java
index 98326bb5..8debb653 100644
--- a/src/javaRestTest/java/com/o19s/es/ltr/action/BaseIntegrationTest.java
+++ b/src/javaRestTest/java/com/o19s/es/ltr/action/BaseIntegrationTest.java
@@ -16,15 +16,22 @@
package com.o19s.es.ltr.action;
-import com.o19s.es.ltr.LtrQueryParserPlugin;
-import com.o19s.es.ltr.action.FeatureStoreAction.FeatureStoreRequestBuilder;
-import com.o19s.es.ltr.action.FeatureStoreAction.FeatureStoreResponse;
-import com.o19s.es.ltr.feature.FeatureValidation;
-import com.o19s.es.ltr.feature.store.StorableElement;
-import com.o19s.es.ltr.feature.store.index.IndexFeatureStore;
-import com.o19s.es.ltr.ranker.parser.LtrRankerParserFactory;
-import com.o19s.es.ltr.ranker.ranklib.RankLibScriptEngine;
+import static com.o19s.es.ltr.feature.store.ScriptFeature.EXTRA_LOGGING;
+import static com.o19s.es.ltr.feature.store.ScriptFeature.FEATURE_VECTOR;
+
+import java.io.IOException;
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.function.Supplier;
+
import org.apache.lucene.index.LeafReaderContext;
+import org.junit.Before;
import org.opensearch.action.DocWriteResponse;
import org.opensearch.action.admin.indices.create.CreateIndexAction;
import org.opensearch.action.admin.indices.create.CreateIndexResponse;
@@ -38,21 +45,15 @@
import org.opensearch.script.ScriptEngine;
import org.opensearch.test.OpenSearchSingleNodeTestCase;
import org.opensearch.test.TestGeoShapeFieldMapperPlugin;
-import org.junit.Before;
-import java.io.IOException;
-import java.util.AbstractMap;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-import java.util.function.Supplier;
-
-import static com.o19s.es.ltr.feature.store.ScriptFeature.EXTRA_LOGGING;
-import static com.o19s.es.ltr.feature.store.ScriptFeature.FEATURE_VECTOR;
+import com.o19s.es.ltr.LtrQueryParserPlugin;
+import com.o19s.es.ltr.action.FeatureStoreAction.FeatureStoreRequestBuilder;
+import com.o19s.es.ltr.action.FeatureStoreAction.FeatureStoreResponse;
+import com.o19s.es.ltr.feature.FeatureValidation;
+import com.o19s.es.ltr.feature.store.StorableElement;
+import com.o19s.es.ltr.feature.store.index.IndexFeatureStore;
+import com.o19s.es.ltr.ranker.parser.LtrRankerParserFactory;
+import com.o19s.es.ltr.ranker.ranklib.RankLibScriptEngine;
public abstract class BaseIntegrationTest extends OpenSearchSingleNodeTestCase {
@@ -61,8 +62,8 @@ public abstract class BaseIntegrationTest extends OpenSearchSingleNodeTestCase {
@Override
// TODO: Remove the TestGeoShapeFieldMapperPlugin once upstream has completed the migration.
protected Collection> getPlugins() {
- return Arrays.asList(LtrQueryParserPlugin.class, NativeScriptPlugin.class, InjectionScriptPlugin.class,
- TestGeoShapeFieldMapperPlugin.class);
+ return Arrays
+ .asList(LtrQueryParserPlugin.class, NativeScriptPlugin.class, InjectionScriptPlugin.class, TestGeoShapeFieldMapperPlugin.class);
}
public void createStore(String name) throws Exception {
@@ -89,8 +90,8 @@ public void createDefaultStore() throws Exception {
createStore(IndexFeatureStore.DEFAULT_STORE);
}
- public FeatureStoreResponse addElement(StorableElement element,
- FeatureValidation validation) throws ExecutionException, InterruptedException {
+ public FeatureStoreResponse addElement(StorableElement element, FeatureValidation validation) throws ExecutionException,
+ InterruptedException {
return addElement(element, validation, IndexFeatureStore.DEFAULT_STORE);
}
@@ -114,11 +115,10 @@ protected LtrRankerParserFactory parserFactory() {
return getInstanceFromNode(LtrRankerParserFactory.class);
}
- public FeatureStoreResponse addElement(StorableElement element,
- @Nullable FeatureValidation validation,
- String store) throws ExecutionException, InterruptedException {
- FeatureStoreRequestBuilder builder =
- new FeatureStoreRequestBuilder(client(), FeatureStoreAction.INSTANCE);
+ public FeatureStoreResponse addElement(StorableElement element, @Nullable FeatureValidation validation, String store)
+ throws ExecutionException,
+ InterruptedException {
+ FeatureStoreRequestBuilder builder = new FeatureStoreRequestBuilder(client(), FeatureStoreAction.INSTANCE);
builder.request().setStorableElement(element);
builder.request().setAction(FeatureStoreAction.FeatureStoreRequest.Action.CREATE);
builder.request().setStore(store);
@@ -160,38 +160,40 @@ public String getType() {
*/
@SuppressWarnings("unchecked")
@Override
- public FactoryType compile(String scriptName, String scriptSource,
- ScriptContext context, Map params) {
+ public FactoryType compile(
+ String scriptName,
+ String scriptSource,
+ ScriptContext context,
+ Map params
+ ) {
if (!context.equals(ScoreScript.CONTEXT) && (!context.equals(AGGS_CONTEXT))) {
- throw new IllegalArgumentException(getType() + " scripts cannot be used for context [" + context.name
- + "]");
+ throw new IllegalArgumentException(getType() + " scripts cannot be used for context [" + context.name + "]");
}
// we use the script "source" as the script identifier
- ScoreScript.Factory factory = (p, lookup, searcher) ->
- new ScoreScript.LeafFactory() {
+ ScoreScript.Factory factory = (p, lookup, searcher) -> new ScoreScript.LeafFactory() {
+ @Override
+ public ScoreScript newInstance(LeafReaderContext ctx) throws IOException {
+ return new ScoreScript(p, lookup, searcher, ctx) {
@Override
- public ScoreScript newInstance(LeafReaderContext ctx) throws IOException {
- return new ScoreScript(p, lookup, searcher, ctx) {
- @Override
- public double execute(ExplanationHolder explainationHolder) {
- // For testing purposes just look for the "terms" key and see if stats were injected
- if(p.containsKey("termStats")) {
- Supplier>> termStats = (Supplier>>) p.get("termStats");
- ArrayList dfStats = termStats.get().get("df");
- return dfStats.size() > 0 ? dfStats.get(0) : 0.0;
- } else {
- return 0.0;
- }
- }
- };
- }
-
- @Override
- public boolean needs_score() {
- return false;
+ public double execute(ExplanationHolder explainationHolder) {
+ // For testing purposes just look for the "terms" key and see if stats were injected
+ if (p.containsKey("termStats")) {
+ Supplier>> termStats =
+ (Supplier>>) p.get("termStats");
+ ArrayList dfStats = termStats.get().get("df");
+ return dfStats.size() > 0 ? dfStats.get(0) : 0.0;
+ } else {
+ return 0.0;
+ }
}
};
+ }
+
+ @Override
+ public boolean needs_score() {
+ return false;
+ }
+ };
return context.factoryClazz.cast(factory);
}
@@ -204,7 +206,6 @@ public Set> getSupportedContexts() {
}
}
-
public static class NativeScriptPlugin extends Plugin implements ScriptPlugin {
public static final String FEATURE_EXTRACTOR = "feature_extractor";
@@ -231,94 +232,94 @@ public String getType() {
*/
@SuppressWarnings("unchecked")
@Override
- public FactoryType compile(String scriptName, String scriptSource,
- ScriptContext context, Map params) {
+ public FactoryType compile(
+ String scriptName,
+ String scriptSource,
+ ScriptContext context,
+ Map params
+ ) {
if (!context.equals(ScoreScript.CONTEXT) && (!context.equals(AGGS_CONTEXT))) {
- throw new IllegalArgumentException(getType() + " scripts cannot be used for context [" + context.name
- + "]");
+ throw new IllegalArgumentException(getType() + " scripts cannot be used for context [" + context.name + "]");
}
// we use the script "source" as the script identifier
if (FEATURE_EXTRACTOR.equals(scriptSource)) {
- ScoreScript.Factory factory = (p, lookup, searcher) ->
- new ScoreScript.LeafFactory() {
- final Map featureSupplier;
- final String dependentFeature;
- double extraMultiplier = 0.0d;
-
- public static final String DEPENDENT_FEATURE = "dependent_feature";
- public static final String EXTRA_SCRIPT_PARAM = "extra_multiplier";
-
- {
- if (!p.containsKey(FEATURE_VECTOR)) {
- throw new IllegalArgumentException("Missing parameter [" + FEATURE_VECTOR + "]");
- }
- if (!p.containsKey(EXTRA_LOGGING)) {
- throw new IllegalArgumentException("Missing parameter [" + EXTRA_LOGGING + "]");
- }
- if (!p.containsKey(DEPENDENT_FEATURE)) {
- throw new IllegalArgumentException("Missing parameter [depdendent_feature ]");
- }
- if (p.containsKey(EXTRA_SCRIPT_PARAM)) {
- extraMultiplier = Double.valueOf(p.get(EXTRA_SCRIPT_PARAM).toString());
- }
- featureSupplier = (Map) p.get(FEATURE_VECTOR);
- dependentFeature = p.get(DEPENDENT_FEATURE).toString();
- }
+ ScoreScript.Factory factory = (p, lookup, searcher) -> new ScoreScript.LeafFactory() {
+ final Map featureSupplier;
+ final String dependentFeature;
+ double extraMultiplier = 0.0d;
- @Override
- public ScoreScript newInstance(LeafReaderContext ctx) throws IOException {
- return new ScoreScript(p, lookup, searcher, ctx) {
- @Override
- public double execute(ExplanationHolder explainationHolder ) {
- return extraMultiplier == 0.0d ?
- featureSupplier.get(dependentFeature) * 10 :
- featureSupplier.get(dependentFeature) * extraMultiplier;
- }
- };
- }
+ public static final String DEPENDENT_FEATURE = "dependent_feature";
+ public static final String EXTRA_SCRIPT_PARAM = "extra_multiplier";
+ {
+ if (!p.containsKey(FEATURE_VECTOR)) {
+ throw new IllegalArgumentException("Missing parameter [" + FEATURE_VECTOR + "]");
+ }
+ if (!p.containsKey(EXTRA_LOGGING)) {
+ throw new IllegalArgumentException("Missing parameter [" + EXTRA_LOGGING + "]");
+ }
+ if (!p.containsKey(DEPENDENT_FEATURE)) {
+ throw new IllegalArgumentException("Missing parameter [depdendent_feature ]");
+ }
+ if (p.containsKey(EXTRA_SCRIPT_PARAM)) {
+ extraMultiplier = Double.valueOf(p.get(EXTRA_SCRIPT_PARAM).toString());
+ }
+ featureSupplier = (Map) p.get(FEATURE_VECTOR);
+ dependentFeature = p.get(DEPENDENT_FEATURE).toString();
+ }
+
+ @Override
+ public ScoreScript newInstance(LeafReaderContext ctx) throws IOException {
+ return new ScoreScript(p, lookup, searcher, ctx) {
@Override
- public boolean needs_score() {
- return false;
+ public double execute(ExplanationHolder explainationHolder) {
+ return extraMultiplier == 0.0d
+ ? featureSupplier.get(dependentFeature) * 10
+ : featureSupplier.get(dependentFeature) * extraMultiplier;
}
};
+ }
+
+ @Override
+ public boolean needs_score() {
+ return false;
+ }
+ };
return context.factoryClazz.cast(factory);
- }
- else if (scriptSource.equals(FEATURE_EXTRACTOR + "_extra_logging")) {
- ScoreScript.Factory factory = (p, lookup, searcher) ->
- new ScoreScript.LeafFactory() {
- {
- if (!p.containsKey(FEATURE_VECTOR)) {
- throw new IllegalArgumentException("Missing parameter [" + FEATURE_VECTOR + "]");
- }
- if (!p.containsKey(EXTRA_LOGGING)) {
- throw new IllegalArgumentException("Missing parameter [" + EXTRA_LOGGING + "]");
- }
- }
+ } else if (scriptSource.equals(FEATURE_EXTRACTOR + "_extra_logging")) {
+ ScoreScript.Factory factory = (p, lookup, searcher) -> new ScoreScript.LeafFactory() {
+ {
+ if (!p.containsKey(FEATURE_VECTOR)) {
+ throw new IllegalArgumentException("Missing parameter [" + FEATURE_VECTOR + "]");
+ }
+ if (!p.containsKey(EXTRA_LOGGING)) {
+ throw new IllegalArgumentException("Missing parameter [" + EXTRA_LOGGING + "]");
+ }
+ }
- @Override
- public ScoreScript newInstance(LeafReaderContext ctx) throws IOException {
- return new ScoreScript(p, lookup, searcher, ctx) {
-
- @Override
- public double execute(ExplanationHolder explanation) {
- Map extraLoggingMap = ((Supplier