Apache Solr open-source search software
SOLR-16029: Enable spotless on ltr module
Kevin Risden5dd6bf1c30a6
diff --git a/gradle/validation/spotless.gradle b/gradle/validation/spotless.gradleindex a6c1472b588..2fe84516dc8 100644--- a/gradle/validation/spotless.gradle+++ b/gradle/validation/spotless.gradle@@ -59,9 +59,6 @@ configure(project(":solr").subprojects) { prj ->case ":solr:test-framework":targetExclude "src/**/*.java"break- case ":solr:modules:ltr":- targetExclude "src/test/**/*.java"- break}}}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/FeatureLoggerTestUtils.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/FeatureLoggerTestUtils.javaindex f2afd9c5281..41747ef7389 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/FeatureLoggerTestUtils.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/FeatureLoggerTestUtils.java@@ -18,27 +18,25 @@ package org.apache.solr.ltr;public class FeatureLoggerTestUtils {- public static String toFeatureVector(String ... keysAndValues) {+ public static String toFeatureVector(String... keysAndValues) {return toFeatureVector(CSVFeatureLogger.DEFAULT_KEY_VALUE_SEPARATOR,CSVFeatureLogger.DEFAULT_FEATURE_SEPARATOR,keysAndValues);}- public static String toFeatureVector(char keyValueSeparator, char featureSeparator,- String ... keysAndValues) {- StringBuilder sb = new StringBuilder(keysAndValues.length/2 * 3);- for (int ii = 0; ii+1 < keysAndValues.length; ii += 2) {- sb.append(keysAndValues[ii])- .append(keyValueSeparator)- .append(keysAndValues[ii+1])- .append(featureSeparator);+ public static String toFeatureVector(+ char keyValueSeparator, char featureSeparator, String... keysAndValues) {+ StringBuilder sb = new StringBuilder(keysAndValues.length / 2 * 3);+ for (int ii = 0; ii + 1 < keysAndValues.length; ii += 2) {+ sb.append(keysAndValues[ii])+ .append(keyValueSeparator)+ .append(keysAndValues[ii + 1])+ .append(featureSeparator);}- final String features = (sb.length() > 0 ?- sb.substring(0, sb.length() - 1) : "");+ final String features = (sb.length() > 0 ? sb.substring(0, sb.length() - 1) : "");return features;}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTROnSolrCloud.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTROnSolrCloud.javaindex 91f07921e53..d64cba9b8b9 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTROnSolrCloud.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTROnSolrCloud.java@@ -15,12 +15,13 @@*/package org.apache.solr.ltr;+import static java.util.stream.Collectors.toList;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;import java.io.File;import java.util.Collections;import java.util.List;import java.util.stream.IntStream;-import org.apache.commons.io.FileUtils;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.embedded.JettyConfig;@@ -40,8 +41,6 @@ import org.apache.solr.util.RestTestHarness;import org.junit.AfterClass;import org.junit.Test;-import static java.util.stream.Collectors.toList;-@ThreadLeakLingering(linger = 10)public class TestLTROnSolrCloud extends TestRerankBase {@@ -55,15 +54,14 @@ public class TestLTROnSolrCloud extends TestRerankBase {setupTestInit(solrconfig, schema, true);System.setProperty("enable.update.log", "true");- int numberOfShards = random().nextInt(4)+1;- int numberOfReplicas = random().nextInt(2)+1;+ int numberOfShards = random().nextInt(4) + 1;+ int numberOfReplicas = random().nextInt(2) + 1;int numberOfNodes = numberOfShards * numberOfReplicas;setupSolrCluster(numberOfShards, numberOfReplicas, numberOfNodes);}-@Overridepublic void tearDown() throws Exception {restTestHarness.close();@@ -73,8 +71,11 @@ public class TestLTROnSolrCloud extends TestRerankBase {}@Test- // commented 4-Sep-2018 @LuceneTestCase.BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 2-Aug-2018- // commented out on: 24-Dec-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 14-Oct-2018+ // commented 4-Sep-2018+ // @LuceneTestCase.BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") //+ // 2-Aug-2018+ // commented out on: 24-Dec-2018+ // @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 14-Oct-2018public void testSimpleQuery() throws Exception {// will randomly pick a configuration with [1..5] shards and [1..3] replicas@@ -87,8 +88,7 @@ public class TestLTROnSolrCloud extends TestRerankBase {query.setFields("*,score");query.setParam("rows", "8");- QueryResponse queryResponse =- solrCluster.getSolrClient().query(COLLECTION,query);+ QueryResponse queryResponse = solrCluster.getSolrClient().query(COLLECTION, query);assertEquals(8, queryResponse.getResults().getNumFound());assertEquals("1", queryResponse.getResults().get(0).get("id").toString());assertEquals("2", queryResponse.getResults().get(1).get("id").toString());@@ -99,53 +99,179 @@ public class TestLTROnSolrCloud extends TestRerankBase {assertEquals("7", queryResponse.getResults().get(6).get("id").toString());assertEquals("8", queryResponse.getResults().get(7).get("id").toString());- final Float original_result0_score = (Float)queryResponse.getResults().get(0).get("score");- final Float original_result1_score = (Float)queryResponse.getResults().get(1).get("score");- final Float original_result2_score = (Float)queryResponse.getResults().get(2).get("score");- final Float original_result3_score = (Float)queryResponse.getResults().get(3).get("score");- final Float original_result4_score = (Float)queryResponse.getResults().get(4).get("score");- final Float original_result5_score = (Float)queryResponse.getResults().get(5).get("score");- final Float original_result6_score = (Float)queryResponse.getResults().get(6).get("score");- final Float original_result7_score = (Float)queryResponse.getResults().get(7).get("score");-- final String result0_features = FeatureLoggerTestUtils.toFeatureVector(- "powpularityS", "64.0", "c3", "2.0", "original", "0.0", "dvIntFieldFeature", "8.0",- "dvLongFieldFeature", "8.0", "dvFloatFieldFeature", "0.8", "dvDoubleFieldFeature", "0.8",- "dvStrNumFieldFeature", "0.0", "dvStrBoolFieldFeature", "1.0");- final String result1_features = FeatureLoggerTestUtils.toFeatureVector(- "powpularityS", "49.0", "c3", "2.0", "original", "1.0", "dvIntFieldFeature", "7.0",- "dvLongFieldFeature", "7.0", "dvFloatFieldFeature", "0.7", "dvDoubleFieldFeature", "0.7",- "dvStrNumFieldFeature", "1.0", "dvStrBoolFieldFeature", "0.0");- final String result2_features = FeatureLoggerTestUtils.toFeatureVector(- "powpularityS", "36.0", "c3", "2.0", "original", "2.0", "dvIntFieldFeature", "6.0",- "dvLongFieldFeature", "6.0", "dvFloatFieldFeature", "0.6", "dvDoubleFieldFeature", "0.6",- "dvStrNumFieldFeature", "0.0", "dvStrBoolFieldFeature", "1.0");- final String result3_features = FeatureLoggerTestUtils.toFeatureVector(- "powpularityS", "25.0", "c3", "2.0", "original", "3.0", "dvIntFieldFeature", "5.0",- "dvLongFieldFeature", "5.0", "dvFloatFieldFeature", "0.5", "dvDoubleFieldFeature", "0.5",- "dvStrNumFieldFeature", "1.0", "dvStrBoolFieldFeature", "0.0");- final String result4_features = FeatureLoggerTestUtils.toFeatureVector(- "powpularityS", "16.0", "c3", "2.0", "original", "4.0", "dvIntFieldFeature", "4.0",- "dvLongFieldFeature", "4.0", "dvFloatFieldFeature", "0.4", "dvDoubleFieldFeature", "0.4",- "dvStrNumFieldFeature", "0.0", "dvStrBoolFieldFeature", "1.0");- final String result5_features = FeatureLoggerTestUtils.toFeatureVector(- "powpularityS", "9.0", "c3", "2.0", "original", "5.0", "dvIntFieldFeature", "3.0",- "dvLongFieldFeature", "3.0", "dvFloatFieldFeature", "0.3", "dvDoubleFieldFeature", "0.3",- "dvStrNumFieldFeature", "1.0", "dvStrBoolFieldFeature", "0.0");- final String result6_features = FeatureLoggerTestUtils.toFeatureVector(- "powpularityS", "4.0", "c3", "2.0", "original", "6.0", "dvIntFieldFeature", "2.0",- "dvLongFieldFeature", "2.0", "dvFloatFieldFeature", "0.2", "dvDoubleFieldFeature", "0.2",- "dvStrNumFieldFeature", "0.0", "dvStrBoolFieldFeature", "1.0");- final String result7_features = FeatureLoggerTestUtils.toFeatureVector(- "powpularityS", "1.0", "c3", "2.0", "original", "7.0", "dvIntFieldFeature", "-1.0",- "dvLongFieldFeature", "-2.0", "dvFloatFieldFeature", "-3.0", "dvDoubleFieldFeature", "-4.0",- "dvStrNumFieldFeature", "-5.0", "dvStrBoolFieldFeature", "0.0");-+ final Float original_result0_score = (Float) queryResponse.getResults().get(0).get("score");+ final Float original_result1_score = (Float) queryResponse.getResults().get(1).get("score");+ final Float original_result2_score = (Float) queryResponse.getResults().get(2).get("score");+ final Float original_result3_score = (Float) queryResponse.getResults().get(3).get("score");+ final Float original_result4_score = (Float) queryResponse.getResults().get(4).get("score");+ final Float original_result5_score = (Float) queryResponse.getResults().get(5).get("score");+ final Float original_result6_score = (Float) queryResponse.getResults().get(6).get("score");+ final Float original_result7_score = (Float) queryResponse.getResults().get(7).get("score");++ final String result0_features =+ FeatureLoggerTestUtils.toFeatureVector(+ "powpularityS",+ "64.0",+ "c3",+ "2.0",+ "original",+ "0.0",+ "dvIntFieldFeature",+ "8.0",+ "dvLongFieldFeature",+ "8.0",+ "dvFloatFieldFeature",+ "0.8",+ "dvDoubleFieldFeature",+ "0.8",+ "dvStrNumFieldFeature",+ "0.0",+ "dvStrBoolFieldFeature",+ "1.0");+ final String result1_features =+ FeatureLoggerTestUtils.toFeatureVector(+ "powpularityS",+ "49.0",+ "c3",+ "2.0",+ "original",+ "1.0",+ "dvIntFieldFeature",+ "7.0",+ "dvLongFieldFeature",+ "7.0",+ "dvFloatFieldFeature",+ "0.7",+ "dvDoubleFieldFeature",+ "0.7",+ "dvStrNumFieldFeature",+ "1.0",+ "dvStrBoolFieldFeature",+ "0.0");+ final String result2_features =+ FeatureLoggerTestUtils.toFeatureVector(+ "powpularityS",+ "36.0",+ "c3",+ "2.0",+ "original",+ "2.0",+ "dvIntFieldFeature",+ "6.0",+ "dvLongFieldFeature",+ "6.0",+ "dvFloatFieldFeature",+ "0.6",+ "dvDoubleFieldFeature",+ "0.6",+ "dvStrNumFieldFeature",+ "0.0",+ "dvStrBoolFieldFeature",+ "1.0");+ final String result3_features =+ FeatureLoggerTestUtils.toFeatureVector(+ "powpularityS",+ "25.0",+ "c3",+ "2.0",+ "original",+ "3.0",+ "dvIntFieldFeature",+ "5.0",+ "dvLongFieldFeature",+ "5.0",+ "dvFloatFieldFeature",+ "0.5",+ "dvDoubleFieldFeature",+ "0.5",+ "dvStrNumFieldFeature",+ "1.0",+ "dvStrBoolFieldFeature",+ "0.0");+ final String result4_features =+ FeatureLoggerTestUtils.toFeatureVector(+ "powpularityS",+ "16.0",+ "c3",+ "2.0",+ "original",+ "4.0",+ "dvIntFieldFeature",+ "4.0",+ "dvLongFieldFeature",+ "4.0",+ "dvFloatFieldFeature",+ "0.4",+ "dvDoubleFieldFeature",+ "0.4",+ "dvStrNumFieldFeature",+ "0.0",+ "dvStrBoolFieldFeature",+ "1.0");+ final String result5_features =+ FeatureLoggerTestUtils.toFeatureVector(+ "powpularityS",+ "9.0",+ "c3",+ "2.0",+ "original",+ "5.0",+ "dvIntFieldFeature",+ "3.0",+ "dvLongFieldFeature",+ "3.0",+ "dvFloatFieldFeature",+ "0.3",+ "dvDoubleFieldFeature",+ "0.3",+ "dvStrNumFieldFeature",+ "1.0",+ "dvStrBoolFieldFeature",+ "0.0");+ final String result6_features =+ FeatureLoggerTestUtils.toFeatureVector(+ "powpularityS",+ "4.0",+ "c3",+ "2.0",+ "original",+ "6.0",+ "dvIntFieldFeature",+ "2.0",+ "dvLongFieldFeature",+ "2.0",+ "dvFloatFieldFeature",+ "0.2",+ "dvDoubleFieldFeature",+ "0.2",+ "dvStrNumFieldFeature",+ "0.0",+ "dvStrBoolFieldFeature",+ "1.0");+ final String result7_features =+ FeatureLoggerTestUtils.toFeatureVector(+ "powpularityS",+ "1.0",+ "c3",+ "2.0",+ "original",+ "7.0",+ "dvIntFieldFeature",+ "-1.0",+ "dvLongFieldFeature",+ "-2.0",+ "dvFloatFieldFeature",+ "-3.0",+ "dvDoubleFieldFeature",+ "-4.0",+ "dvStrNumFieldFeature",+ "-5.0",+ "dvStrBoolFieldFeature",+ "0.0");// Test feature vectors returned (without re-ranking)query.setFields("*,score,features:[fv store=test]");- queryResponse =- solrCluster.getSolrClient().query(COLLECTION,query);+ queryResponse = solrCluster.getSolrClient().query(COLLECTION, query);assertEquals(8, queryResponse.getResults().getNumFound());assertEquals("1", queryResponse.getResults().get(0).get("id").toString());assertEquals("2", queryResponse.getResults().get(1).get("id").toString());@@ -165,53 +291,36 @@ public class TestLTROnSolrCloud extends TestRerankBase {assertEquals(original_result6_score, queryResponse.getResults().get(6).get("score"));assertEquals(original_result7_score, queryResponse.getResults().get(7).get("score"));- assertEquals(result7_features,- queryResponse.getResults().get(0).get("features").toString());- assertEquals(result6_features,- queryResponse.getResults().get(1).get("features").toString());- assertEquals(result5_features,- queryResponse.getResults().get(2).get("features").toString());- assertEquals(result4_features,- queryResponse.getResults().get(3).get("features").toString());- assertEquals(result3_features,- queryResponse.getResults().get(4).get("features").toString());- assertEquals(result2_features,- queryResponse.getResults().get(5).get("features").toString());- assertEquals(result1_features,- queryResponse.getResults().get(6).get("features").toString());- assertEquals(result0_features,- queryResponse.getResults().get(7).get("features").toString());+ assertEquals(result7_features, queryResponse.getResults().get(0).get("features").toString());+ assertEquals(result6_features, queryResponse.getResults().get(1).get("features").toString());+ assertEquals(result5_features, queryResponse.getResults().get(2).get("features").toString());+ assertEquals(result4_features, queryResponse.getResults().get(3).get("features").toString());+ assertEquals(result3_features, queryResponse.getResults().get(4).get("features").toString());+ assertEquals(result2_features, queryResponse.getResults().get(5).get("features").toString());+ assertEquals(result1_features, queryResponse.getResults().get(6).get("features").toString());+ assertEquals(result0_features, queryResponse.getResults().get(7).get("features").toString());// Test feature vectors returned (with re-ranking)query.setFields("*,score,features:[fv]");query.add("rq", "{!ltr model=powpularityS-model reRankDocs=8}");- queryResponse =- solrCluster.getSolrClient().query(COLLECTION,query);+ queryResponse = solrCluster.getSolrClient().query(COLLECTION, query);assertEquals(8, queryResponse.getResults().getNumFound());assertEquals("8", queryResponse.getResults().get(0).get("id").toString());- assertEquals(result0_features,- queryResponse.getResults().get(0).get("features").toString());+ assertEquals(result0_features, queryResponse.getResults().get(0).get("features").toString());assertEquals("7", queryResponse.getResults().get(1).get("id").toString());- assertEquals(result1_features,- queryResponse.getResults().get(1).get("features").toString());+ assertEquals(result1_features, queryResponse.getResults().get(1).get("features").toString());assertEquals("6", queryResponse.getResults().get(2).get("id").toString());- assertEquals(result2_features,- queryResponse.getResults().get(2).get("features").toString());+ assertEquals(result2_features, queryResponse.getResults().get(2).get("features").toString());assertEquals("5", queryResponse.getResults().get(3).get("id").toString());- assertEquals(result3_features,- queryResponse.getResults().get(3).get("features").toString());+ assertEquals(result3_features, queryResponse.getResults().get(3).get("features").toString());assertEquals("4", queryResponse.getResults().get(4).get("id").toString());- assertEquals(result4_features,- queryResponse.getResults().get(4).get("features").toString());+ assertEquals(result4_features, queryResponse.getResults().get(4).get("features").toString());assertEquals("3", queryResponse.getResults().get(5).get("id").toString());- assertEquals(result5_features,- queryResponse.getResults().get(5).get("features").toString());+ assertEquals(result5_features, queryResponse.getResults().get(5).get("features").toString());assertEquals("2", queryResponse.getResults().get(6).get("id").toString());- assertEquals(result6_features,- queryResponse.getResults().get(6).get("features").toString());+ assertEquals(result6_features, queryResponse.getResults().get(6).get("features").toString());assertEquals("1", queryResponse.getResults().get(7).get("id").toString());- assertEquals(result7_features,- queryResponse.getResults().get(7).get("features").toString());+ assertEquals(result7_features, queryResponse.getResults().get(7).get("features").toString());}private void setupSolrCluster(int numShards, int numReplicas, int numServers) throws Exception {@@ -226,16 +335,16 @@ public class TestLTROnSolrCloud extends TestRerankBase {createCollection(COLLECTION, "conf1", numShards, numReplicas);indexDocuments(COLLECTION);for (JettySolrRunner solrRunner : solrCluster.getJettySolrRunners()) {- if (!solrRunner.getCoreContainer().getCores().isEmpty()){+ if (!solrRunner.getCoreContainer().getCores().isEmpty()) {String coreName = solrRunner.getCoreContainer().getCores().iterator().next().getName();- restTestHarness = new RestTestHarness(() -> solrRunner.getBaseUrl().toString() + "/" + coreName);+ restTestHarness =+ new RestTestHarness(() -> solrRunner.getBaseUrl().toString() + "/" + coreName);break;}}loadModelsAndFeatures();}-private void createCollection(String name, String config, int numShards, int numReplicas)throws Exception {CollectionAdminResponse response;@@ -250,9 +359,8 @@ public class TestLTROnSolrCloud extends TestRerankBase {solrCluster.waitForActiveCollection(name, numShards, numShards * numReplicas);}-void indexDocument(String collection, String id, String title, String description, int popularity)- throws Exception{+ throws Exception {SolrInputDocument doc = new SolrInputDocument();doc.setField("id", id);doc.setField("title", title);@@ -270,8 +378,7 @@ public class TestLTROnSolrCloud extends TestRerankBase {solrCluster.getSolrClient().add(collection, doc);}- private void indexDocuments(final String collection)- throws Exception {+ private void indexDocuments(final String collection) throws Exception {final int collectionSize = 8;// put documents in random order to check that advanceExact is working correctlyList<Integer> docIds = IntStream.rangeClosed(1, collectionSize).boxed().collect(toList());@@ -281,7 +388,8 @@ public class TestLTROnSolrCloud extends TestRerankBase {for (int docId : docIds) {final int popularity = docId;indexDocument(collection, String.valueOf(docId), "a1", "bloom", popularity);- // maybe commit in the middle in order to check that everything works fine for multi-segment case+ // maybe commit in the middle in order to check that everything works fine for multi-segment+ // caseif (docCounter == collectionSize / 2 && random().nextBoolean()) {solrCluster.getSolrClient().commit(collection);}@@ -292,79 +400,73 @@ public class TestLTROnSolrCloud extends TestRerankBase {private void loadModelsAndFeatures() throws Exception {final String featureStore = "test";- final String[] featureNames = new String[]{"powpularityS", "c3", "original", "dvIntFieldFeature",- "dvLongFieldFeature", "dvFloatFieldFeature", "dvDoubleFieldFeature", "dvStrNumFieldFeature", "dvStrBoolFieldFeature"};- final String jsonModelParams = "{\"weights\":{\"powpularityS\":1.0,\"c3\":1.0,\"original\":0.1," +- "\"dvIntFieldFeature\":0.1,\"dvLongFieldFeature\":0.1," +- "\"dvFloatFieldFeature\":0.1,\"dvDoubleFieldFeature\":0.1,\"dvStrNumFieldFeature\":0.1,\"dvStrBoolFieldFeature\":0.1}}";+ final String[] featureNames =+ new String[] {+ "powpularityS",+ "c3",+ "original",+ "dvIntFieldFeature",+ "dvLongFieldFeature",+ "dvFloatFieldFeature",+ "dvDoubleFieldFeature",+ "dvStrNumFieldFeature",+ "dvStrBoolFieldFeature"+ };+ final String jsonModelParams =+ "{\"weights\":{\"powpularityS\":1.0,\"c3\":1.0,\"original\":0.1,"+ + "\"dvIntFieldFeature\":0.1,\"dvLongFieldFeature\":0.1,"+ + "\"dvFloatFieldFeature\":0.1,\"dvDoubleFieldFeature\":0.1,\"dvStrNumFieldFeature\":0.1,\"dvStrBoolFieldFeature\":0.1}}";loadFeature(featureNames[0],SolrFeature.class.getName(),featureStore,- "{\"q\":\"{!func}pow(popularity,2)\"}"- );- loadFeature(- featureNames[1],- ValueFeature.class.getName(),- featureStore,- "{\"value\":2}"- );- loadFeature(- featureNames[2],- OriginalScoreFeature.class.getName(),- featureStore,- null- );+ "{\"q\":\"{!func}pow(popularity,2)\"}");+ loadFeature(featureNames[1], ValueFeature.class.getName(), featureStore, "{\"value\":2}");+ loadFeature(featureNames[2], OriginalScoreFeature.class.getName(), featureStore, null);loadFeature(featureNames[3],FieldValueFeature.class.getName(),featureStore,- "{\"field\":\"dvIntField\"}"- );+ "{\"field\":\"dvIntField\"}");loadFeature(featureNames[4],FieldValueFeature.class.getName(),featureStore,- "{\"field\":\"dvLongField\"}"- );+ "{\"field\":\"dvLongField\"}");loadFeature(featureNames[5],FieldValueFeature.class.getName(),featureStore,- "{\"field\":\"dvFloatField\"}"- );+ "{\"field\":\"dvFloatField\"}");loadFeature(featureNames[6],FieldValueFeature.class.getName(),featureStore,- "{\"field\":\"dvDoubleField\",\"defaultValue\":-4.0}"- );+ "{\"field\":\"dvDoubleField\",\"defaultValue\":-4.0}");loadFeature(featureNames[7],FieldValueFeature.class.getName(),featureStore,- "{\"field\":\"dvStrNumField\",\"defaultValue\":-5}"- );+ "{\"field\":\"dvStrNumField\",\"defaultValue\":-5}");loadFeature(featureNames[8],FieldValueFeature.class.getName(),featureStore,- "{\"field\":\"dvStrBoolField\"}"- );+ "{\"field\":\"dvStrBoolField\"}");loadModel("powpularityS-model",LinearModel.class.getName(),featureNames,featureStore,- jsonModelParams- );+ jsonModelParams);reloadCollection(COLLECTION);}private void reloadCollection(String collection) throws Exception {- CollectionAdminRequest.Reload reloadRequest = CollectionAdminRequest.reloadCollection(collection);+ CollectionAdminRequest.Reload reloadRequest =+ CollectionAdminRequest.reloadCollection(collection);CollectionAdminResponse response = reloadRequest.process(solrCluster.getSolrClient());assertEquals(0, response.getStatus());assertTrue(response.isSuccess());@@ -378,5 +480,4 @@ public class TestLTROnSolrCloud extends TestRerankBase {}System.clearProperty("managed.schema.mutable");}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRQParserExplain.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRQParserExplain.javaindex 0b154a28b15..fd944460218 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRQParserExplain.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRQParserExplain.java@@ -17,7 +17,6 @@package org.apache.solr.ltr;import java.util.Random;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.feature.SolrFeature;import org.apache.solr.ltr.interleaving.algorithms.TeamDraftInterleaving;@@ -39,11 +38,12 @@ public class TestLTRQParserExplain extends TestRerankBase {aftertest();}-@Testpublic void testRerankedExplain() throws Exception {- loadModel("linear2", LinearModel.class.getName(), new String[] {- "constant1", "constant2", "pop"},+ loadModel(+ "linear2",+ LinearModel.class.getName(),+ new String[] {"constant1", "constant2", "pop"},"{\"weights\":{\"pop\":1.0,\"constant1\":1.5,\"constant2\":3.5}}");final SolrQuery query = new SolrQuery();@@ -71,22 +71,21 @@ public class TestLTRQParserExplain extends TestRerankBase {query.add("fl", "*,score");query.add("wt", "json");final String expectedExplainNormalizer = "normalized using MinMaxNormalizer(min=0.0,max=10.0)";- final String expectedExplain = "\n3.5116758 = LinearModel(name=6029760550880411648,featureWeights=["- + "title=0.0,"- + "description=0.1,"- + "keywords=0.2,"- + "popularity=0.3,"- + "text=0.4,"- + "queryIntentPerson=0.1231231,"- + "queryIntentCompany=0.12121211"- + "]) model applied to features, sum of:\n 0.0 = prod of:\n 0.0 = weight on feature\n 1.0 = ValueFeature [name=title, params={value=1}]\n 0.2 = prod of:\n 0.1 = weight on feature\n 2.0 = ValueFeature [name=description, params={value=2}]\n 0.4 = prod of:\n 0.2 = weight on feature\n 2.0 = ValueFeature [name=keywords, params={value=2}]\n 0.09 = prod of:\n 0.3 = weight on feature\n 0.3 = "+expectedExplainNormalizer+"\n 3.0 = ValueFeature [name=popularity, params={value=3}]\n 1.6 = prod of:\n 0.4 = weight on feature\n 4.0 = ValueFeature [name=text, params={value=4}]\n 0.6156155 = prod of:\n 0.1231231 = weight on feature\n 5.0 = ValueFeature [name=queryIntentPerson, params={value=5}]\n 0.60606056 = prod of:\n 0.12121211 = weight on feature\n 5.0 = ValueFeature [name=queryIntentCompany, params={value=5}]\n";-- assertJQ(- "/query" + query.toQueryString(),- "/debug/explain/7=='"+expectedExplain+"'}");- assertJQ(- "/query" + query.toQueryString(),- "/debug/explain/9=='"+expectedExplain+"'}");+ final String expectedExplain =+ "\n3.5116758 = LinearModel(name=6029760550880411648,featureWeights=["+ + "title=0.0,"+ + "description=0.1,"+ + "keywords=0.2,"+ + "popularity=0.3,"+ + "text=0.4,"+ + "queryIntentPerson=0.1231231,"+ + "queryIntentCompany=0.12121211"+ + "]) model applied to features, sum of:\n 0.0 = prod of:\n 0.0 = weight on feature\n 1.0 = ValueFeature [name=title, params={value=1}]\n 0.2 = prod of:\n 0.1 = weight on feature\n 2.0 = ValueFeature [name=description, params={value=2}]\n 0.4 = prod of:\n 0.2 = weight on feature\n 2.0 = ValueFeature [name=keywords, params={value=2}]\n 0.09 = prod of:\n 0.3 = weight on feature\n 0.3 = "+ + expectedExplainNormalizer+ + "\n 3.0 = ValueFeature [name=popularity, params={value=3}]\n 1.6 = prod of:\n 0.4 = weight on feature\n 4.0 = ValueFeature [name=text, params={value=4}]\n 0.6156155 = prod of:\n 0.1231231 = weight on feature\n 5.0 = ValueFeature [name=queryIntentPerson, params={value=5}]\n 0.60606056 = prod of:\n 0.12121211 = weight on feature\n 5.0 = ValueFeature [name=queryIntentCompany, params={value=5}]\n";++ assertJQ("/query" + query.toQueryString(), "/debug/explain/7=='" + expectedExplain + "'}");+ assertJQ("/query" + query.toQueryString(), "/debug/explain/9=='" + expectedExplain + "'}");}@Test@@ -102,28 +101,34 @@ public class TestLTRQParserExplain extends TestRerankBase {query.add("fl", "*,score");query.add("wt", "xml");- final String linearModelEfiString = "LinearModel(name=linear-efi,featureWeights=["- + "sampleConstant=1.0,"- + "search_number_of_nights=2.0])";+ final String linearModelEfiString =+ "LinearModel(name=linear-efi,featureWeights=["+ + "sampleConstant=1.0,"+ + "search_number_of_nights=2.0])";query.remove("wt");query.add("wt", "json");assertJQ("/query" + query.toQueryString(),- "/debug/explain/7=='\n5.0 = "+linearModelEfiString+" model applied to features, sum of:\n 5.0 = prod of:\n 1.0 = weight on feature\n 5.0 = ValueFeature [name=sampleConstant, params={value=5}]\n" +- " 0.0 = prod of:\n" +- " 2.0 = weight on feature\n" +- " 0.0 = The feature has no value\n'}");+ "/debug/explain/7=='\n5.0 = "+ + linearModelEfiString+ + " model applied to features, sum of:\n 5.0 = prod of:\n 1.0 = weight on feature\n 5.0 = ValueFeature [name=sampleConstant, params={value=5}]\n"+ + " 0.0 = prod of:\n"+ + " 2.0 = weight on feature\n"+ + " 0.0 = The feature has no value\n'}");assertJQ("/query" + query.toQueryString(),- "/debug/explain/9=='\n5.0 = "+linearModelEfiString+" model applied to features, sum of:\n 5.0 = prod of:\n 1.0 = weight on feature\n 5.0 = ValueFeature [name=sampleConstant, params={value=5}]\n" +- " 0.0 = prod of:\n" +- " 2.0 = weight on feature\n" +- " 0.0 = The feature has no value\n'}");+ "/debug/explain/9=='\n5.0 = "+ + linearModelEfiString+ + " model applied to features, sum of:\n 5.0 = prod of:\n 1.0 = weight on feature\n 5.0 = ValueFeature [name=sampleConstant, params={value=5}]\n"+ + " 0.0 = prod of:\n"+ + " 2.0 = weight on feature\n"+ + " 0.0 = The feature has no value\n'}");}@Test- public void multipleAdditiveTreesScoreExplainMissingEfiFeatureShouldReturnDefaultScore() throws Exception {+ public void multipleAdditiveTreesScoreExplainMissingEfiFeatureShouldReturnDefaultScore()+ throws Exception {loadFeatures("external_features_for_sparse_processing.json");loadModels("multipleadditivetreesmodel_external_binary_features.json");@@ -131,49 +136,58 @@ public class TestLTRQParserExplain extends TestRerankBase {query.setQuery("title:bloomberg");query.setParam("debugQuery", "on");query.add("rows", "4");- query.add("rq", "{!ltr reRankDocs=4 model=external_model_binary_feature efi.user_device_tablet=1}");+ query.add(+ "rq", "{!ltr reRankDocs=4 model=external_model_binary_feature efi.user_device_tablet=1}");query.add("fl", "*,score");- final String tree1 = "(weight=1.0,root=(feature=user_device_smartphone,threshold=0.5,left=0.0,right=50.0))";- final String tree2 = "(weight=1.0,root=(feature=user_device_tablet,threshold=0.5,left=0.0,right=65.0))";- final String trees = "["+tree1+","+tree2+"]";+ final String tree1 =+ "(weight=1.0,root=(feature=user_device_smartphone,threshold=0.5,left=0.0,right=50.0))";+ final String tree2 =+ "(weight=1.0,root=(feature=user_device_tablet,threshold=0.5,left=0.0,right=65.0))";+ final String trees = "[" + tree1 + "," + tree2 + "]";query.add("wt", "json");assertJQ("/query" + query.toQueryString(),- "/debug/explain/7=='\n" +- "65.0 = MultipleAdditiveTreesModel(name=external_model_binary_feature,trees="+trees+") model applied to features, sum of:\n" +- " 0.0 = tree 0 | \\'user_device_smartphone\\':0.0 <= 0.500001, Go Left | val: 0.0\n" +- " 65.0 = tree 1 | \\'user_device_tablet\\':1.0 > 0.500001, Go Right | val: 65.0\n'}");+ "/debug/explain/7=='\n"+ + "65.0 = MultipleAdditiveTreesModel(name=external_model_binary_feature,trees="+ + trees+ + ") model applied to features, sum of:\n"+ + " 0.0 = tree 0 | \\'user_device_smartphone\\':0.0 <= 0.500001, Go Left | val: 0.0\n"+ + " 65.0 = tree 1 | \\'user_device_tablet\\':1.0 > 0.500001, Go Right | val: 65.0\n'}");assertJQ("/query" + query.toQueryString(),- "/debug/explain/9=='\n" +- "65.0 = MultipleAdditiveTreesModel(name=external_model_binary_feature,trees="+trees+") model applied to features, sum of:\n" +- " 0.0 = tree 0 | \\'user_device_smartphone\\':0.0 <= 0.500001, Go Left | val: 0.0\n" +- " 65.0 = tree 1 | \\'user_device_tablet\\':1.0 > 0.500001, Go Right | val: 65.0\n'}");+ "/debug/explain/9=='\n"+ + "65.0 = MultipleAdditiveTreesModel(name=external_model_binary_feature,trees="+ + trees+ + ") model applied to features, sum of:\n"+ + " 0.0 = tree 0 | \\'user_device_smartphone\\':0.0 <= 0.500001, Go Left | val: 0.0\n"+ + " 65.0 = tree 1 | \\'user_device_tablet\\':1.0 > 0.500001, Go Right | val: 65.0\n'}");}@Testpublic void interleavingModels_shouldReturnExplainForTheModelPicked() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10));//Random Boolean Choices Generation from Seed: [1,0]-- loadFeature("featureA1", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=popularity}1\"]}");- loadFeature("featureA2", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=description}bloomberg\"]}");- loadFeature("featureAB", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=popularity}2\"]}");- loadFeature("featureB1", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=popularity}5\"]}");- loadFeature("featureB2", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=title}different\"]}");-- loadModel("modelA", LinearModel.class.getName(),- new String[]{"featureA1", "featureA2", "featureAB"},+ TeamDraftInterleaving.setRANDOM(+ new Random(10)); // Random Boolean Choices Generation from Seed: [1,0]++ loadFeature("featureA1", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=popularity}1\"]}");+ loadFeature(+ "featureA2", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=description}bloomberg\"]}");+ loadFeature("featureAB", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=popularity}2\"]}");+ loadFeature("featureB1", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=popularity}5\"]}");+ loadFeature(+ "featureB2", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=title}different\"]}");++ loadModel(+ "modelA",+ LinearModel.class.getName(),+ new String[] {"featureA1", "featureA2", "featureAB"},"{\"weights\":{\"featureA1\":3.0, \"featureA2\":9.0, \"featureAB\":27.0}}");- loadModel("modelB", LinearModel.class.getName(),- new String[]{"featureB1", "featureB2", "featureAB"},+ loadModel(+ "modelB",+ LinearModel.class.getName(),+ new String[] {"featureB1", "featureB2", "featureAB"},"{\"weights\":{\"featureB1\":2.0, \"featureB2\":4.0, \"featureAB\":8.0}}");final SolrQuery query = new SolrQuery();@@ -188,65 +202,72 @@ public class TestLTRQParserExplain extends TestRerankBase {Doc7 = "featureA2=1.0 featureAB=1.0", ScoreA(36), ScoreB(8)Doc8 = "featureA2=1.0", ScoreA(9), ScoreB(0)Doc9 = "featureA2=1.0 featureB1=1.0", ScoreA(9), ScoreB(2)-+ModelARerankedList = [7,6,8,9]ModelBRerankedList = [7,6,9,8]Random Boolean Choices Generation from Seed: [1,0]-+*/- int[] expectedInterleaved = new int[]{7, 6, 8, 9};- String[] expectedExplains = new String[]{- "\n8.0 = LinearModel(name=modelB," +- "featureWeights=[featureB1=2.0,featureB2=4.0,featureAB=8.0]) " +- "model applied to features, sum of:\n " +- "0.0 = prod of:\n 2.0 = weight on feature\n 0.0 = SolrFeature [name=featureB1, params={fq=[{!terms f=popularity}5]}]\n " +- "0.0 = prod of:\n 4.0 = weight on feature\n 0.0 = SolrFeature [name=featureB2, params={fq=[{!terms f=title}different]}]\n " +- "8.0 = prod of:\n 8.0 = weight on feature\n 1.0 = SolrFeature [name=featureAB, params={fq=[{!terms f=popularity}2]}]\n",- "\n12.0 = LinearModel(name=modelA," +- "featureWeights=[featureA1=3.0,featureA2=9.0,featureAB=27.0]) " +- "model applied to features, sum of:\n " +- "3.0 = prod of:\n 3.0 = weight on feature\n 1.0 = SolrFeature [name=featureA1, params={fq=[{!terms f=popularity}1]}]\n " +- "9.0 = prod of:\n 9.0 = weight on feature\n 1.0 = SolrFeature [name=featureA2, params={fq=[{!terms f=description}bloomberg]}]\n " +- "0.0 = prod of:\n 27.0 = weight on feature\n 0.0 = SolrFeature [name=featureAB, params={fq=[{!terms f=popularity}2]}]\n",- "\n9.0 = LinearModel(name=modelA," +- "featureWeights=[featureA1=3.0,featureA2=9.0,featureAB=27.0]) " +- "model applied to features, sum of:\n " +- "0.0 = prod of:\n 3.0 = weight on feature\n 0.0 = SolrFeature [name=featureA1, params={fq=[{!terms f=popularity}1]}]\n " +- "9.0 = prod of:\n 9.0 = weight on feature\n 1.0 = SolrFeature [name=featureA2, params={fq=[{!terms f=description}bloomberg]}]\n " +- "0.0 = prod of:\n 27.0 = weight on feature\n 0.0 = SolrFeature [name=featureAB, params={fq=[{!terms f=popularity}2]}]\n",- "\n2.0 = LinearModel(name=modelB," +- "featureWeights=[featureB1=2.0,featureB2=4.0,featureAB=8.0]) " +- "model applied to features, sum of:\n " +- "2.0 = prod of:\n 2.0 = weight on feature\n 1.0 = SolrFeature [name=featureB1, params={fq=[{!terms f=popularity}5]}]\n " +- "0.0 = prod of:\n 4.0 = weight on feature\n 0.0 = SolrFeature [name=featureB2, params={fq=[{!terms f=title}different]}]\n " +- "0.0 = prod of:\n 8.0 = weight on feature\n 0.0 = SolrFeature [name=featureAB, params={fq=[{!terms f=popularity}2]}]\n"};--+ int[] expectedInterleaved = new int[] {7, 6, 8, 9};+ String[] expectedExplains =+ new String[] {+ "\n8.0 = LinearModel(name=modelB,"+ + "featureWeights=[featureB1=2.0,featureB2=4.0,featureAB=8.0]) "+ + "model applied to features, sum of:\n "+ + "0.0 = prod of:\n 2.0 = weight on feature\n 0.0 = SolrFeature [name=featureB1, params={fq=[{!terms f=popularity}5]}]\n "+ + "0.0 = prod of:\n 4.0 = weight on feature\n 0.0 = SolrFeature [name=featureB2, params={fq=[{!terms f=title}different]}]\n "+ + "8.0 = prod of:\n 8.0 = weight on feature\n 1.0 = SolrFeature [name=featureAB, params={fq=[{!terms f=popularity}2]}]\n",+ "\n12.0 = LinearModel(name=modelA,"+ + "featureWeights=[featureA1=3.0,featureA2=9.0,featureAB=27.0]) "+ + "model applied to features, sum of:\n "+ + "3.0 = prod of:\n 3.0 = weight on feature\n 1.0 = SolrFeature [name=featureA1, params={fq=[{!terms f=popularity}1]}]\n "+ + "9.0 = prod of:\n 9.0 = weight on feature\n 1.0 = SolrFeature [name=featureA2, params={fq=[{!terms f=description}bloomberg]}]\n "+ + "0.0 = prod of:\n 27.0 = weight on feature\n 0.0 = SolrFeature [name=featureAB, params={fq=[{!terms f=popularity}2]}]\n",+ "\n9.0 = LinearModel(name=modelA,"+ + "featureWeights=[featureA1=3.0,featureA2=9.0,featureAB=27.0]) "+ + "model applied to features, sum of:\n "+ + "0.0 = prod of:\n 3.0 = weight on feature\n 0.0 = SolrFeature [name=featureA1, params={fq=[{!terms f=popularity}1]}]\n "+ + "9.0 = prod of:\n 9.0 = weight on feature\n 1.0 = SolrFeature [name=featureA2, params={fq=[{!terms f=description}bloomberg]}]\n "+ + "0.0 = prod of:\n 27.0 = weight on feature\n 0.0 = SolrFeature [name=featureAB, params={fq=[{!terms f=popularity}2]}]\n",+ "\n2.0 = LinearModel(name=modelB,"+ + "featureWeights=[featureB1=2.0,featureB2=4.0,featureAB=8.0]) "+ + "model applied to features, sum of:\n "+ + "2.0 = prod of:\n 2.0 = weight on feature\n 1.0 = SolrFeature [name=featureB1, params={fq=[{!terms f=popularity}5]}]\n "+ + "0.0 = prod of:\n 4.0 = weight on feature\n 0.0 = SolrFeature [name=featureB2, params={fq=[{!terms f=title}different]}]\n "+ + "0.0 = prod of:\n 8.0 = weight on feature\n 0.0 = SolrFeature [name=featureAB, params={fq=[{!terms f=popularity}2]}]\n"+ };String[] tests = new String[16];tests[0] = "/response/numFound/==4";for (int i = 1; i <= 4; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 4] = "/debug/explain/" + expectedInterleaved[(i - 1)] + "=='" + expectedExplains[(i - 1)]+"'}";+ tests[i + 4] =+ "/debug/explain/"+ + expectedInterleaved[(i - 1)]+ + "=='"+ + expectedExplains[(i - 1)]+ + "'}";}assertJQ("/query" + query.toQueryString(), tests);}@Test- public void interleavingModelsWithOriginalRanking_shouldReturnExplainForTheModelPicked() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10));//Random Boolean Choices Generation from Seed: [1,0]-- loadFeature("featureA1", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=popularity}1\"]}");- loadFeature("featureA2", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=description}bloomberg\"]}");- loadFeature("featureAB", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=popularity}2\"]}");-- loadModel("modelA", LinearModel.class.getName(),- new String[]{"featureA1", "featureA2", "featureAB"},+ public void interleavingModelsWithOriginalRanking_shouldReturnExplainForTheModelPicked()+ throws Exception {+ TeamDraftInterleaving.setRANDOM(+ new Random(10)); // Random Boolean Choices Generation from Seed: [1,0]++ loadFeature("featureA1", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=popularity}1\"]}");+ loadFeature(+ "featureA2", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=description}bloomberg\"]}");+ loadFeature("featureAB", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=popularity}2\"]}");++ loadModel(+ "modelA",+ LinearModel.class.getName(),+ new String[] {"featureA1", "featureA2", "featureAB"},"{\"weights\":{\"featureA1\":3.0, \"featureA2\":9.0, \"featureAB\":27.0}}");final SolrQuery query = new SolrQuery();@@ -261,52 +282,58 @@ public class TestLTRQParserExplain extends TestRerankBase {Doc7 = "featureA2=1.0 featureAB=1.0", ScoreA(36)Doc8 = "featureA2=1.0", ScoreA(9)Doc9 = "featureA2=1.0 featureB1=1.0", ScoreA(9)-+ModelARerankedList = [7,6,8,9]OriginalRanking = [9,8,7,6]Random Boolean Choices Generation from Seed: [1,0]-+*/- int[] expectedInterleaved = new int[]{9, 7, 6, 8};- String[] expectedExplains = new String[]{- "\n0.07662583 = weight(title:bloomberg in 3) [SchemaSimilarity], result of:\n " +- "0.07662583 = score(freq=4.0), computed as boost * idf * tf from:\n " +- "0.105360515 = idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:\n 4 = n, number of documents containing term\n 4 = N, total number of documents with field\n " +- "0.72727275 = tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:\n 4.0 = freq, occurrences of term within document\n " +- "1.2 = k1, term saturation parameter\n " +- "0.75 = b, length normalization parameter\n " +- "4.0 = dl, length of field\n " +- "3.0 = avgdl, average length of field\n",- "\n36.0 = LinearModel(name=modelA," +- "featureWeights=[featureA1=3.0,featureA2=9.0,featureAB=27.0]) " +- "model applied to features, sum of:\n " +- "0.0 = prod of:\n 3.0 = weight on feature\n 0.0 = SolrFeature [name=featureA1, params={fq=[{!terms f=popularity}1]}]\n " +- "9.0 = prod of:\n 9.0 = weight on feature\n 1.0 = SolrFeature [name=featureA2, params={fq=[{!terms f=description}bloomberg]}]\n " +- "27.0 = prod of:\n 27.0 = weight on feature\n 1.0 = SolrFeature [name=featureAB, params={fq=[{!terms f=popularity}2]}]\n",- "\n12.0 = LinearModel(name=modelA," +- "featureWeights=[featureA1=3.0,featureA2=9.0,featureAB=27.0]) " +- "model applied to features, sum of:\n " +- "3.0 = prod of:\n 3.0 = weight on feature\n 1.0 = SolrFeature [name=featureA1, params={fq=[{!terms f=popularity}1]}]\n " +- "9.0 = prod of:\n 9.0 = weight on feature\n 1.0 = SolrFeature [name=featureA2, params={fq=[{!terms f=description}bloomberg]}]\n " +- "0.0 = prod of:\n 27.0 = weight on feature\n 0.0 = SolrFeature [name=featureAB, params={fq=[{!terms f=popularity}2]}]\n",- "\n0.07525751 = weight(title:bloomberg in 2) [SchemaSimilarity], result of:\n " +- "0.07525751 = score(freq=3.0), computed as boost * idf * tf from:\n " +- "0.105360515 = idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:\n 4 = n, number of documents containing term\n 4 = N, total number of documents with field\n " +- "0.71428573 = tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:\n 3.0 = freq, occurrences of term within document\n " +- "1.2 = k1, term saturation parameter\n " +- "0.75 = b, length normalization parameter\n " +- "3.0 = dl, length of field\n " +- "3.0 = avgdl, average length of field\n"};+ int[] expectedInterleaved = new int[] {9, 7, 6, 8};+ String[] expectedExplains =+ new String[] {+ "\n0.07662583 = weight(title:bloomberg in 3) [SchemaSimilarity], result of:\n "+ + "0.07662583 = score(freq=4.0), computed as boost * idf * tf from:\n "+ + "0.105360515 = idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:\n 4 = n, number of documents containing term\n 4 = N, total number of documents with field\n "+ + "0.72727275 = tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:\n 4.0 = freq, occurrences of term within document\n "+ + "1.2 = k1, term saturation parameter\n "+ + "0.75 = b, length normalization parameter\n "+ + "4.0 = dl, length of field\n "+ + "3.0 = avgdl, average length of field\n",+ "\n36.0 = LinearModel(name=modelA,"+ + "featureWeights=[featureA1=3.0,featureA2=9.0,featureAB=27.0]) "+ + "model applied to features, sum of:\n "+ + "0.0 = prod of:\n 3.0 = weight on feature\n 0.0 = SolrFeature [name=featureA1, params={fq=[{!terms f=popularity}1]}]\n "+ + "9.0 = prod of:\n 9.0 = weight on feature\n 1.0 = SolrFeature [name=featureA2, params={fq=[{!terms f=description}bloomberg]}]\n "+ + "27.0 = prod of:\n 27.0 = weight on feature\n 1.0 = SolrFeature [name=featureAB, params={fq=[{!terms f=popularity}2]}]\n",+ "\n12.0 = LinearModel(name=modelA,"+ + "featureWeights=[featureA1=3.0,featureA2=9.0,featureAB=27.0]) "+ + "model applied to features, sum of:\n "+ + "3.0 = prod of:\n 3.0 = weight on feature\n 1.0 = SolrFeature [name=featureA1, params={fq=[{!terms f=popularity}1]}]\n "+ + "9.0 = prod of:\n 9.0 = weight on feature\n 1.0 = SolrFeature [name=featureA2, params={fq=[{!terms f=description}bloomberg]}]\n "+ + "0.0 = prod of:\n 27.0 = weight on feature\n 0.0 = SolrFeature [name=featureAB, params={fq=[{!terms f=popularity}2]}]\n",+ "\n0.07525751 = weight(title:bloomberg in 2) [SchemaSimilarity], result of:\n "+ + "0.07525751 = score(freq=3.0), computed as boost * idf * tf from:\n "+ + "0.105360515 = idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:\n 4 = n, number of documents containing term\n 4 = N, total number of documents with field\n "+ + "0.71428573 = tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:\n 3.0 = freq, occurrences of term within document\n "+ + "1.2 = k1, term saturation parameter\n "+ + "0.75 = b, length normalization parameter\n "+ + "3.0 = dl, length of field\n "+ + "3.0 = avgdl, average length of field\n"+ };String[] tests = new String[16];tests[0] = "/response/numFound/==4";for (int i = 1; i <= 4; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 4] = "/debug/explain/" + expectedInterleaved[(i - 1)] + "=='" + expectedExplains[(i - 1)]+"'}";+ tests[i + 4] =+ "/debug/explain/"+ + expectedInterleaved[(i - 1)]+ + "=='"+ + expectedExplains[(i - 1)]+ + "'}";}assertJQ("/query" + query.toQueryString(), tests);}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRQParserPlugin.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRQParserPlugin.javaindex 6730b9b5b8c..1bdca68ce58 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRQParserPlugin.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRQParserPlugin.java@@ -23,7 +23,6 @@ import org.junit.Test;public class TestLTRQParserPlugin extends TestRerankBase {-@BeforeClasspublic static void before() throws Exception {setuptest(true);@@ -106,24 +105,26 @@ public class TestLTRQParserPlugin extends TestRerankBase {// String nonRerankedScore = "0.09271725";// Normal solr order- assertJQ("/query" + query.toQueryString(),+ assertJQ(+ "/query" + query.toQueryString(),"/response/docs/[0]/id=='9'","/response/docs/[1]/id=='8'","/response/docs/[2]/id=='7'","/response/docs/[3]/id=='6'"- // "/response/docs/[3]/score=="+nonRerankedScore- );+ // "/response/docs/[3]/score=="+nonRerankedScore+ );query.add("rq", "{!ltr model=6029760550880411648 reRankDocs=3}");// Different order for top 3 reranked, but last one is the same top nonreranked doc- assertJQ("/query" + query.toQueryString(),+ assertJQ(+ "/query" + query.toQueryString(),"/response/docs/[0]/id=='7'","/response/docs/[1]/id=='8'","/response/docs/[2]/id=='9'","/response/docs/[3]/id=='6'"- // "/response/docs/[3]/score=="+nonRerankedScore- );+ // "/response/docs/[3]/score=="+nonRerankedScore+ );}@Test@@ -136,5 +137,4 @@ public class TestLTRQParserPlugin extends TestRerankBase {query.add("rq", "{!ltr reRankDocs=3 model=6029760550880411648}");assertJQ("/query" + query.toQueryString(), "/response/numFound/==0");}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRReRankingPipeline.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRReRankingPipeline.javaindex e8a69422ae0..6c749cd99d0 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRReRankingPipeline.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRReRankingPipeline.java@@ -17,14 +17,13 @@package org.apache.solr.ltr;import java.io.IOException;-import java.nio.file.Paths;import java.lang.invoke.MethodHandles;+import java.nio.file.Paths;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.List;import java.util.Map;-import org.apache.lucene.index.LeafReaderContext;import org.apache.lucene.index.Term;import org.apache.lucene.search.BooleanClause;@@ -56,22 +55,22 @@ public class TestLTRReRankingPipeline extends SolrTestCaseJ4 {private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());- private static final SolrResourceLoader solrResourceLoader = new SolrResourceLoader(Paths.get("").toAbsolutePath());+ private static final SolrResourceLoader solrResourceLoader =+ new SolrResourceLoader(Paths.get("").toAbsolutePath());@BeforeClasspublic static void setup() throws Exception {initCore("solrconfig-ltr.xml", "schema.xml");}- private static List<Feature> makeFieldValueFeatures(int[] featureIds,- String field) {+ private static List<Feature> makeFieldValueFeatures(int[] featureIds, String field) {final List<Feature> features = new ArrayList<>();for (final int i : featureIds) {- final Map<String,Object> params = new HashMap<String,Object>();+ final Map<String, Object> params = new HashMap<String, Object>();params.put("field", field);- final Feature f = Feature.getInstance(solrResourceLoader,- FieldValueFeature.class.getName(),- "f" + i, params);+ final Feature f =+ Feature.getInstance(+ solrResourceLoader, FieldValueFeature.class.getName(), "f" + i, params);f.setIndex(i);features.add(f);}@@ -80,10 +79,13 @@ public class TestLTRReRankingPipeline extends SolrTestCaseJ4 {private static class MockModel extends LTRScoringModel {- public MockModel(String name, List<Feature> features,+ public MockModel(+ String name,+ List<Feature> features,List<Normalizer> norms,- String featureStoreName, List<Feature> allFeatures,- Map<String,Object> params) {+ String featureStoreName,+ List<Feature> allFeatures,+ Map<String, Object> params) {super(name, features, norms, featureStoreName, allFeatures, params);}@@ -93,11 +95,13 @@ public class TestLTRReRankingPipeline extends SolrTestCaseJ4 {}@Override- public Explanation explain(LeafReaderContext context, int doc,- float finalScore, List<Explanation> featureExplanations) {+ public Explanation explain(+ LeafReaderContext context,+ int doc,+ float finalScore,+ List<Explanation> featureExplanations) {return null;}-}@Test@@ -107,7 +111,8 @@ public class TestLTRReRankingPipeline extends SolrTestCaseJ4 {assertU(adoc("id", "1", "field", "wizard oz the the the the the the", "finalScore", "T"));assertU(commit());- try (SolrQueryRequest solrQueryRequest = new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams())) {+ try (SolrQueryRequest solrQueryRequest =+ new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams())) {final BooleanQuery.Builder bqBuilder = new BooleanQuery.Builder();bqBuilder.add(new TermQuery(new Term("field", "wizard")), BooleanClause.Occur.SHOULD);@@ -119,15 +124,20 @@ public class TestLTRReRankingPipeline extends SolrTestCaseJ4 {assertEquals("0", searcher.doc(hits.scoreDocs[0].doc).get("id"));assertEquals("1", searcher.doc(hits.scoreDocs[1].doc).get("id"));- final List<Feature> features = makeFieldValueFeatures(new int[] {0, 1, 2},- "finalScore");+ final List<Feature> features = makeFieldValueFeatures(new int[] {0, 1, 2}, "finalScore");final List<Normalizer> norms =- new ArrayList<Normalizer>(- Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));- final List<Feature> allFeatures = makeFieldValueFeatures(new int[] {0, 1,- 2, 3, 4, 5, 6, 7, 8, 9}, "finalScore");- final LTRScoringModel ltrScoringModel = TestLinearModel.createLinearModel("test",- features, norms, "test", allFeatures, TestLinearModel.makeFeatureWeights(features));+ new ArrayList<Normalizer>(+ Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));+ final List<Feature> allFeatures =+ makeFieldValueFeatures(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, "finalScore");+ final LTRScoringModel ltrScoringModel =+ TestLinearModel.createLinearModel(+ "test",+ features,+ norms,+ "test",+ allFeatures,+ TestLinearModel.makeFeatureWeights(features));LTRScoringQuery ltrScoringQuery = new LTRScoringQuery(ltrScoringModel);ltrScoringQuery.setRequest(solrQueryRequest);@@ -147,10 +157,12 @@ public class TestLTRReRankingPipeline extends SolrTestCaseJ4 {assertU(adoc("id", "1", "field", "wizard oz oz oz oz the", "finalScoreFloat", "2.0"));assertU(adoc("id", "2", "field", "wizard oz oz oz the the ", "finalScoreFloat", "3.0"));assertU(adoc("id", "3", "field", "wizard oz oz the the the the ", "finalScoreFloat", "4.0"));- assertU(adoc("id", "4", "field", "wizard oz the the the the the the", "finalScoreFloat", "5.0"));+ assertU(+ adoc("id", "4", "field", "wizard oz the the the the the the", "finalScoreFloat", "5.0"));assertU(commit());- try (SolrQueryRequest solrQueryRequest = new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams())) {+ try (SolrQueryRequest solrQueryRequest =+ new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams())) {// Do ordinary BooleanQuery:final BooleanQuery.Builder bqBuilder = new BooleanQuery.Builder();bqBuilder.add(new TermQuery(new Term("field", "wizard")), BooleanClause.Occur.SHOULD);@@ -167,16 +179,21 @@ public class TestLTRReRankingPipeline extends SolrTestCaseJ4 {assertEquals("3", searcher.doc(hits.scoreDocs[3].doc).get("id"));assertEquals("4", searcher.doc(hits.scoreDocs[4].doc).get("id"));- final List<Feature> features = makeFieldValueFeatures(new int[] {0, 1, 2},- "finalScoreFloat");+ final List<Feature> features = makeFieldValueFeatures(new int[] {0, 1, 2}, "finalScoreFloat");final List<Normalizer> norms =- new ArrayList<Normalizer>(- Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));- final List<Feature> allFeatures = makeFieldValueFeatures(new int[] {0, 1,- 2, 3, 4, 5, 6, 7, 8, 9}, "finalScoreFloat");+ new ArrayList<Normalizer>(+ Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));+ final List<Feature> allFeatures =+ makeFieldValueFeatures(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, "finalScoreFloat");final Double featureWeight = 0.1;- final LTRScoringModel ltrScoringModel = TestLinearModel.createLinearModel("test",- features, norms, "test", allFeatures, TestLinearModel.makeFeatureWeights(features, featureWeight));+ final LTRScoringModel ltrScoringModel =+ TestLinearModel.createLinearModel(+ "test",+ features,+ norms,+ "test",+ allFeatures,+ TestLinearModel.makeFeatureWeights(features, featureWeight));LTRScoringQuery scoringQuery = new LTRScoringQuery(ltrScoringModel);scoringQuery.setRequest(solrQueryRequest);@@ -202,13 +219,10 @@ public class TestLTRReRankingPipeline extends SolrTestCaseJ4 {hits = rescorer.rescore(searcher, hits, topN);for (int i = topN - 1, j = 0; i >= 0; i--, j++) {if (log.isInfoEnabled()) {- log.info("doc {} in pos {}", searcher.doc(hits.scoreDocs[j].doc)- .get("id"), j);+ log.info("doc {} in pos {}", searcher.doc(hits.scoreDocs[j].doc).get("id"), j);}- assertEquals(i,- Integer.parseInt(searcher.doc(hits.scoreDocs[j].doc).get("id")));- assertEquals((i + 1) * features.size()*featureWeight, hits.scoreDocs[j].score, 0.00001);-+ assertEquals(i, Integer.parseInt(searcher.doc(hits.scoreDocs[j].doc).get("id")));+ assertEquals((i + 1) * features.size() * featureWeight, hits.scoreDocs[j].score, 0.00001);}}}@@ -216,40 +230,38 @@ public class TestLTRReRankingPipeline extends SolrTestCaseJ4 {@Testpublic void testDocParam() throws Exception {- try (SolrQueryRequest solrQueryRequest = new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams())) {- List<Feature> features = makeFieldValueFeatures(new int[] {0},- "finalScore");+ try (SolrQueryRequest solrQueryRequest =+ new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams())) {+ List<Feature> features = makeFieldValueFeatures(new int[] {0}, "finalScore");List<Normalizer> norms =- new ArrayList<Normalizer>(- Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));- List<Feature> allFeatures = makeFieldValueFeatures(new int[] {0},- "finalScore");- MockModel ltrScoringModel = new MockModel("test",- features, norms, "test", allFeatures, null);+ new ArrayList<Normalizer>(+ Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));+ List<Feature> allFeatures = makeFieldValueFeatures(new int[] {0}, "finalScore");+ MockModel ltrScoringModel = new MockModel("test", features, norms, "test", allFeatures, null);LTRScoringQuery query = new LTRScoringQuery(ltrScoringModel);query.setRequest(solrQueryRequest);LTRScoringQuery.ModelWeight wgt = query.createWeight(null, ScoreMode.COMPLETE, 1f);LTRScoringQuery.ModelWeight.ModelScorer modelScr = wgt.scorer(null);modelScr.getDocInfo().setOriginalDocScore(1f);for (final Scorable.ChildScorable feat : modelScr.getChildren()) {- assertNotNull(((Feature.FeatureWeight.FeatureScorer) feat.child).getDocInfo().getOriginalDocScore());+ assertNotNull(+ ((Feature.FeatureWeight.FeatureScorer) feat.child).getDocInfo().getOriginalDocScore());}features = makeFieldValueFeatures(new int[] {0, 1, 2}, "finalScore");norms =- new ArrayList<Normalizer>(- Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));- allFeatures = makeFieldValueFeatures(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8,- 9}, "finalScore");- ltrScoringModel = new MockModel("test", features, norms,- "test", allFeatures, null);+ new ArrayList<Normalizer>(+ Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));+ allFeatures = makeFieldValueFeatures(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, "finalScore");+ ltrScoringModel = new MockModel("test", features, norms, "test", allFeatures, null);query = new LTRScoringQuery(ltrScoringModel);query.setRequest(solrQueryRequest);wgt = query.createWeight(null, ScoreMode.COMPLETE, 1f);modelScr = wgt.scorer(null);modelScr.getDocInfo().setOriginalDocScore(1f);for (final Scorable.ChildScorable feat : modelScr.getChildren()) {- assertNotNull(((Feature.FeatureWeight.FeatureScorer) feat.child).getDocInfo().getOriginalDocScore());+ assertNotNull(+ ((Feature.FeatureWeight.FeatureScorer) feat.child).getDocInfo().getOriginalDocScore());}}}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.javaindex 71df1ed1ef3..9008218df74 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java@@ -24,7 +24,6 @@ import java.util.HashMap;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;-import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.document.FloatDocValuesField;@@ -56,7 +55,8 @@ import org.junit.Test;public class TestLTRScoringQuery extends SolrTestCase {- public final static SolrResourceLoader solrResourceLoader = new SolrResourceLoader(Paths.get("").toAbsolutePath());+ public static final SolrResourceLoader solrResourceLoader =+ new SolrResourceLoader(Paths.get("").toAbsolutePath());private IndexSearcher getSearcher(IndexReader r) {final IndexSearcher searcher = newSearcher(r, false, false);@@ -66,11 +66,10 @@ public class TestLTRScoringQuery extends SolrTestCase {private static List<Feature> makeFeatures(int[] featureIds) {final List<Feature> features = new ArrayList<>();for (final int i : featureIds) {- Map<String,Object> params = new HashMap<String,Object>();+ Map<String, Object> params = new HashMap<String, Object>();params.put("value", i);- final Feature f = Feature.getInstance(solrResourceLoader,- ValueFeature.class.getName(),- "f" + i, params);+ final Feature f =+ Feature.getInstance(solrResourceLoader, ValueFeature.class.getName(), "f" + i, params);f.setIndex(i);features.add(f);}@@ -80,22 +79,20 @@ public class TestLTRScoringQuery extends SolrTestCase {private static List<Feature> makeFilterFeatures(int[] featureIds) {final List<Feature> features = new ArrayList<>();for (final int i : featureIds) {- Map<String,Object> params = new HashMap<String,Object>();+ Map<String, Object> params = new HashMap<String, Object>();params.put("value", i);- final Feature f = Feature.getInstance(solrResourceLoader,- ValueFeature.class.getName(),- "f" + i, params);+ final Feature f =+ Feature.getInstance(solrResourceLoader, ValueFeature.class.getName(), "f" + i, params);f.setIndex(i);features.add(f);}return features;}- private LTRScoringQuery.ModelWeight performQuery(TopDocs hits,- IndexSearcher searcher, int docid, LTRScoringQuery model) throws IOException,- ModelException {- final List<LeafReaderContext> leafContexts = searcher.getTopReaderContext()- .leaves();+ private LTRScoringQuery.ModelWeight performQuery(+ TopDocs hits, IndexSearcher searcher, int docid, LTRScoringQuery model)+ throws IOException, ModelException {+ final List<LeafReaderContext> leafContexts = searcher.getTopReaderContext().leaves();final int n = ReaderUtil.subIndex(hits.scoreDocs[0].doc, leafContexts);final LeafReaderContext context = leafContexts.get(n);final int deBasedDoc = hits.scoreDocs[0].doc - context.docBase;@@ -113,7 +110,6 @@ public class TestLTRScoringQuery extends SolrTestCase {assertTrue(weight instanceof LTRScoringQuery.ModelWeight);final LTRScoringQuery.ModelWeight modelWeight = (LTRScoringQuery.ModelWeight) weight;return modelWeight;-}@Test@@ -121,29 +117,28 @@ public class TestLTRScoringQuery extends SolrTestCase {final List<Feature> features = makeFeatures(new int[] {0, 1, 2});final List<Normalizer> norms =new ArrayList<Normalizer>(- Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));- final List<Feature> allFeatures = makeFeatures(- new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});- final Map<String,Object> modelParams = TestLinearModel.makeFeatureWeights(features);+ Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));+ final List<Feature> allFeatures = makeFeatures(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});+ final Map<String, Object> modelParams = TestLinearModel.makeFeatureWeights(features);- final LTRScoringModel algorithm1 = TestLinearModel.createLinearModel(- "testModelName",- features, norms, "testStoreName", allFeatures, modelParams);+ final LTRScoringModel algorithm1 =+ TestLinearModel.createLinearModel(+ "testModelName", features, norms, "testStoreName", allFeatures, modelParams);final LTRScoringQuery m0 = new LTRScoringQuery(algorithm1);- final HashMap<String,String[]> externalFeatureInfo = new HashMap<>();+ final HashMap<String, String[]> externalFeatureInfo = new HashMap<>();externalFeatureInfo.put("queryIntent", new String[] {"company"});externalFeatureInfo.put("user_query", new String[] {"abc"});final LTRScoringQuery m1 = new LTRScoringQuery(algorithm1, externalFeatureInfo, false, null);- final HashMap<String,String[]> externalFeatureInfo2 = new HashMap<>();+ final HashMap<String, String[]> externalFeatureInfo2 = new HashMap<>();externalFeatureInfo2.put("user_query", new String[] {"abc"});externalFeatureInfo2.put("queryIntent", new String[] {"company"});int totalPoolThreads = 10, numThreadsPerRequest = 10;LTRThreadModule threadManager = new LTRThreadModule(totalPoolThreads, numThreadsPerRequest);- final LTRScoringQuery m2 = new LTRScoringQuery(algorithm1, externalFeatureInfo2, false, threadManager);-+ final LTRScoringQuery m2 =+ new LTRScoringQuery(algorithm1, externalFeatureInfo2, false, threadManager);// Models with same algorithm and efis, just in different order should be the sameassertEquals(m1, m2);@@ -153,25 +148,23 @@ public class TestLTRScoringQuery extends SolrTestCase {assertFalse(m1.equals(m0));assertFalse(m1.hashCode() == m0.hashCode());-- final LTRScoringModel algorithm2 = TestLinearModel.createLinearModel(- "testModelName2",- features, norms, "testStoreName", allFeatures, modelParams);+ final LTRScoringModel algorithm2 =+ TestLinearModel.createLinearModel(+ "testModelName2", features, norms, "testStoreName", allFeatures, modelParams);final LTRScoringQuery m3 = new LTRScoringQuery(algorithm2);assertFalse(m1.equals(m3));assertFalse(m1.hashCode() == m3.hashCode());- final LTRScoringModel algorithm3 = TestLinearModel.createLinearModel(- "testModelName",- features, norms, "testStoreName3", allFeatures, modelParams);+ final LTRScoringModel algorithm3 =+ TestLinearModel.createLinearModel(+ "testModelName", features, norms, "testStoreName3", allFeatures, modelParams);final LTRScoringQuery m4 = new LTRScoringQuery(algorithm3);assertFalse(m1.equals(m4));assertFalse(m1.hashCode() == m4.hashCode());}-@Testpublic void testLTRScoringQuery() throws IOException, ModelException {final Directory dir = newDirectory();@@ -179,16 +172,14 @@ public class TestLTRScoringQuery extends SolrTestCase {Document doc = new Document();doc.add(newStringField("id", "0", Field.Store.YES));- doc.add(newTextField("field", "wizard the the the the the oz",- Field.Store.NO));+ doc.add(newTextField("field", "wizard the the the the the oz", Field.Store.NO));doc.add(new FloatDocValuesField("final-score", 1.0f));w.addDocument(doc);doc = new Document();doc.add(newStringField("id", "1", Field.Store.YES));// 1 extra token, but wizard and oz are close;- doc.add(newTextField("field", "wizard oz the the the the the the",- Field.Store.NO));+ doc.add(newTextField("field", "wizard oz the the the the the the", Field.Store.NO));doc.add(new FloatDocValuesField("final-score", 2.0f));w.addDocument(doc);@@ -207,17 +198,21 @@ public class TestLTRScoringQuery extends SolrTestCase {assertEquals("1", searcher.doc(hits.scoreDocs[1].doc).get("id"));List<Feature> features = makeFeatures(new int[] {0, 1, 2});- final List<Feature> allFeatures = makeFeatures(new int[] {0, 1, 2, 3, 4, 5,- 6, 7, 8, 9});+ final List<Feature> allFeatures = makeFeatures(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});List<Normalizer> norms =new ArrayList<Normalizer>(- Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));- LTRScoringModel ltrScoringModel = TestLinearModel.createLinearModel("test",- features, norms, "test", allFeatures,- TestLinearModel.makeFeatureWeights(features));-- LTRScoringQuery.ModelWeight modelWeight = performQuery(hits, searcher,- hits.scoreDocs[0].doc, new LTRScoringQuery(ltrScoringModel));+ Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));+ LTRScoringModel ltrScoringModel =+ TestLinearModel.createLinearModel(+ "test",+ features,+ norms,+ "test",+ allFeatures,+ TestLinearModel.makeFeatureWeights(features));++ LTRScoringQuery.ModelWeight modelWeight =+ performQuery(hits, searcher, hits.scoreDocs[0].doc, new LTRScoringQuery(ltrScoringModel));assertEquals(3, modelWeight.getModelFeatureValuesNormalized().length);for (int i = 0; i < 3; i++) {@@ -225,45 +220,56 @@ public class TestLTRScoringQuery extends SolrTestCase {}int[] posVals = new int[] {0, 1, 2};int pos = 0;- for (LTRScoringQuery.FeatureInfo fInfo:modelWeight.getFeaturesInfo()) {- if (fInfo == null){- continue;- }- assertEquals(posVals[pos], fInfo.getValue(), 0.0001);- assertEquals("f"+posVals[pos], fInfo.getName());- pos++;+ for (LTRScoringQuery.FeatureInfo fInfo : modelWeight.getFeaturesInfo()) {+ if (fInfo == null) {+ continue;+ }+ assertEquals(posVals[pos], fInfo.getValue(), 0.0001);+ assertEquals("f" + posVals[pos], fInfo.getName());+ pos++;}final int[] mixPositions = new int[] {8, 2, 4, 9, 0};features = makeFeatures(mixPositions);norms =new ArrayList<Normalizer>(- Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));- ltrScoringModel = TestLinearModel.createLinearModel("test",- features, norms, "test", allFeatures, TestLinearModel.makeFeatureWeights(features));-- modelWeight = performQuery(hits, searcher, hits.scoreDocs[0].doc,- new LTRScoringQuery(ltrScoringModel));- assertEquals(mixPositions.length,- modelWeight.getModelFeatureWeights().length);+ Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));+ ltrScoringModel =+ TestLinearModel.createLinearModel(+ "test",+ features,+ norms,+ "test",+ allFeatures,+ TestLinearModel.makeFeatureWeights(features));++ modelWeight =+ performQuery(hits, searcher, hits.scoreDocs[0].doc, new LTRScoringQuery(ltrScoringModel));+ assertEquals(mixPositions.length, modelWeight.getModelFeatureWeights().length);for (int i = 0; i < mixPositions.length; i++) {- assertEquals(mixPositions[i],- modelWeight.getModelFeatureValuesNormalized()[i], 0.0001);+ assertEquals(mixPositions[i], modelWeight.getModelFeatureValuesNormalized()[i], 0.0001);}- final ModelException expectedModelException = new ModelException("no features declared for model test");+ final ModelException expectedModelException =+ new ModelException("no features declared for model test");final int[] noPositions = new int[] {};features = makeFeatures(noPositions);norms =new ArrayList<Normalizer>(- Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));+ Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));try {- ltrScoringModel = TestLinearModel.createLinearModel("test",- features, norms, "test", allFeatures, TestLinearModel.makeFeatureWeights(features));- fail("unexpectedly got here instead of catching "+expectedModelException);- modelWeight = performQuery(hits, searcher, hits.scoreDocs[0].doc,- new LTRScoringQuery(ltrScoringModel));+ ltrScoringModel =+ TestLinearModel.createLinearModel(+ "test",+ features,+ norms,+ "test",+ allFeatures,+ TestLinearModel.makeFeatureWeights(features));+ fail("unexpectedly got here instead of catching " + expectedModelException);+ modelWeight =+ performQuery(hits, searcher, hits.scoreDocs[0].doc, new LTRScoringQuery(ltrScoringModel));assertEquals(0, modelWeight.getModelFeatureWeights().length);} catch (ModelException actualModelException) {assertEquals(expectedModelException.toString(), actualModelException.toString());@@ -271,41 +277,40 @@ public class TestLTRScoringQuery extends SolrTestCase {// test normalizersfeatures = makeFilterFeatures(mixPositions);- final Normalizer norm = new Normalizer() {-- @Override- public float normalize(float value) {- return 42.42f;- }-- @Override- public LinkedHashMap<String,Object> paramsToMap() {- return null;- }-- @Override- protected void validate() throws NormalizerException {- }-- };- norms =- new ArrayList<Normalizer>(- Collections.nCopies(features.size(),norm));- final LTRScoringModel normMeta = TestLinearModel.createLinearModel("test",- features, norms, "test", allFeatures,- TestLinearModel.makeFeatureWeights(features));-- modelWeight = performQuery(hits, searcher, hits.scoreDocs[0].doc,- new LTRScoringQuery(normMeta));+ final Normalizer norm =+ new Normalizer() {++ @Override+ public float normalize(float value) {+ return 42.42f;+ }++ @Override+ public LinkedHashMap<String, Object> paramsToMap() {+ return null;+ }++ @Override+ protected void validate() throws NormalizerException {}+ };+ norms = new ArrayList<Normalizer>(Collections.nCopies(features.size(), norm));+ final LTRScoringModel normMeta =+ TestLinearModel.createLinearModel(+ "test",+ features,+ norms,+ "test",+ allFeatures,+ TestLinearModel.makeFeatureWeights(features));++ modelWeight =+ performQuery(hits, searcher, hits.scoreDocs[0].doc, new LTRScoringQuery(normMeta));normMeta.normalizeFeaturesInPlace(modelWeight.getModelFeatureValuesNormalized());- assertEquals(mixPositions.length,- modelWeight.getModelFeatureWeights().length);+ assertEquals(mixPositions.length, modelWeight.getModelFeatureWeights().length);for (int i = 0; i < mixPositions.length; i++) {assertEquals(42.42f, modelWeight.getModelFeatureValuesNormalized()[i], 0.0001);}r.close();dir.close();-}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRWithFacet.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRWithFacet.javaindex 31c2b761a59..61b64600d47 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRWithFacet.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRWithFacet.java@@ -30,39 +30,35 @@ public class TestLTRWithFacet extends TestRerankBase {public void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "a1", "description", "E", "popularity",- "1"));- assertU(adoc("id", "2", "title", "a1 b1", "description",- "B", "popularity", "2"));- assertU(adoc("id", "3", "title", "a1 b1 c1", "description", "B", "popularity",- "3"));- assertU(adoc("id", "4", "title", "a1 b1 c1 d1", "description", "B", "popularity",- "4"));- assertU(adoc("id", "5", "title", "a1 b1 c1 d1 e1", "description", "E", "popularity",- "5"));- assertU(adoc("id", "6", "title", "a1 b1 c1 d1 e1 f1", "description", "B",- "popularity", "6"));- assertU(adoc("id", "7", "title", "a1 b1 c1 d1 e1 f1 g1", "description",- "C", "popularity", "7"));- assertU(adoc("id", "8", "title", "a1 b1 c1 d1 e1 f1 g1 h1", "description",- "D", "popularity", "8"));+ assertU(adoc("id", "1", "title", "a1", "description", "E", "popularity", "1"));+ assertU(adoc("id", "2", "title", "a1 b1", "description", "B", "popularity", "2"));+ assertU(adoc("id", "3", "title", "a1 b1 c1", "description", "B", "popularity", "3"));+ assertU(adoc("id", "4", "title", "a1 b1 c1 d1", "description", "B", "popularity", "4"));+ assertU(adoc("id", "5", "title", "a1 b1 c1 d1 e1", "description", "E", "popularity", "5"));+ assertU(adoc("id", "6", "title", "a1 b1 c1 d1 e1 f1", "description", "B", "popularity", "6"));+ assertU(+ adoc("id", "7", "title", "a1 b1 c1 d1 e1 f1 g1", "description", "C", "popularity", "7"));+ assertU(+ adoc("id", "8", "title", "a1 b1 c1 d1 e1 f1 g1 h1", "description", "D", "popularity", "8"));assertU(commit());}-+@Afterpublic void after() throws Exception {aftertest();}-@Testpublic void testRankingSolrFacet() throws Exception {// before();- loadFeature("powpularityS", SolrFeature.class.getName(),- "{\"q\":\"{!func}pow(popularity,2)\"}");+ loadFeature(+ "powpularityS", SolrFeature.class.getName(), "{\"q\":\"{!func}pow(popularity,2)\"}");- loadModel("powpularityS-model", LinearModel.class.getName(),- new String[] {"powpularityS"}, "{\"weights\":{\"powpularityS\":1.0}}");+ loadModel(+ "powpularityS-model",+ LinearModel.class.getName(),+ new String[] {"powpularityS"},+ "{\"weights\":{\"powpularityS\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:a1");@@ -77,9 +73,9 @@ public class TestLTRWithFacet extends TestRerankBase {assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='3'");assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='4'");// Normal term match- assertJQ("/query" + query.toQueryString(), ""- + "/facet_counts/facet_fields/description=="- + "['b', 4, 'e', 2, 'c', 1, 'd', 1]");+ assertJQ(+ "/query" + query.toQueryString(),+ "" + "/facet_counts/facet_fields/description==" + "['b', 4, 'e', 2, 'c', 1, 'd', 1]");query.add("rq", "{!ltr model=powpularityS-model reRankDocs=4}");query.set("debugQuery", "on");@@ -94,9 +90,8 @@ public class TestLTRWithFacet extends TestRerankBase {assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='1'");assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/score==1.0");- assertJQ("/query" + query.toQueryString(), ""- + "/facet_counts/facet_fields/description=="- + "['b', 4, 'e', 2, 'c', 1, 'd', 1]");+ assertJQ(+ "/query" + query.toQueryString(),+ "" + "/facet_counts/facet_fields/description==" + "['b', 4, 'e', 2, 'c', 1, 'd', 1]");}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRWithSort.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRWithSort.javaindex c0157130bcf..10df43922ec 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRWithSort.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestLTRWithSort.java@@ -18,7 +18,6 @@package org.apache.solr.ltr;import java.util.Random;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.feature.SolrFeature;import org.apache.solr.ltr.interleaving.algorithms.TeamDraftInterleaving;@@ -32,25 +31,19 @@ public class TestLTRWithSort extends TestRerankBase {@Beforepublic void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "a1", "description", "E", "popularity",- "1"));- assertU(adoc("id", "2", "title", "a1 b1", "description",- "B", "popularity", "2"));- assertU(adoc("id", "3", "title", "a1 b1 c1", "description", "B", "popularity",- "3"));- assertU(adoc("id", "4", "title", "a1 b1 c1 d1", "description", "B", "popularity",- "4"));- assertU(adoc("id", "5", "title", "a1 b1 c1 d1 e1", "description", "E", "popularity",- "5"));- assertU(adoc("id", "6", "title", "a1 b1 c1 d1 e1 f1", "description", "B",- "popularity", "6"));- assertU(adoc("id", "7", "title", "a1 b1 c1 d1 e1 f1 g1", "description",- "C", "popularity", "7"));- assertU(adoc("id", "8", "title", "a1 b1 c1 d1 e1 f1 g1 h1", "description",- "D", "popularity", "8"));+ assertU(adoc("id", "1", "title", "a1", "description", "E", "popularity", "1"));+ assertU(adoc("id", "2", "title", "a1 b1", "description", "B", "popularity", "2"));+ assertU(adoc("id", "3", "title", "a1 b1 c1", "description", "B", "popularity", "3"));+ assertU(adoc("id", "4", "title", "a1 b1 c1 d1", "description", "B", "popularity", "4"));+ assertU(adoc("id", "5", "title", "a1 b1 c1 d1 e1", "description", "E", "popularity", "5"));+ assertU(adoc("id", "6", "title", "a1 b1 c1 d1 e1 f1", "description", "B", "popularity", "6"));+ assertU(+ adoc("id", "7", "title", "a1 b1 c1 d1 e1 f1 g1", "description", "C", "popularity", "7"));+ assertU(+ adoc("id", "8", "title", "a1 b1 c1 d1 e1 f1 g1 h1", "description", "D", "popularity", "8"));assertU(commit());}-+@Afterpublic void after() throws Exception {aftertest();@@ -59,11 +52,14 @@ public class TestLTRWithSort extends TestRerankBase {@Testpublic void testRankingSolrSort() throws Exception {// before();- loadFeature("powpularityS", SolrFeature.class.getName(),- "{\"q\":\"{!func}pow(popularity,2)\"}");+ loadFeature(+ "powpularityS", SolrFeature.class.getName(), "{\"q\":\"{!func}pow(popularity,2)\"}");- loadModel("powpularityS-model", LinearModel.class.getName(),- new String[] {"powpularityS"}, "{\"weights\":{\"powpularityS\":1.0}}");+ loadModel(+ "powpularityS-model",+ LinearModel.class.getName(),+ new String[] {"powpularityS"},+ "{\"weights\":{\"powpularityS\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:a1");@@ -77,7 +73,7 @@ public class TestLTRWithSort extends TestRerankBase {assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='3'");assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='4'");- //Add sort+ // Add sortquery.add("sort", "description desc");assertJQ("/query" + query.toQueryString(), "/response/numFound/==8");assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='1'");@@ -97,24 +93,28 @@ public class TestLTRWithSort extends TestRerankBase {assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/score==25.0");assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='1'");assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/score==1.0");-}@Testpublic void interleavingTwoModelsWithSort_shouldInterleave() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10));//Random Boolean Choices Generation from Seed: [1,0]+ TeamDraftInterleaving.setRANDOM(+ new Random(10)); // Random Boolean Choices Generation from Seed: [1,0]- loadFeature("featureA", SolrFeature.class.getName(),- "{\"q\":\"{!func}pow(popularity,2)\"}");+ loadFeature("featureA", SolrFeature.class.getName(), "{\"q\":\"{!func}pow(popularity,2)\"}");- loadFeature("featureB", SolrFeature.class.getName(),- "{\"q\":\"{!func}pow(popularity,-2)\"}");+ loadFeature("featureB", SolrFeature.class.getName(), "{\"q\":\"{!func}pow(popularity,-2)\"}");- loadModel("modelA", LinearModel.class.getName(),- new String[] {"featureA"}, "{\"weights\":{\"featureA\":1.0}}");+ loadModel(+ "modelA",+ LinearModel.class.getName(),+ new String[] {"featureA"},+ "{\"weights\":{\"featureA\":1.0}}");- loadModel("modelB", LinearModel.class.getName(),- new String[] {"featureB"}, "{\"weights\":{\"featureB\":1.0}}");+ loadModel(+ "modelB",+ LinearModel.class.getName(),+ new String[] {"featureB"},+ "{\"weights\":{\"featureB\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:a1");@@ -128,16 +128,16 @@ public class TestLTRWithSort extends TestRerankBase {Doc5 = "popularity=5", ScoreA(25) ScoreB(0.04)Doc7 = "popularity=7", ScoreA(49) ScoreB(0.02)Doc8 = "popularity=8", ScoreA(64) ScoreB(0.01)-+ModelARerankedList = [8,7,5,1]ModelBRerankedList = [1,5,7,8]-+OriginalRanking = [1,5,8,7]Random Boolean Choices Generation from Seed: [1,0]*/- int[] expectedInterleaved = new int[]{1, 8, 7, 5};+ int[] expectedInterleaved = new int[] {1, 8, 7, 5};String[] tests = new String[5];tests[0] = "/response/numFound/==8";@@ -145,20 +145,23 @@ public class TestLTRWithSort extends TestRerankBase {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";}assertJQ("/query" + query.toQueryString(), tests);-}@Testpublic void interleavingModelsWithOriginalRankingSort_shouldInterleave() throws Exception {- loadFeature("powpularityS", SolrFeature.class.getName(),- "{\"q\":\"{!func}pow(popularity,2)\"}");+ loadFeature(+ "powpularityS", SolrFeature.class.getName(), "{\"q\":\"{!func}pow(popularity,2)\"}");- loadModel("powpularityS-model", LinearModel.class.getName(),- new String[] {"powpularityS"}, "{\"weights\":{\"powpularityS\":1.0}}");+ loadModel(+ "powpularityS-model",+ LinearModel.class.getName(),+ new String[] {"powpularityS"},+ "{\"weights\":{\"powpularityS\":1.0}}");- for (boolean originalRankingLast : new boolean[] { true, false }) {- TeamDraftInterleaving.setRANDOM(new Random(10));//Random Boolean Choices Generation from Seed: [1,0]+ for (boolean originalRankingLast : new boolean[] {true, false}) {+ TeamDraftInterleaving.setRANDOM(+ new Random(10)); // Random Boolean Choices Generation from Seed: [1,0]final SolrQuery query = new SolrQuery();query.setQuery("title:a1");@@ -172,22 +175,22 @@ public class TestLTRWithSort extends TestRerankBase {query.add("sort", "description desc");/*- Doc1 = "popularity=1", ScorePowpularityS(1)- Doc5 = "popularity=5", ScorePowpularityS(25)- Doc7 = "popularity=7", ScorePowpularityS(49)- Doc8 = "popularity=8", ScorePowpularityS(64)+ Doc1 = "popularity=1", ScorePowpularityS(1)+ Doc5 = "popularity=5", ScorePowpularityS(25)+ Doc7 = "popularity=7", ScorePowpularityS(49)+ Doc8 = "popularity=8", ScorePowpularityS(64)- PowpularitySRerankedList = [8,7,5,1]- OriginalRanking = [1,5,8,7]+ PowpularitySRerankedList = [8,7,5,1]+ OriginalRanking = [1,5,8,7]- Random Boolean Choices Generation from Seed: [1,0]- */+ Random Boolean Choices Generation from Seed: [1,0]+ */final int[] expectedInterleaved;if (originalRankingLast) {- expectedInterleaved = new int[]{1, 8, 7, 5};+ expectedInterleaved = new int[] {1, 8, 7, 5};} else {- expectedInterleaved = new int[]{8, 1, 5, 7};+ expectedInterleaved = new int[] {8, 1, 5, 7};}String[] tests = new String[5];@@ -197,7 +200,5 @@ public class TestLTRWithSort extends TestRerankBase {}assertJQ("/query" + query.toQueryString(), tests);}-}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestParallelWeightCreation.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestParallelWeightCreation.javaindex 46330c9f26d..9f2e54f91d7 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestParallelWeightCreation.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestParallelWeightCreation.java@@ -19,23 +19,24 @@ package org.apache.solr.ltr;import org.apache.solr.client.solrj.SolrQuery;import org.junit.Test;-public class TestParallelWeightCreation extends TestRerankBase{+public class TestParallelWeightCreation extends TestRerankBase {@Testpublic void testLTRScoringQueryParallelWeightCreationResultOrder() throws Exception {setuptest("solrconfig-ltr_Th10_10.xml", "schema.xml");assertU(adoc("id", "1", "title", "w1 w3", "description", "w1", "popularity", "1"));- assertU(adoc("id", "2", "title", "w2", "description", "w2", "popularity", "2"));- assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));+ assertU(adoc("id", "2", "title", "w2", "description", "w2", "popularity", "2"));+ assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));assertU(adoc("id", "4", "title", "w3 w3", "description", "w4", "popularity", "4"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));assertU(commit());loadFeatures("external_features.json");loadModels("external_model.json");- // check to make sure that the order of results will be the same when using parallel weight creation+ // check to make sure that the order of results will be the same when using parallel weight+ // creationfinal SolrQuery query = new SolrQuery();query.setQuery("*:*");query.add("fl", "*,score");@@ -53,18 +54,20 @@ public class TestParallelWeightCreation extends TestRerankBase{public void testLTRQParserThreadInitialization() throws Exception {// setting the value of number of threads to -ve should throw an exceptionString msg1 = null;- try{- new LTRThreadModule(1,-1);- }catch(IllegalArgumentException iae){- msg1 = iae.getMessage();;+ try {+ new LTRThreadModule(1, -1);+ } catch (IllegalArgumentException iae) {+ msg1 = iae.getMessage();+ ;}assertTrue(msg1.equals("numThreadsPerRequest cannot be less than 1"));- // set totalPoolThreads to 1 and numThreadsPerRequest to 2 and verify that an exception is thrown+ // set totalPoolThreads to 1 and numThreadsPerRequest to 2 and verify that an exception is+ // thrownString msg2 = null;- try{- new LTRThreadModule(1,2);- }catch(IllegalArgumentException iae){+ try {+ new LTRThreadModule(1, 2);+ } catch (IllegalArgumentException iae) {msg2 = iae.getMessage();}assertTrue(msg2.equals("numThreadsPerRequest cannot be greater than totalPoolThreads"));diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestRerankBase.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestRerankBase.javaindex 4fb042b75a1..4f96ef658e5 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestRerankBase.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestRerankBase.java@@ -28,7 +28,6 @@ import java.util.HashMap;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;-import org.apache.commons.io.FileUtils;import org.apache.solr.common.util.Utils;import org.apache.solr.core.SolrCore;@@ -49,7 +48,8 @@ public class TestRerankBase extends RestTestBase {private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());- protected static final SolrResourceLoader solrResourceLoader = new SolrResourceLoader(Paths.get("").toAbsolutePath());+ protected static final SolrResourceLoader solrResourceLoader =+ new SolrResourceLoader(Paths.get("").toAbsolutePath());protected static File tmpSolrHome;protected static File tmpConfDir;@@ -64,19 +64,21 @@ public class TestRerankBase extends RestTestBase {protected static File fstorefile = null;protected static File mstorefile = null;- final private static String SYSTEM_PROPERTY_SOLR_LTR_TRANSFORMER_FV_DEFAULTFORMAT = "solr.ltr.transformer.fv.defaultFormat";+ private static final String SYSTEM_PROPERTY_SOLR_LTR_TRANSFORMER_FV_DEFAULTFORMAT =+ "solr.ltr.transformer.fv.defaultFormat";private static String defaultFeatureFormat;protected String chooseDefaultFeatureVector(String dense, String sparse) {if (defaultFeatureFormat == null) {- // to match <code><str name="defaultFormat">${solr.ltr.transformer.fv.defaultFormat:dense}</str></code> snippet+ // to match <code><str+ // name="defaultFormat">${solr.ltr.transformer.fv.defaultFormat:dense}</str></code> snippetreturn dense;- } else if ("dense".equals(defaultFeatureFormat)) {+ } else if ("dense".equals(defaultFeatureFormat)) {return dense;- } else if ("sparse".equals(defaultFeatureFormat)) {+ } else if ("sparse".equals(defaultFeatureFormat)) {return sparse;} else {- fail("unexpected feature format choice: "+defaultFeatureFormat);+ fail("unexpected feature format choice: " + defaultFeatureFormat);return null;}}@@ -97,7 +99,8 @@ public class TestRerankBase extends RestTestBase {break;}if (defaultFeatureFormat != null) {- System.setProperty(SYSTEM_PROPERTY_SOLR_LTR_TRANSFORMER_FV_DEFAULTFORMAT, defaultFeatureFormat);+ System.setProperty(+ SYSTEM_PROPERTY_SOLR_LTR_TRANSFORMER_FV_DEFAULTFORMAT, defaultFeatureFormat);}}@@ -129,14 +132,12 @@ public class TestRerankBase extends RestTestBase {}}- protected static void setupTestInit(- String solrconfig, String schema,- boolean isPersistent) throws Exception {+ protected static void setupTestInit(String solrconfig, String schema, boolean isPersistent)+ throws Exception {tmpSolrHome = createTempDir().toFile();tmpConfDir = new File(tmpSolrHome, CONF_DIR);tmpConfDir.deleteOnExit();- FileUtils.copyDirectory(new File(TEST_HOME()),- tmpSolrHome.getAbsoluteFile());+ FileUtils.copyDirectory(new File(TEST_HOME()), tmpSolrHome.getAbsoluteFile());final File fstore = new File(tmpConfDir, FEATURE_FILE_NAME);final File mstore = new File(tmpConfDir, MODEL_FILE_NAME);@@ -159,38 +160,32 @@ public class TestRerankBase extends RestTestBase {Files.delete(mstore.toPath());}if (!solrconfig.equals("solrconfig.xml")) {- FileUtils.copyFile(new File(tmpSolrHome.getAbsolutePath()- + "/collection1/conf/" + solrconfig),- new File(tmpSolrHome.getAbsolutePath()- + "/collection1/conf/solrconfig.xml"));+ FileUtils.copyFile(+ new File(tmpSolrHome.getAbsolutePath() + "/collection1/conf/" + solrconfig),+ new File(tmpSolrHome.getAbsolutePath() + "/collection1/conf/solrconfig.xml"));}if (!schema.equals("schema.xml")) {- FileUtils.copyFile(new File(tmpSolrHome.getAbsolutePath()- + "/collection1/conf/" + schema),- new File(tmpSolrHome.getAbsolutePath()- + "/collection1/conf/schema.xml"));+ FileUtils.copyFile(+ new File(tmpSolrHome.getAbsolutePath() + "/collection1/conf/" + schema),+ new File(tmpSolrHome.getAbsolutePath() + "/collection1/conf/schema.xml"));}System.setProperty("managed.schema.mutable", "true");}- public static void setuptest(String solrconfig, String schema)- throws Exception {+ public static void setuptest(String solrconfig, String schema) throws Exception {- setupTestInit(solrconfig,schema,false);+ setupTestInit(solrconfig, schema, false);System.setProperty("enable.update.log", "false");- createJettyAndHarness(tmpSolrHome.getAbsolutePath(), solrconfig, schema,- "/solr", true, null);+ createJettyAndHarness(tmpSolrHome.getAbsolutePath(), solrconfig, schema, "/solr", true, null);}- public static void setupPersistentTest(String solrconfig, String schema)- throws Exception {+ public static void setupPersistentTest(String solrconfig, String schema) throws Exception {- setupTestInit(solrconfig,schema,true);+ setupTestInit(solrconfig, schema, true);- createJettyAndHarness(tmpSolrHome.getAbsolutePath(), solrconfig, schema,- "/solr", true, null);+ createJettyAndHarness(tmpSolrHome.getAbsolutePath(), solrconfig, schema, "/solr", true, null);}protected static void aftertest() throws Exception {@@ -215,21 +210,19 @@ public class TestRerankBase extends RestTestBase {restTestHarness = null;}- /** produces a model encoded in json **/- public static String getModelInJson(String name, String type,- String[] features, String fstore, String params) {+ /** produces a model encoded in json * */+ public static String getModelInJson(+ String name, String type, String[] features, String fstore, String params) {final StringBuilder sb = new StringBuilder();sb.append("{\n");sb.append("\"name\":").append('"').append(name).append('"').append(",\n");- sb.append("\"store\":").append('"').append(fstore).append('"')- .append(",\n");+ sb.append("\"store\":").append('"').append(fstore).append('"').append(",\n");sb.append("\"class\":").append('"').append(type).append('"').append(",\n");sb.append("\"features\":").append('[');if (features.length > 0) {for (final String feature : features) {sb.append("\n\t{ ");- sb.append("\"name\":").append('"').append(feature).append('"')- .append("},");+ sb.append("\"name\":").append('"').append(feature).append('"').append("},");}sb.deleteCharAt(sb.length() - 1);}@@ -242,14 +235,12 @@ public class TestRerankBase extends RestTestBase {return sb.toString();}- /** produces a model encoded in json **/- public static String getFeatureInJson(String name, String type,- String fstore, String params) {+ /** produces a model encoded in json * */+ public static String getFeatureInJson(String name, String type, String fstore, String params) {final StringBuilder sb = new StringBuilder();sb.append("{\n");sb.append("\"name\":").append('"').append(name).append('"').append(",\n");- sb.append("\"store\":").append('"').append(fstore).append('"')- .append(",\n");+ sb.append("\"store\":").append('"').append(fstore).append('"').append(",\n");sb.append("\"class\":").append('"').append(type).append('"');if (params != null) {sb.append(",\n");@@ -260,8 +251,7 @@ public class TestRerankBase extends RestTestBase {}/** Load a feature from the test fstore and verify that it succeeded */- protected static void loadFeature(String name, String type, String params)- throws IOException {+ protected static void loadFeature(String name, String type, String params) throws IOException {loadFeature(name, type, "test", params, 0);}@@ -272,61 +262,56 @@ public class TestRerankBase extends RestTestBase {}/** Load a feature from a custom fstore and verify that it succeeded */- protected static void loadFeature(String name, String type, String fstore,- String params) throws Exception {+ protected static void loadFeature(String name, String type, String fstore, String params)+ throws Exception {loadFeature(name, type, fstore, params, 0);}- /** Load a feature from a custom fstore and expect a given status code (i.e. testing for failure) */- protected static void loadFeature(String name, String type, String fstore,- String params, int responseCode) throws IOException {+ /**+ * Load a feature from a custom fstore and expect a given status code (i.e. testing for failure)+ */+ protected static void loadFeature(+ String name, String type, String fstore, String params, int responseCode) throws IOException {final String feature = getFeatureInJson(name, type, fstore, params);log.info("loading feauture \n{} ", feature);- assertJPut(ManagedFeatureStore.REST_END_POINT, feature,- "/responseHeader/status==" + responseCode);+ assertJPut(+ ManagedFeatureStore.REST_END_POINT, feature, "/responseHeader/status==" + responseCode);}- protected static void loadModel(String name, String type, String[] features,- String params) throws Exception {+ protected static void loadModel(String name, String type, String[] features, String params)+ throws Exception {loadModel(name, type, features, "test", params);}- protected static void loadModel(String name, String type, String[] features,- String fstore, String params) throws Exception {+ protected static void loadModel(+ String name, String type, String[] features, String fstore, String params) throws Exception {final String model = getModelInJson(name, type, features, fstore, params);log.info("loading model \n{} ", model);- assertJPut(ManagedModelStore.REST_END_POINT, model,- "/responseHeader/status==0");+ assertJPut(ManagedModelStore.REST_END_POINT, model, "/responseHeader/status==0");}public static void loadModels(String fileName) throws Exception {- final URL url = TestRerankBase.class.getResource("/modelExamples/"- + fileName);- final String multipleModels = FileUtils.readFileToString(- new File(url.toURI()), "UTF-8");+ final URL url = TestRerankBase.class.getResource("/modelExamples/" + fileName);+ final String multipleModels = FileUtils.readFileToString(new File(url.toURI()), "UTF-8");- assertJPut(ManagedModelStore.REST_END_POINT, multipleModels,- "/responseHeader/status==0");+ assertJPut(ManagedModelStore.REST_END_POINT, multipleModels, "/responseHeader/status==0");}- public static LTRScoringModel createModelFromFiles(String modelFileName,- String featureFileName) throws ModelException, Exception {- return createModelFromFiles(modelFileName, featureFileName,- FeatureStore.DEFAULT_FEATURE_STORE_NAME);+ public static LTRScoringModel createModelFromFiles(String modelFileName, String featureFileName)+ throws ModelException, Exception {+ return createModelFromFiles(+ modelFileName, featureFileName, FeatureStore.DEFAULT_FEATURE_STORE_NAME);}- public static LTRScoringModel createModelFromFiles(String modelFileName,- String featureFileName, String featureStoreName) throws ModelException, Exception {- URL url = TestRerankBase.class.getResource("/modelExamples/"- + modelFileName);- final String modelJson = FileUtils.readFileToString(new File(url.toURI()),- "UTF-8");+ public static LTRScoringModel createModelFromFiles(+ String modelFileName, String featureFileName, String featureStoreName)+ throws ModelException, Exception {+ URL url = TestRerankBase.class.getResource("/modelExamples/" + modelFileName);+ final String modelJson = FileUtils.readFileToString(new File(url.toURI()), "UTF-8");final ManagedModelStore ms = getManagedModelStore();- url = TestRerankBase.class.getResource("/featureExamples/"- + featureFileName);- final String featureJson = FileUtils.readFileToString(- new File(url.toURI()), "UTF-8");+ url = TestRerankBase.class.getResource("/featureExamples/" + featureFileName);+ final String featureJson = FileUtils.readFileToString(new File(url.toURI()), "UTF-8");Object parsedFeatureJson = null;try {@@ -344,44 +329,41 @@ public class TestRerankBase extends RestTestBase {fs.applyUpdatesToManagedData(parsedFeatureJson);ms.setManagedFeatureStore(fs); // can we skip this and just use fs directly below?- final LTRScoringModel ltrScoringModel = ManagedModelStore.fromLTRScoringModelMap(- solrResourceLoader, mapFromJson(modelJson), ms.getManagedFeatureStore());+ final LTRScoringModel ltrScoringModel =+ ManagedModelStore.fromLTRScoringModelMap(+ solrResourceLoader, mapFromJson(modelJson), ms.getManagedFeatureStore());ms.addModel(ltrScoringModel);return ltrScoringModel;}@SuppressWarnings("unchecked")- static private Map<String,Object> mapFromJson(String json) throws ModelException {+ private static Map<String, Object> mapFromJson(String json) throws ModelException {Object parsedJson = null;try {parsedJson = Utils.fromJSONString(json);} catch (final Exception ioExc) {throw new ModelException("ObjectBuilder failed parsing json", ioExc);}- return (Map<String,Object>) parsedJson;+ return (Map<String, Object>) parsedJson;}public static void loadFeatures(String fileName) throws Exception {- final URL url = TestRerankBase.class.getResource("/featureExamples/"- + fileName);- final String multipleFeatures = FileUtils.readFileToString(- new File(url.toURI()), "UTF-8");+ final URL url = TestRerankBase.class.getResource("/featureExamples/" + fileName);+ final String multipleFeatures = FileUtils.readFileToString(new File(url.toURI()), "UTF-8");log.info("send \n{}", multipleFeatures);- assertJPut(ManagedFeatureStore.REST_END_POINT, multipleFeatures,- "/responseHeader/status==0");+ assertJPut(ManagedFeatureStore.REST_END_POINT, multipleFeatures, "/responseHeader/status==0");}- protected List<Feature> getFeatures(List<String> names)- throws FeatureException {+ protected List<Feature> getFeatures(List<String> names) throws FeatureException {final List<Feature> features = new ArrayList<>();int pos = 0;for (final String name : names) {- final Map<String,Object> params = new HashMap<String,Object>();+ final Map<String, Object> params = new HashMap<String, Object>();params.put("value", 10);- final Feature f = Feature.getInstance(solrResourceLoader,- ValueFeature.class.getCanonicalName(),- name, params);+ final Feature f =+ Feature.getInstance(+ solrResourceLoader, ValueFeature.class.getCanonicalName(), name, params);f.setIndex(pos);features.add(f);++pos;@@ -394,22 +376,54 @@ public class TestRerankBase extends RestTestBase {}protected static void bulkIndex() throws Exception {- assertU(adoc("title", "bloomberg different bla", "description",- "bloomberg", "id", "6", "popularity", "1"));- assertU(adoc("title", "bloomberg bloomberg ", "description", "bloomberg",- "id", "7", "popularity", "2"));- assertU(adoc("title", "bloomberg bloomberg bloomberg", "description",- "bloomberg", "id", "8", "popularity", "3"));- assertU(adoc("title", "bloomberg bloomberg bloomberg bloomberg",- "description", "bloomberg", "id", "9", "popularity", "5"));+ assertU(+ adoc(+ "title",+ "bloomberg different bla",+ "description",+ "bloomberg",+ "id",+ "6",+ "popularity",+ "1"));+ assertU(+ adoc(+ "title",+ "bloomberg bloomberg ",+ "description",+ "bloomberg",+ "id",+ "7",+ "popularity",+ "2"));+ assertU(+ adoc(+ "title",+ "bloomberg bloomberg bloomberg",+ "description",+ "bloomberg",+ "id",+ "8",+ "popularity",+ "3"));+ assertU(+ adoc(+ "title",+ "bloomberg bloomberg bloomberg bloomberg",+ "description",+ "bloomberg",+ "id",+ "9",+ "popularity",+ "5"));assertU(commit());}- protected static void doTestParamsToMap(String featureClassName,- LinkedHashMap<String,Object> featureParams) throws Exception {+ protected static void doTestParamsToMap(+ String featureClassName, LinkedHashMap<String, Object> featureParams) throws Exception {// start with default parameters- final LinkedHashMap<String,Object> paramsA = new LinkedHashMap<String,Object>();+ final LinkedHashMap<String, Object> paramsA = new LinkedHashMap<String, Object>();final Object defaultValue;switch (random().nextInt(6)) {case 0:@@ -443,21 +457,20 @@ public class TestRerankBase extends RestTestBase {paramsA.putAll(featureParams);// next choose a random feature name- final String featureName = "randomFeatureName"+random().nextInt(10);+ final String featureName = "randomFeatureName" + random().nextInt(10);// create a feature from the parameters- final Feature featureA = Feature.getInstance(solrResourceLoader,- featureClassName, featureName, paramsA);+ final Feature featureA =+ Feature.getInstance(solrResourceLoader, featureClassName, featureName, paramsA);// turn the feature back into parameters- final LinkedHashMap<String,Object> paramsB = featureA.paramsToMap();+ final LinkedHashMap<String, Object> paramsB = featureA.paramsToMap();// create feature B from feature A's parameters- final Feature featureB = Feature.getInstance(solrResourceLoader,- featureClassName, featureName, paramsB);+ final Feature featureB =+ Feature.getInstance(solrResourceLoader, featureClassName, featureName, paramsB);// check that feature A and feature B are identicalassertEquals(featureA, featureB);}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.javaindex d98addab173..65af5626ac0 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java@@ -21,7 +21,6 @@ import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;-import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.document.FloatDocValuesField;@@ -60,22 +59,20 @@ public class TestSelectiveWeightCreation extends TestRerankBase {private static List<Feature> makeFeatures(int[] featureIds) {final List<Feature> features = new ArrayList<>();for (final int i : featureIds) {- Map<String,Object> params = new HashMap<String,Object>();+ Map<String, Object> params = new HashMap<String, Object>();params.put("value", i);- final Feature f = Feature.getInstance(solrResourceLoader,- ValueFeature.class.getName(),- "f" + i, params);+ final Feature f =+ Feature.getInstance(solrResourceLoader, ValueFeature.class.getName(), "f" + i, params);f.setIndex(i);features.add(f);}return features;}- private LTRScoringQuery.ModelWeight performQuery(TopDocs hits,- IndexSearcher searcher, int docid, LTRScoringQuery model) throws IOException,- ModelException {- final List<LeafReaderContext> leafContexts = searcher.getTopReaderContext()- .leaves();+ private LTRScoringQuery.ModelWeight performQuery(+ TopDocs hits, IndexSearcher searcher, int docid, LTRScoringQuery model)+ throws IOException, ModelException {+ final List<LeafReaderContext> leafContexts = searcher.getTopReaderContext().leaves();final int n = ReaderUtil.subIndex(hits.scoreDocs[0].doc, leafContexts);final LeafReaderContext context = leafContexts.get(n);final int deBasedDoc = hits.scoreDocs[0].doc - context.docBase;@@ -89,19 +86,17 @@ public class TestSelectiveWeightCreation extends TestRerankBase {assertTrue(weight instanceof LTRScoringQuery.ModelWeight);final LTRScoringQuery.ModelWeight modelWeight = (LTRScoringQuery.ModelWeight) weight;return modelWeight;-}-@BeforeClasspublic static void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w3 w1", "description", "w1", "popularity", "1"));- assertU(adoc("id", "2", "title", "w2", "description", "w2", "popularity", "2"));- assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));+ assertU(adoc("id", "2", "title", "w2", "description", "w2", "popularity", "2"));+ assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));assertU(adoc("id", "4", "title", "w3 w3", "description", "w4", "popularity", "4"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));assertU(commit());loadFeatures("external_features.json");@@ -121,16 +116,14 @@ public class TestSelectiveWeightCreation extends TestRerankBase {Document doc = new Document();doc.add(newStringField("id", "10", Field.Store.YES));- doc.add(newTextField("field", "wizard the the the the the oz",- Field.Store.NO));+ doc.add(newTextField("field", "wizard the the the the the oz", Field.Store.NO));doc.add(new FloatDocValuesField("final-score", 1.0f));w.addDocument(doc);doc = new Document();doc.add(newStringField("id", "11", Field.Store.YES));// 1 extra token, but wizard and oz are close;- doc.add(newTextField("field", "wizard oz the the the the the the",- Field.Store.NO));+ doc.add(newTextField("field", "wizard oz the the the the the the", Field.Store.NO));doc.add(new FloatDocValuesField("final-score", 2.0f));w.addDocument(doc);@@ -149,66 +142,84 @@ public class TestSelectiveWeightCreation extends TestRerankBase {assertEquals("11", searcher.doc(hits.scoreDocs[1].doc).get("id"));List<Feature> features = makeFeatures(new int[] {0, 1, 2});- final List<Feature> allFeatures = makeFeatures(new int[] {0, 1, 2, 3, 4, 5,- 6, 7, 8, 9});+ final List<Feature> allFeatures = makeFeatures(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});final List<Normalizer> norms = new ArrayList<>();- for (int k=0; k < features.size(); ++k){- norms.add(IdentityNormalizer.INSTANCE);+ for (int k = 0; k < features.size(); ++k) {+ norms.add(IdentityNormalizer.INSTANCE);}- // when features are NOT requested in the response, only the modelFeature weights should be created- final LTRScoringModel ltrScoringModel1 = TestLinearModel.createLinearModel("test",- features, norms, "test", allFeatures,- TestLinearModel.makeFeatureWeights(features));- LTRScoringQuery.ModelWeight modelWeight = performQuery(hits, searcher,- hits.scoreDocs[0].doc, new LTRScoringQuery(ltrScoringModel1, false)); // features not requested in response+ // when features are NOT requested in the response, only the modelFeature weights should be+ // created+ final LTRScoringModel ltrScoringModel1 =+ TestLinearModel.createLinearModel(+ "test",+ features,+ norms,+ "test",+ allFeatures,+ TestLinearModel.makeFeatureWeights(features));+ LTRScoringQuery.ModelWeight modelWeight =+ performQuery(+ hits,+ searcher,+ hits.scoreDocs[0].doc,+ new LTRScoringQuery(ltrScoringModel1, false)); // features not requested in responseLTRScoringQuery.FeatureInfo[] featuresInfo = modelWeight.getFeaturesInfo();assertEquals(features.size(), modelWeight.getModelFeatureValuesNormalized().length);int validFeatures = 0;- for (int i=0; i < featuresInfo.length; ++i){- if (featuresInfo[i] != null && featuresInfo[i].isUsed()){+ for (int i = 0; i < featuresInfo.length; ++i) {+ if (featuresInfo[i] != null && featuresInfo[i].isUsed()) {validFeatures += 1;}}assertEquals(validFeatures, features.size());// when features are requested in the response, weights should be created for all features- final LTRScoringModel ltrScoringModel2 = TestLinearModel.createLinearModel("test",- features, norms, "test", allFeatures,- TestLinearModel.makeFeatureWeights(features));- modelWeight = performQuery(hits, searcher,- hits.scoreDocs[0].doc, new LTRScoringQuery(ltrScoringModel2, true)); // features requested in response+ final LTRScoringModel ltrScoringModel2 =+ TestLinearModel.createLinearModel(+ "test",+ features,+ norms,+ "test",+ allFeatures,+ TestLinearModel.makeFeatureWeights(features));+ modelWeight =+ performQuery(+ hits,+ searcher,+ hits.scoreDocs[0].doc,+ new LTRScoringQuery(ltrScoringModel2, true)); // features requested in responsefeaturesInfo = modelWeight.getFeaturesInfo();assertEquals(features.size(), modelWeight.getModelFeatureValuesNormalized().length);assertEquals(allFeatures.size(), modelWeight.getExtractedFeatureWeights().length);validFeatures = 0;- for (int i=0; i < featuresInfo.length; ++i){- if (featuresInfo[i] != null && featuresInfo[i].isUsed()){+ for (int i = 0; i < featuresInfo.length; ++i) {+ if (featuresInfo[i] != null && featuresInfo[i].isUsed()) {validFeatures += 1;}}assertEquals(validFeatures, allFeatures.size());- assertU(delI("10"));assertU(delI("11"));+ assertU(delI("10"));+ assertU(delI("11"));r.close();dir.close();}-@Testpublic void testSelectiveWeightsRequestFeaturesFromDifferentStore() throws Exception {-// final String docs0fv_sparse = FeatureLoggerTestUtils.toFeatureVector(-// "matchedTitle","1.0", "titlePhraseMatch","0.6103343");-// final String docs0fv_dense = FeatureLoggerTestUtils.toFeatureVector(-// "matchedTitle","1.0", "titlePhraseMatch","0.6103343", "titlePhrasesMatch","0.0");-// final String docs0fv_fstore4= FeatureLoggerTestUtils.toFeatureVector(-// "popularity","3.0", "originalScore","1.0");-//-// final String docs0fv = chooseDefaultFeatureVector(docs0fv_dense, docs0fv_sparse);+ // final String docs0fv_sparse = FeatureLoggerTestUtils.toFeatureVector(+ // "matchedTitle","1.0", "titlePhraseMatch","0.6103343");+ // final String docs0fv_dense = FeatureLoggerTestUtils.toFeatureVector(+ // "matchedTitle","1.0", "titlePhraseMatch","0.6103343", "titlePhrasesMatch","0.0");+ // final String docs0fv_fstore4= FeatureLoggerTestUtils.toFeatureVector(+ // "popularity","3.0", "originalScore","1.0");+ //+ // final String docs0fv = chooseDefaultFeatureVector(docs0fv_dense, docs0fv_sparse);// extract all features in externalmodel's store (default store)// rerank using externalmodel (default store)@@ -216,7 +227,9 @@ public class TestSelectiveWeightCreation extends TestRerankBase {query.setQuery("*:*");query.add("fl", "*,score,fv:[fv]");query.add("rows", "5");- query.add("rq", "{!ltr reRankDocs=10 model=externalmodel efi.user_query=w3 efi.userTitlePhrase1=w2 efi.userTitlePhrase2=w1}");+ query.add(+ "rq",+ "{!ltr reRankDocs=10 model=externalmodel efi.user_query=w3 efi.userTitlePhrase1=w2 efi.userTitlePhrase2=w1}");// SOLR-10710, feature based on query with term w3 now scores higher on doc 4, updatedassertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='4'");@@ -245,12 +258,11 @@ public class TestSelectiveWeightCreation extends TestRerankBase {query.remove("rq");query.add("fl", "*,score,fv:[fv store=fstore4 efi.myPop=3]");query.add("rq", "{!ltr reRankDocs=10 model=externalmodel2 efi.user_query=w3}");-- assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='5'");- assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='4'");++ assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='5'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='4'");assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='3'");// FIXME design better way to test this, we can't rely on absolute scores// assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fv=='"+docs0fv_fstore4+"'");}}-diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestEdisMaxSolrFeature.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestEdisMaxSolrFeature.javaindex bbc881552c1..f01f329c9ae 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestEdisMaxSolrFeature.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestEdisMaxSolrFeature.java@@ -29,22 +29,41 @@ public class TestEdisMaxSolrFeature extends TestRerankBase {public void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",- "1"));- assertU(adoc("id", "2", "title", "w2 2asd asdd didid", "description",- "w2 2asd asdd didid", "popularity", "2"));- assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity",- "3"));- assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity",- "4"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity",- "5"));- assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2",- "popularity", "6"));- assertU(adoc("id", "7", "title", "w1 w2 w3 w4 w5", "description",- "w1 w2 w3 w4 w5 w8", "popularity", "7"));- assertU(adoc("id", "8", "title", "w1 w1 w1 w2 w2 w8", "description",- "w1 w1 w1 w2 w2", "popularity", "8"));+ assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity", "1"));+ assertU(+ adoc(+ "id",+ "2",+ "title",+ "w2 2asd asdd didid",+ "description",+ "w2 2asd asdd didid",+ "popularity",+ "2"));+ assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));+ assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity", "4"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));+ assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2", "popularity", "6"));+ assertU(+ adoc(+ "id",+ "7",+ "title",+ "w1 w2 w3 w4 w5",+ "description",+ "w1 w2 w3 w4 w5 w8",+ "popularity",+ "7"));+ assertU(+ adoc(+ "id",+ "8",+ "title",+ "w1 w1 w1 w2 w2 w8",+ "description",+ "w1 w1 w1 w2 w2",+ "popularity",+ "8"));assertU(commit());}@@ -60,8 +79,11 @@ public class TestEdisMaxSolrFeature extends TestRerankBase {SolrFeature.class.getName(),"{\"q\":\"{!edismax qf='title description' pf='description' mm=100% boost='pow(popularity, 0.1)' v='w1' tie=0.1}\"}");- loadModel("EdisMax-model", LinearModel.class.getName(),- new String[] {"SomeEdisMax"}, "{\"weights\":{\"SomeEdisMax\":1.0}}");+ loadModel(+ "EdisMax-model",+ LinearModel.class.getName(),+ new String[] {"SomeEdisMax"},+ "{\"weights\":{\"SomeEdisMax\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:w1");diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestExternalFeatures.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestExternalFeatures.javaindex 0c97f0f7330..df7c5e48b78 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestExternalFeatures.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestExternalFeatures.java@@ -29,16 +29,11 @@ public class TestExternalFeatures extends TestRerankBase {public static void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",- "1"));- assertU(adoc("id", "2", "title", "w2", "description", "w2", "popularity",- "2"));- assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity",- "3"));- assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity",- "4"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity",- "5"));+ assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity", "1"));+ assertU(adoc("id", "2", "title", "w2", "description", "w2", "popularity", "2"));+ assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));+ assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity", "4"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));assertU(commit());loadFeatures("external_features.json");@@ -67,7 +62,9 @@ public class TestExternalFeatures extends TestRerankBase {query.remove("fl");query.add("fl", "*,score,[fv]");- query.add("rq", "{!ltr reRankDocs=10 model=externalmodel efi.user_query=w3 efi.userTitlePhrase1=w4 efi.userTitlePhrase2=w5}");+ query.add(+ "rq",+ "{!ltr reRankDocs=10 model=externalmodel efi.user_query=w3 efi.userTitlePhrase1=w4 efi.userTitlePhrase2=w5}");assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='3'");assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==0.34972426");@@ -77,7 +74,8 @@ public class TestExternalFeatures extends TestRerankBase {// Adding an efi in the transformer should not affect the rq ranking with a// different value for efi of the same parameterquery.remove("fl");- query.add("fl", "*,score,[fv efi.user_query=w2 efi.userTitlePhrase1=w4 efi.userTitlePhrase2=w5]");+ query.add(+ "fl", "*,score,[fv efi.user_query=w2 efi.userTitlePhrase1=w4 efi.userTitlePhrase2=w5]");assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='3'");assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==0.34972426");@@ -92,18 +90,23 @@ public class TestExternalFeatures extends TestRerankBase {query.add("fl", "*,score,fv:[fv]");query.add("rows", "1");// Stopword only query passed in- query.add("rq", "{!ltr reRankDocs=10 model=externalmodel efi.user_query='a' efi.userTitlePhrase1='b' efi.userTitlePhrase2='c'}");-- final String docs0fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "matchedTitle","0.0",- "titlePhraseMatch","0.0",- "titlePhrasesMatch","0.0");+ query.add(+ "rq",+ "{!ltr reRankDocs=10 model=externalmodel efi.user_query='a' efi.userTitlePhrase1='b' efi.userTitlePhrase2='c'}");++ final String docs0fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "matchedTitle", "0.0",+ "titlePhraseMatch", "0.0",+ "titlePhrasesMatch", "0.0");final String docs0fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector();- final String docs0fv_default_csv = chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);+ final String docs0fv_default_csv =+ chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);// Features are query title matches, which remove stopwords, leaving blank query, so no matches- assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fv=='"+docs0fv_default_csv+"'");+ assertJQ(+ "/query" + query.toQueryString(), "/response/docs/[0]/fv=='" + docs0fv_default_csv + "'");}@Test@@ -112,63 +115,75 @@ public class TestExternalFeatures extends TestRerankBase {query.setQuery("*:*");query.add("rows", "1");- final String docs0fv_csv = FeatureLoggerTestUtils.toFeatureVector(- "occurrences","2.3", "originalScore","1.0");+ final String docs0fv_csv =+ FeatureLoggerTestUtils.toFeatureVector("occurrences", "2.3", "originalScore", "1.0");// Features we're extracting depend on external feature info not passed inquery.add("fl", "[fv]");- assertJQ("/query" + query.toQueryString(), "/error/msg=='Exception from createWeight for SolrFeature [name=matchedTitle, params={q={!terms f=title}${user_query}}] SolrFeatureWeight requires efi parameter that was not passed in request.'");+ assertJQ(+ "/query" + query.toQueryString(),+ "/error/msg=='Exception from createWeight for SolrFeature [name=matchedTitle, params={q={!terms f=title}${user_query}}] SolrFeatureWeight requires efi parameter that was not passed in request.'");// Adding efi in features section should make it workquery.remove("fl");query.add("fl", "score,fvalias:[fv store=fstore3 efi.myOcc=2.3]");- assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fvalias=='"+docs0fv_csv+"'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fvalias=='" + docs0fv_csv + "'");// Adding efi in transformer + rq should still returns featuresquery.remove("fl");query.add("fl", "score,fvalias:[fv store=fstore3 efi.myOcc=2.3]");query.add("rq", "{!ltr reRankDocs=10 model=externalmodel efi.user_query=w3}");- assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fvalias=='"+docs0fv_csv+"'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fvalias=='" + docs0fv_csv + "'");}@Test- public void featureExtraction_valueFeatureImplicitlyNotRequired_shouldNotScoreFeature() throws Exception {+ public void featureExtraction_valueFeatureImplicitlyNotRequired_shouldNotScoreFeature()+ throws Exception {final SolrQuery query = new SolrQuery();query.setQuery("*:*");query.add("rows", "1");- final String docs0fvalias_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "occurrences","0.0",- "originalScore","1.0");- final String docs0fvalias_sparse_csv = FeatureLoggerTestUtils.toFeatureVector(- "originalScore","1.0");+ final String docs0fvalias_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "occurrences", "0.0",+ "originalScore", "1.0");+ final String docs0fvalias_sparse_csv =+ FeatureLoggerTestUtils.toFeatureVector("originalScore", "1.0");- final String docs0fvalias_default_csv = chooseDefaultFeatureVector(docs0fvalias_dense_csv, docs0fvalias_sparse_csv);+ final String docs0fvalias_default_csv =+ chooseDefaultFeatureVector(docs0fvalias_dense_csv, docs0fvalias_sparse_csv);// Efi is explicitly not required, so we do not score the featurequery.remove("fl");query.add("fl", "fvalias:[fv store=fstore3]");- assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fvalias=='"+docs0fvalias_default_csv+"'");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/fvalias=='" + docs0fvalias_default_csv + "'");}@Test- public void featureExtraction_valueFeatureExplicitlyNotRequired_shouldNotScoreFeature() throws Exception {+ public void featureExtraction_valueFeatureExplicitlyNotRequired_shouldNotScoreFeature()+ throws Exception {final SolrQuery query = new SolrQuery();query.setQuery("*:*");query.add("rows", "1");- final String docs0fvalias_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "occurrences","0.0",- "originalScore","1.0");- final String docs0fvalias_sparse_csv = FeatureLoggerTestUtils.toFeatureVector(- "originalScore","1.0");+ final String docs0fvalias_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "occurrences", "0.0",+ "originalScore", "1.0");+ final String docs0fvalias_sparse_csv =+ FeatureLoggerTestUtils.toFeatureVector("originalScore", "1.0");- final String docs0fvalias_default_csv = chooseDefaultFeatureVector(docs0fvalias_dense_csv, docs0fvalias_sparse_csv);+ final String docs0fvalias_default_csv =+ chooseDefaultFeatureVector(docs0fvalias_dense_csv, docs0fvalias_sparse_csv);// Efi is explicitly not required, so we do not score the featurequery.remove("fl");query.add("fl", "fvalias:[fv store=fstore3]");- assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fvalias=='"+docs0fvalias_default_csv+"'");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/fvalias=='" + docs0fvalias_default_csv + "'");}@Test@@ -180,22 +195,30 @@ public class TestExternalFeatures extends TestRerankBase {// Using nondefault store should still result in error with no efi when it is required (myPop)query.remove("fl");query.add("fl", "fvalias:[fv store=fstore4]");- assertJQ("/query" + query.toQueryString(), "/error/msg=='Exception from createWeight for ValueFeature [name=popularity, params={value=${myPop}, required=true}] ValueFeatureWeight requires efi parameter that was not passed in request.'");+ assertJQ(+ "/query" + query.toQueryString(),+ "/error/msg=='Exception from createWeight for ValueFeature [name=popularity, params={value=${myPop}, required=true}] ValueFeatureWeight requires efi parameter that was not passed in request.'");}@Testpublic void featureExtraction_valueFeatureRequiredInFq_shouldThrowException() throws Exception {final String userTitlePhrase1 = "userTitlePhrase1";final String userTitlePhrase2 = "userTitlePhrase2";- final String userTitlePhrasePresent = (random().nextBoolean() ? userTitlePhrase1 : userTitlePhrase2);+ final String userTitlePhrasePresent =+ (random().nextBoolean() ? userTitlePhrase1 : userTitlePhrase2);final SolrQuery query = new SolrQuery();query.setQuery("*:*");query.add("rows", "1");- query.add("fl", "score,features:[fv efi.user_query=uq "+userTitlePhrasePresent+"=utpp]");- assertJQ("/query" + query.toQueryString(), "/error/msg=='Exception from createWeight for "- + "SolrFeature [name=titlePhrasesMatch, params={fq=[{!field f=title}${"+userTitlePhrase1+"}, {!field f=title}${"+userTitlePhrase2+"}]}] "- + "SolrFeatureWeight requires efi parameter that was not passed in request.'");+ query.add("fl", "score,features:[fv efi.user_query=uq " + userTitlePhrasePresent + "=utpp]");+ assertJQ(+ "/query" + query.toQueryString(),+ "/error/msg=='Exception from createWeight for "+ + "SolrFeature [name=titlePhrasesMatch, params={fq=[{!field f=title}${"+ + userTitlePhrase1+ + "}, {!field f=title}${"+ + userTitlePhrase2+ + "}]}] "+ + "SolrFeatureWeight requires efi parameter that was not passed in request.'");}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestExternalValueFeatures.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestExternalValueFeatures.javaindex 2de23a544e2..ead1a6c6a89 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestExternalValueFeatures.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestExternalValueFeatures.java@@ -29,16 +29,11 @@ public class TestExternalValueFeatures extends TestRerankBase {public static void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",- "1"));- assertU(adoc("id", "2", "title", "w2", "description", "w2", "popularity",- "2"));- assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity",- "3"));- assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity",- "4"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity",- "5"));+ assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity", "1"));+ assertU(adoc("id", "2", "title", "w2", "description", "w2", "popularity", "2"));+ assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));+ assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity", "4"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));assertU(commit());loadFeatures("external_features_for_sparse_processing.json");@@ -51,26 +46,30 @@ public class TestExternalValueFeatures extends TestRerankBase {}@Test- public void efiFeatureProcessing_oneEfiMissing_shouldNotCalculateMissingFeature() throws Exception {+ public void efiFeatureProcessing_oneEfiMissing_shouldNotCalculateMissingFeature()+ throws Exception {SolrQuery query = new SolrQuery();query.setQuery("*:*");query.add("fl", "*,score,features:[fv]");query.add("rows", "3");- query.add("rq", "{!ltr reRankDocs=3 model=external_model_binary_feature efi.user_device_tablet=1}");+ query.add(+ "rq", "{!ltr reRankDocs=3 model=external_model_binary_feature efi.user_device_tablet=1}");- final String docs0features_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "user_device_smartphone","0.0",- "user_device_tablet","1.0");- final String docs0features_sparse_csv = FeatureLoggerTestUtils.toFeatureVector(- "user_device_tablet","1.0");+ final String docs0features_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "user_device_smartphone", "0.0",+ "user_device_tablet", "1.0");+ final String docs0features_sparse_csv =+ FeatureLoggerTestUtils.toFeatureVector("user_device_tablet", "1.0");- final String docs0features_default_csv = chooseDefaultFeatureVector(docs0features_dense_csv, docs0features_sparse_csv);+ final String docs0features_default_csv =+ chooseDefaultFeatureVector(docs0features_dense_csv, docs0features_sparse_csv);assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='1'");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/features=='"+docs0features_default_csv+"'");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/score==65.0");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/features=='" + docs0features_default_csv + "'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==65.0");}@Test@@ -81,21 +80,21 @@ public class TestExternalValueFeatures extends TestRerankBase {query.add("rows", "3");query.add("fl", "[fv]");- query- .add("rq", "{!ltr reRankDocs=3 model=external_model_binary_feature}");+ query.add("rq", "{!ltr reRankDocs=3 model=external_model_binary_feature}");- final String docs0features_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "user_device_smartphone","0.0",- "user_device_tablet","0.0");+ final String docs0features_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "user_device_smartphone", "0.0",+ "user_device_tablet", "0.0");final String docs0features_sparse_csv = FeatureLoggerTestUtils.toFeatureVector();- final String docs0features_default_csv = chooseDefaultFeatureVector(docs0features_dense_csv, docs0features_sparse_csv);+ final String docs0features_default_csv =+ chooseDefaultFeatureVector(docs0features_dense_csv, docs0features_sparse_csv);assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='1'");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/features=='"+docs0features_default_csv+"'");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/score==0.0");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/features=='" + docs0features_default_csv + "'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==0.0");}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFeature.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFeature.javaindex e14012b2fe3..8ec7a5547b0 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFeature.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFeature.java@@ -17,7 +17,6 @@package org.apache.solr.ltr.feature;import java.lang.reflect.Method;-import org.apache.lucene.search.Scorer;import org.apache.solr.SolrTestCase;import org.junit.Test;@@ -35,14 +34,15 @@ public class TestFeature extends SolrTestCase {// the FilterFeatureScorer may simply inherit Scorer's default implementationif (scorerClassMethod.getName().equals("smoothingScore")) continue;-+// the FilterFeatureScorer's implementation does not influence its parent Weightif (scorerClassMethod.getName().equals("getWeight")) continue;- final Method ffsClassMethod = ffsClass.getDeclaredMethod(- scorerClassMethod.getName(),- scorerClassMethod.getParameterTypes());- assertEquals("getReturnType() difference",+ final Method ffsClassMethod =+ ffsClass.getDeclaredMethod(+ scorerClassMethod.getName(), scorerClassMethod.getParameterTypes());+ assertEquals(+ "getReturnType() difference",scorerClassMethod.getReturnType(),ffsClassMethod.getReturnType());} catch (NoSuchMethodException e) {@@ -50,5 +50,4 @@ public class TestFeature extends SolrTestCase {}}}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureExtractionFromMultipleSegments.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureExtractionFromMultipleSegments.javaindex 8b75dd62882..c7c2288d18a 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureExtractionFromMultipleSegments.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureExtractionFromMultipleSegments.java@@ -18,7 +18,6 @@ package org.apache.solr.ltr.feature;import java.util.List;import java.util.Map;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.common.util.Utils;import org.apache.solr.ltr.TestRerankBase;@@ -26,46 +25,198 @@ import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;-public class TestFeatureExtractionFromMultipleSegments extends TestRerankBase {static final String AB = "abcdefghijklmnopqrstuvwxyz";- static String randomString( int len ){- StringBuilder sb = new StringBuilder( len );- for( int i = 0; i < len; i++ ) {- sb.append( AB.charAt( random().nextInt(AB.length()) ) );+ static String randomString(int len) {+ StringBuilder sb = new StringBuilder(len);+ for (int i = 0; i < len; i++) {+ sb.append(AB.charAt(random().nextInt(AB.length())));}return sb.toString();- }+ }@BeforeClasspublic static void before() throws Exception {// solrconfig-multiseg.xml contains the merge policy to restrict mergingsetuptest("solrconfig-multiseg.xml", "schema.xml");// index 400 documents- for(int i = 0; i<400;i=i+20) {- assertU(adoc("id", Integer.toString(i), "popularity", "201", "description", "apple is a company " + randomString(i%6+3), "normHits", "0.1"));- assertU(adoc("id", Integer.toString(i+1), "popularity", "201", "description", "d " + randomString(i%6+3), "normHits", "0.11"));+ for (int i = 0; i < 400; i = i + 20) {+ assertU(+ adoc(+ "id",+ Integer.toString(i),+ "popularity",+ "201",+ "description",+ "apple is a company " + randomString(i % 6 + 3),+ "normHits",+ "0.1"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 1),+ "popularity",+ "201",+ "description",+ "d " + randomString(i % 6 + 3),+ "normHits",+ "0.11"));- assertU(adoc("id", Integer.toString(i+2), "popularity", "201", "description", "apple is a company too " + randomString(i%6+3), "normHits", "0.1"));- assertU(adoc("id", Integer.toString(i+3), "popularity", "201", "description", "new york city is big apple " + randomString(i%6+3), "normHits", "0.11"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 2),+ "popularity",+ "201",+ "description",+ "apple is a company too " + randomString(i % 6 + 3),+ "normHits",+ "0.1"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 3),+ "popularity",+ "201",+ "description",+ "new york city is big apple " + randomString(i % 6 + 3),+ "normHits",+ "0.11"));- assertU(adoc("id", Integer.toString(i+6), "popularity", "301", "description", "function name " + randomString(i%6+3), "normHits", "0.1"));- assertU(adoc("id", Integer.toString(i+7), "popularity", "301", "description", "function " + randomString(i%6+3), "normHits", "0.1"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 6),+ "popularity",+ "301",+ "description",+ "function name " + randomString(i % 6 + 3),+ "normHits",+ "0.1"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 7),+ "popularity",+ "301",+ "description",+ "function " + randomString(i % 6 + 3),+ "normHits",+ "0.1"));- assertU(adoc("id", Integer.toString(i+8), "popularity", "301", "description", "This is a sample function for testing " + randomString(i%6+3), "normHits", "0.1"));- assertU(adoc("id", Integer.toString(i+9), "popularity", "301", "description", "Function to check out stock prices "+randomString(i%6+3), "normHits", "0.1"));- assertU(adoc("id", Integer.toString(i+10),"popularity", "301", "description", "Some descriptions "+randomString(i%6+3), "normHits", "0.1"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 8),+ "popularity",+ "301",+ "description",+ "This is a sample function for testing " + randomString(i % 6 + 3),+ "normHits",+ "0.1"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 9),+ "popularity",+ "301",+ "description",+ "Function to check out stock prices " + randomString(i % 6 + 3),+ "normHits",+ "0.1"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 10),+ "popularity",+ "301",+ "description",+ "Some descriptions " + randomString(i % 6 + 3),+ "normHits",+ "0.1"));- assertU(adoc("id", Integer.toString(i+11), "popularity", "201", "description", "apple apple is a company " + randomString(i%6+3), "normHits", "0.1"));- assertU(adoc("id", Integer.toString(i+12), "popularity", "201", "description", "Big Apple is New York.", "normHits", "0.01"));- assertU(adoc("id", Integer.toString(i+13), "popularity", "201", "description", "New some York is Big. "+ randomString(i%6+3), "normHits", "0.1"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 11),+ "popularity",+ "201",+ "description",+ "apple apple is a company " + randomString(i % 6 + 3),+ "normHits",+ "0.1"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 12),+ "popularity",+ "201",+ "description",+ "Big Apple is New York.",+ "normHits",+ "0.01"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 13),+ "popularity",+ "201",+ "description",+ "New some York is Big. " + randomString(i % 6 + 3),+ "normHits",+ "0.1"));- assertU(adoc("id", Integer.toString(i+14), "popularity", "201", "description", "apple apple is a company " + randomString(i%6+3), "normHits", "0.1"));- assertU(adoc("id", Integer.toString(i+15), "popularity", "201", "description", "Big Apple is New York.", "normHits", "0.01"));- assertU(adoc("id", Integer.toString(i+16), "popularity", "401", "description", "barack h", "normHits", "0.0"));- assertU(adoc("id", Integer.toString(i+17), "popularity", "201", "description", "red delicious apple " + randomString(i%6+3), "normHits", "0.1"));- assertU(adoc("id", Integer.toString(i+18), "popularity", "201", "description", "nyc " + randomString(i%6+3), "normHits", "0.11"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 14),+ "popularity",+ "201",+ "description",+ "apple apple is a company " + randomString(i % 6 + 3),+ "normHits",+ "0.1"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 15),+ "popularity",+ "201",+ "description",+ "Big Apple is New York.",+ "normHits",+ "0.01"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 16),+ "popularity",+ "401",+ "description",+ "barack h",+ "normHits",+ "0.0"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 17),+ "popularity",+ "201",+ "description",+ "red delicious apple " + randomString(i % 6 + 3),+ "normHits",+ "0.1"));+ assertU(+ adoc(+ "id",+ Integer.toString(i + 18),+ "popularity",+ "201",+ "description",+ "nyc " + randomString(i % 6 + 3),+ "normHits",+ "0.11"));}assertU(commit());@@ -82,26 +233,31 @@ public class TestFeatureExtractionFromMultipleSegments extends TestRerankBase {public void testFeatureExtractionFromMultipleSegments() throws Exception {final SolrQuery query = new SolrQuery();- query.setQuery("{!edismax qf='description^1' boost='sum(product(pow(normHits, 0.7), 1600), .1)' v='apple'}");- // request 100 rows, if any rows are fetched from the second or subsequent segments the tests should succeed if LTRRescorer::extractFeaturesInfo() advances the doc iterator properly+ query.setQuery(+ "{!edismax qf='description^1' boost='sum(product(pow(normHits, 0.7), 1600), .1)' v='apple'}");+ // request 100 rows, if any rows are fetched from the second or subsequent segments the tests+ // should succeed if LTRRescorer::extractFeaturesInfo() advances the doc iterator properlyint numRows = 100;query.add("rows", Integer.toString(numRows));query.add("wt", "json");query.add("fq", "popularity:201");- query.add("fl", "*, score,id,normHits,description,fv:[features store='feature-store-6' format='dense' efi.user_text='apple']");+ query.add(+ "fl",+ "*, score,id,normHits,description,fv:[features store='feature-store-6' format='dense' efi.user_text='apple']");String res = restTestHarness.query("/query" + query.toQueryString());@SuppressWarnings({"unchecked"})- Map<String,Object> resultJson = (Map<String,Object>) Utils.fromJSONString(res);+ Map<String, Object> resultJson = (Map<String, Object>) Utils.fromJSONString(res);@SuppressWarnings({"unchecked"})- List<Map<String,Object>> docs = (List<Map<String,Object>>)((Map<String,Object>)resultJson.get("response")).get("docs");+ List<Map<String, Object>> docs =+ (List<Map<String, Object>>) ((Map<String, Object>) resultJson.get("response")).get("docs");int passCount = 0;- for (final Map<String,Object> doc : docs) {- String features = (String)doc.get("fv");- assert(features.length() > 0);- ++passCount;+ for (final Map<String, Object> doc : docs) {+ String features = (String) doc.get("fv");+ assert (features.length() > 0);+ ++passCount;}- assert(passCount == numRows);+ assert (passCount == numRows);}}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureLogging.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureLogging.javaindex e7af2506b5f..054987cd9de 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureLogging.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureLogging.java@@ -39,38 +39,40 @@ public class TestFeatureLogging extends TestRerankBase {@Testpublic void testGeneratedFeatures() throws Exception {- loadFeature("c1", ValueFeature.class.getName(), "test1",- "{\"value\":1.0}");- loadFeature("c2", ValueFeature.class.getName(), "test1",- "{\"value\":2.0}");- loadFeature("c3", ValueFeature.class.getName(), "test1",- "{\"value\":3.0}");- loadFeature("pop", FieldValueFeature.class.getName(), "test1",- "{\"field\":\"popularity\"}");- loadFeature("nomatch", SolrFeature.class.getName(), "test1",- "{\"q\":\"{!terms f=title}foobarbat\"}");- loadFeature("yesmatch", SolrFeature.class.getName(), "test1",- "{\"q\":\"{!terms f=popularity}2\"}");-- loadModel("sum1", LinearModel.class.getName(), new String[] {- "c1", "c2", "c3"}, "test1",+ loadFeature("c1", ValueFeature.class.getName(), "test1", "{\"value\":1.0}");+ loadFeature("c2", ValueFeature.class.getName(), "test1", "{\"value\":2.0}");+ loadFeature("c3", ValueFeature.class.getName(), "test1", "{\"value\":3.0}");+ loadFeature("pop", FieldValueFeature.class.getName(), "test1", "{\"field\":\"popularity\"}");+ loadFeature(+ "nomatch", SolrFeature.class.getName(), "test1", "{\"q\":\"{!terms f=title}foobarbat\"}");+ loadFeature(+ "yesmatch", SolrFeature.class.getName(), "test1", "{\"q\":\"{!terms f=popularity}2\"}");++ loadModel(+ "sum1",+ LinearModel.class.getName(),+ new String[] {"c1", "c2", "c3"},+ "test1","{\"weights\":{\"c1\":1.0,\"c2\":1.0,\"c3\":1.0}}");- final String docs0fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "c1","1.0",- "c2","2.0",- "c3","3.0",- "pop","2.0",- "nomatch","0.0",- "yesmatch","1.0");- final String docs0fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector(- "c1","1.0",- "c2","2.0",- "c3","3.0",- "pop","2.0",- "yesmatch","1.0");-- final String docs0fv_default_csv = chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);+ final String docs0fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "c1", "1.0",+ "c2", "2.0",+ "c3", "3.0",+ "pop", "2.0",+ "nomatch", "0.0",+ "yesmatch", "1.0");+ final String docs0fv_sparse_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "c1", "1.0",+ "c2", "2.0",+ "c3", "3.0",+ "pop", "2.0",+ "yesmatch", "1.0");++ final String docs0fv_default_csv =+ chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);final SolrQuery query = new SolrQuery();query.setQuery("title:bloomberg");@@ -82,7 +84,9 @@ public class TestFeatureLogging extends TestRerankBase {restTestHarness.query("/query" + query.toQueryString());assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'title':'bloomberg bloomberg ', 'description':'bloomberg','id':'7', 'popularity':2, '[fv]':'"+docs0fv_default_csv+"'}");+ "/response/docs/[0]/=={'title':'bloomberg bloomberg ', 'description':'bloomberg','id':'7', 'popularity':2, '[fv]':'"+ + docs0fv_default_csv+ + "'}");query.remove("fl");query.add("fl", "[fv]");@@ -90,25 +94,26 @@ public class TestFeatureLogging extends TestRerankBase {query.add("rq", "{!ltr reRankDocs=3 model=sum1}");restTestHarness.query("/query" + query.toQueryString());- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'[fv]':'"+docs0fv_default_csv+"'}");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'[fv]':'" + docs0fv_default_csv + "'}");}@Testpublic void testDefaultStoreFeatureExtraction() throws Exception {- loadFeature("defaultf1", ValueFeature.class.getName(),+ loadFeature(+ "defaultf1",+ ValueFeature.class.getName(),FeatureStore.DEFAULT_FEATURE_STORE_NAME,"{\"value\":1.0}");- loadFeature("store8f1", ValueFeature.class.getName(),- "store8",- "{\"value\":2.0}");- loadFeature("store9f1", ValueFeature.class.getName(),+ loadFeature("store8f1", ValueFeature.class.getName(), "store8", "{\"value\":2.0}");+ loadFeature("store9f1", ValueFeature.class.getName(), "store9", "{\"value\":3.0}");+ loadModel(+ "store9m1",+ LinearModel.class.getName(),+ new String[] {"store9f1"},"store9",- "{\"value\":3.0}");- loadModel("store9m1", LinearModel.class.getName(),- new String[] {"store9f1"},- "store9",- "{\"weights\":{\"store9f1\":1.0}}");+ "{\"weights\":{\"store9f1\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("id:7");@@ -116,41 +121,52 @@ public class TestFeatureLogging extends TestRerankBase {// No store specified, use default store for extractionquery.add("fl", "fv:[fv]");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'fv':'"+FeatureLoggerTestUtils.toFeatureVector("defaultf1","1.0")+"'}");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'fv':'"+ + FeatureLoggerTestUtils.toFeatureVector("defaultf1", "1.0")+ + "'}");// Store specified, use store for extractionquery.remove("fl");query.add("fl", "fv:[fv store=store8]");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'fv':'"+FeatureLoggerTestUtils.toFeatureVector("store8f1","2.0")+"'}");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'fv':'"+ + FeatureLoggerTestUtils.toFeatureVector("store8f1", "2.0")+ + "'}");// Store specified + model specified, use store for extractionquery.add("rq", "{!ltr reRankDocs=3 model=store9m1}");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'fv':'"+FeatureLoggerTestUtils.toFeatureVector("store8f1","2.0")+"'}");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'fv':'"+ + FeatureLoggerTestUtils.toFeatureVector("store8f1", "2.0")+ + "'}");// No store specified + model specified, use model store for extractionquery.remove("fl");query.add("fl", "fv:[fv]");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'fv':'"+FeatureLoggerTestUtils.toFeatureVector("store9f1","3.0")+"'}");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'fv':'"+ + FeatureLoggerTestUtils.toFeatureVector("store9f1", "3.0")+ + "'}");}-@Testpublic void testGeneratedGroup() throws Exception {- loadFeature("c1", ValueFeature.class.getName(), "testgroup",- "{\"value\":1.0}");- loadFeature("c2", ValueFeature.class.getName(), "testgroup",- "{\"value\":2.0}");- loadFeature("c3", ValueFeature.class.getName(), "testgroup",- "{\"value\":3.0}");- loadFeature("pop", FieldValueFeature.class.getName(), "testgroup",- "{\"field\":\"popularity\"}");-- loadModel("sumgroup", LinearModel.class.getName(), new String[] {- "c1", "c2", "c3"}, "testgroup",+ loadFeature("c1", ValueFeature.class.getName(), "testgroup", "{\"value\":1.0}");+ loadFeature("c2", ValueFeature.class.getName(), "testgroup", "{\"value\":2.0}");+ loadFeature("c3", ValueFeature.class.getName(), "testgroup", "{\"value\":3.0}");+ loadFeature(+ "pop", FieldValueFeature.class.getName(), "testgroup", "{\"field\":\"popularity\"}");++ loadModel(+ "sumgroup",+ LinearModel.class.getName(),+ new String[] {"c1", "c2", "c3"},+ "testgroup","{\"weights\":{\"c1\":1.0,\"c2\":1.0,\"c3\":1.0}}");final SolrQuery query = new SolrQuery();@@ -166,72 +182,73 @@ public class TestFeatureLogging extends TestRerankBase {query.add("rq", "{!ltr reRankDocs=3 model=sumgroup}");- final String docs0fv_csv = FeatureLoggerTestUtils.toFeatureVector(- "c1","1.0",- "c2","2.0",- "c3","3.0",- "pop","5.0");+ final String docs0fv_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "c1", "1.0",+ "c2", "2.0",+ "c3", "3.0",+ "pop", "5.0");restTestHarness.query("/query" + query.toQueryString());assertJQ("/query" + query.toQueryString(),- "/grouped/title/groups/[0]/doclist/docs/[0]/=={'fv':'"+docs0fv_csv+"'}");+ "/grouped/title/groups/[0]/doclist/docs/[0]/=={'fv':'" + docs0fv_csv + "'}");}@Testpublic void testSparseDenseFeatures() throws Exception {- loadFeature("match", SolrFeature.class.getName(), "test4",- "{\"q\":\"{!terms f=title}different\"}");- loadFeature("c4", ValueFeature.class.getName(), "test4",- "{\"value\":1.0}");-- loadModel("sum4", LinearModel.class.getName(), new String[] {- "match"}, "test4",+ loadFeature(+ "match", SolrFeature.class.getName(), "test4", "{\"q\":\"{!terms f=title}different\"}");+ loadFeature("c4", ValueFeature.class.getName(), "test4", "{\"value\":1.0}");++ loadModel(+ "sum4",+ LinearModel.class.getName(),+ new String[] {"match"},+ "test4","{\"weights\":{\"match\":1.0}}");- final String docs0fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector("match", "1.0", "c4", "1.0");- final String docs1fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector( "c4", "1.0");+ final String docs0fv_sparse_csv =+ FeatureLoggerTestUtils.toFeatureVector("match", "1.0", "c4", "1.0");+ final String docs1fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector("c4", "1.0");- final String docs0fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector("match", "1.0", "c4", "1.0");- final String docs1fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector("match", "0.0", "c4", "1.0");+ final String docs0fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector("match", "1.0", "c4", "1.0");+ final String docs1fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector("match", "0.0", "c4", "1.0");- final String docs0fv_default_csv = chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);- final String docs1fv_default_csv = chooseDefaultFeatureVector(docs1fv_dense_csv, docs1fv_sparse_csv);+ final String docs0fv_default_csv =+ chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);+ final String docs1fv_default_csv =+ chooseDefaultFeatureVector(docs1fv_dense_csv, docs1fv_sparse_csv);final SolrQuery query = new SolrQuery();query.setQuery("title:bloomberg");query.add("rows", "10");query.add("rq", "{!ltr reRankDocs=10 model=sum4}");- //csv - no feature format specified i.e. use default+ // csv - no feature format specified i.e. use defaultquery.remove("fl");query.add("fl", "*,score,fv:[fv store=test4]");assertJQ(- "/query" + query.toQueryString(),- "/response/docs/[0]/fv/=='"+docs0fv_default_csv+"'");+ "/query" + query.toQueryString(), "/response/docs/[0]/fv/=='" + docs0fv_default_csv + "'");assertJQ(- "/query" + query.toQueryString(),- "/response/docs/[1]/fv/=='"+docs1fv_default_csv+"'");+ "/query" + query.toQueryString(), "/response/docs/[1]/fv/=='" + docs1fv_default_csv + "'");- //csv - sparse feature format check+ // csv - sparse feature format checkquery.remove("fl");query.add("fl", "*,score,fv:[fv store=test4 format=sparse]");assertJQ(- "/query" + query.toQueryString(),- "/response/docs/[0]/fv/=='"+docs0fv_sparse_csv+"'");+ "/query" + query.toQueryString(), "/response/docs/[0]/fv/=='" + docs0fv_sparse_csv + "'");assertJQ(- "/query" + query.toQueryString(),- "/response/docs/[1]/fv/=='"+docs1fv_sparse_csv+"'");+ "/query" + query.toQueryString(), "/response/docs/[1]/fv/=='" + docs1fv_sparse_csv + "'");- //csv - dense feature format check+ // csv - dense feature format checkquery.remove("fl");query.add("fl", "*,score,fv:[fv store=test4 format=dense]");assertJQ(- "/query" + query.toQueryString(),- "/response/docs/[0]/fv/=='"+docs0fv_dense_csv+"'");+ "/query" + query.toQueryString(), "/response/docs/[0]/fv/=='" + docs0fv_dense_csv + "'");assertJQ(- "/query" + query.toQueryString(),- "/response/docs/[1]/fv/=='"+docs1fv_dense_csv+"'");+ "/query" + query.toQueryString(), "/response/docs/[1]/fv/=='" + docs1fv_dense_csv + "'");}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFieldLengthFeature.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFieldLengthFeature.javaindex b913d1bd72b..efafdcb4a0a 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFieldLengthFeature.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFieldLengthFeature.java@@ -17,7 +17,6 @@package org.apache.solr.ltr.feature;import java.util.LinkedHashMap;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;@@ -32,16 +31,13 @@ public class TestFieldLengthFeature extends TestRerankBase {setuptest(false);assertU(adoc("id", "1", "title", "w1", "description", "w1"));- assertU(adoc("id", "2", "title", "w2 2asd asdd didid", "description",- "w2 2asd asdd didid"));+ assertU(adoc("id", "2", "title", "w2 2asd asdd didid", "description", "w2 2asd asdd didid"));assertU(adoc("id", "3", "title", "w3", "description", "w3"));assertU(adoc("id", "4", "title", "w4", "description", "w4"));assertU(adoc("id", "5", "title", "w5", "description", "w5"));assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2"));- assertU(adoc("id", "7", "title", "w1 w2 w3 w4 w5", "description",- "w1 w2 w3 w4 w5 w8"));- assertU(adoc("id", "8", "title", "w1 w1 w1 w2 w2 w8", "description",- "w1 w1 w1 w2 w2"));+ assertU(adoc("id", "7", "title", "w1 w2 w3 w4 w5", "description", "w1 w2 w3 w4 w5 w8"));+ assertU(adoc("id", "8", "title", "w1 w1 w1 w2 w2 w8", "description", "w1 w1 w1 w2 w2"));assertU(commit());}@@ -56,11 +52,14 @@ public class TestFieldLengthFeature extends TestRerankBase {assertU(adoc("id", "42", "title", "w10"));assertU(commit());- loadFeature("description-length2", FieldLengthFeature.class.getName(),- "{\"field\":\"description\"}");+ loadFeature(+ "description-length2", FieldLengthFeature.class.getName(), "{\"field\":\"description\"}");- loadModel("description-model2", LinearModel.class.getName(),- new String[] {"description-length2"}, "{\"weights\":{\"description-length2\":1.0}}");+ loadModel(+ "description-model2",+ LinearModel.class.getName(),+ new String[] {"description-length2"},+ "{\"weights\":{\"description-length2\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:w10");@@ -70,18 +69,20 @@ public class TestFieldLengthFeature extends TestRerankBase {assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==0.0");}-@Testpublic void testIfFieldIsEmptyLengthIsZero() throws Exception {// add a document without the field 'description'assertU(adoc("id", "43", "title", "w11", "description", ""));assertU(commit());- loadFeature("description-length3", FieldLengthFeature.class.getName(),- "{\"field\":\"description\"}");+ loadFeature(+ "description-length3", FieldLengthFeature.class.getName(), "{\"field\":\"description\"}");- loadModel("description-model3", LinearModel.class.getName(),- new String[] {"description-length3"}, "{\"weights\":{\"description-length3\":1.0}}");+ loadModel(+ "description-model3",+ LinearModel.class.getName(),+ new String[] {"description-length3"},+ "{\"weights\":{\"description-length3\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:w11");@@ -91,14 +92,15 @@ public class TestFieldLengthFeature extends TestRerankBase {assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==0.0");}-@Testpublic void testRanking() throws Exception {- loadFeature("title-length", FieldLengthFeature.class.getName(),- "{\"field\":\"title\"}");+ loadFeature("title-length", FieldLengthFeature.class.getName(), "{\"field\":\"title\"}");- loadModel("title-model", LinearModel.class.getName(),- new String[] {"title-length"}, "{\"weights\":{\"title-length\":1.0}}");+ loadModel(+ "title-model",+ LinearModel.class.getName(),+ new String[] {"title-length"},+ "{\"weights\":{\"title-length\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:w1");@@ -132,10 +134,11 @@ public class TestFieldLengthFeature extends TestRerankBase {assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='2'");assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='6'");- loadFeature("description-length",- FieldLengthFeature.class.getName(),- "{\"field\":\"description\"}");- loadModel("description-model", LinearModel.class.getName(),+ loadFeature(+ "description-length", FieldLengthFeature.class.getName(), "{\"field\":\"description\"}");+ loadModel(+ "description-model",+ LinearModel.class.getName(),new String[] {"description-length"},"{\"weights\":{\"description-length\":1.0}}");query.setQuery("title:w1");@@ -153,12 +156,8 @@ public class TestFieldLengthFeature extends TestRerankBase {@Testpublic void testParamsToMap() throws Exception {- final LinkedHashMap<String,Object> params = new LinkedHashMap<String,Object>();- params.put("field", "field"+random().nextInt(10));+ final LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();+ params.put("field", "field" + random().nextInt(10));doTestParamsToMap(FieldLengthFeature.class.getName(), params);}----}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.javaindex 15a007bb584..cae28a25b0a 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java@@ -19,7 +19,6 @@ package org.apache.solr.ltr.feature;import java.io.IOException;import java.util.LinkedHashMap;import java.util.Map;-import org.apache.lucene.index.LeafReaderContext;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.Query;@@ -41,56 +40,153 @@ public class TestFieldValueFeature extends TestRerankBase {private static final float FIELD_VALUE_FEATURE_DEFAULT_VAL = 0.0f;private static final String[] FIELDS = {- "popularity",- "dvIntPopularity", "dvLongPopularity",- "dvFloatPopularity", "dvDoublePopularity",- "dvStringPopularity",- "isTrendy",- "dvIsTrendy"+ "popularity",+ "dvIntPopularity",+ "dvLongPopularity",+ "dvFloatPopularity",+ "dvDoublePopularity",+ "dvStringPopularity",+ "isTrendy",+ "dvIsTrendy"};@Beforepublic void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "popularity", "1", "title", "w1",- "dvStringPopularity", "1",- "description", "w1", "isTrendy", "true"));- assertU(adoc("id", "2", "popularity", "2", "title", "w2 2asd asdd didid",- "dvStringPopularity", "2",- "description", "w2 2asd asdd didid"));- assertU(adoc("id", "3", "popularity", "3", "title", "w3",- "dvStringPopularity", "3",- "description", "w3", "isTrendy", "true"));- assertU(adoc("id", "4", "popularity", "4", "title", "w4",- "dvStringPopularity", "4",- "description", "w4", "isTrendy", "false"));- assertU(adoc("id", "5", "popularity", "5", "title", "w5",- "dvStringPopularity", "5",- "description", "w5", "isTrendy", "true"));- assertU(adoc("id", "6", "popularity", "6", "title", "w1 w2",- "dvStringPopularity", "6",- "description", "w1 w2", "isTrendy", "false"));- assertU(adoc("id", "7", "popularity", "7", "title", "w1 w2 w3 w4 w5",- "dvStringPopularity", "7",- "description", "w1 w2 w3 w4 w5 w8", "isTrendy", "true"));- assertU(adoc("id", "8", "popularity", "8", "title", "w1 w1 w1 w2 w2 w8",- "dvStringPopularity", "8",- "description", "w1 w1 w1 w2 w2", "isTrendy", "false"));+ assertU(+ adoc(+ "id",+ "1",+ "popularity",+ "1",+ "title",+ "w1",+ "dvStringPopularity",+ "1",+ "description",+ "w1",+ "isTrendy",+ "true"));+ assertU(+ adoc(+ "id",+ "2",+ "popularity",+ "2",+ "title",+ "w2 2asd asdd didid",+ "dvStringPopularity",+ "2",+ "description",+ "w2 2asd asdd didid"));+ assertU(+ adoc(+ "id",+ "3",+ "popularity",+ "3",+ "title",+ "w3",+ "dvStringPopularity",+ "3",+ "description",+ "w3",+ "isTrendy",+ "true"));+ assertU(+ adoc(+ "id",+ "4",+ "popularity",+ "4",+ "title",+ "w4",+ "dvStringPopularity",+ "4",+ "description",+ "w4",+ "isTrendy",+ "false"));+ assertU(+ adoc(+ "id",+ "5",+ "popularity",+ "5",+ "title",+ "w5",+ "dvStringPopularity",+ "5",+ "description",+ "w5",+ "isTrendy",+ "true"));+ assertU(+ adoc(+ "id",+ "6",+ "popularity",+ "6",+ "title",+ "w1 w2",+ "dvStringPopularity",+ "6",+ "description",+ "w1 w2",+ "isTrendy",+ "false"));+ assertU(+ adoc(+ "id",+ "7",+ "popularity",+ "7",+ "title",+ "w1 w2 w3 w4 w5",+ "dvStringPopularity",+ "7",+ "description",+ "w1 w2 w3 w4 w5 w8",+ "isTrendy",+ "true"));+ assertU(+ adoc(+ "id",+ "8",+ "popularity",+ "8",+ "title",+ "w1 w1 w1 w2 w2 w8",+ "dvStringPopularity",+ "8",+ "description",+ "w1 w1 w1 w2 w2",+ "isTrendy",+ "false"));// a document without the popularity and the dv fields- assertU(adoc("id", "42", "title", "NO popularity or isTrendy", "description", "NO popularity or isTrendy"));+ assertU(+ adoc(+ "id",+ "42",+ "title",+ "NO popularity or isTrendy",+ "description",+ "NO popularity or isTrendy"));assertU(commit());for (String field : FIELDS) {- loadFeature(field, FieldValueFeature.class.getName(),- "{\"field\":\"" + field + "\"}");+ loadFeature(field, FieldValueFeature.class.getName(), "{\"field\":\"" + field + "\"}");}- loadModel("model", LinearModel.class.getName(), FIELDS,- "{\"weights\":{\"popularity\":1.0,\"dvIntPopularity\":1.0,\"dvLongPopularity\":1.0," +- "\"dvFloatPopularity\":1.0,\"dvDoublePopularity\":1.0," +- "\"dvStringPopularity\":1.0,\"isTrendy\":1.0,\"dvIsTrendy\":1.0}}");+ loadModel(+ "model",+ LinearModel.class.getName(),+ FIELDS,+ "{\"weights\":{\"popularity\":1.0,\"dvIntPopularity\":1.0,\"dvLongPopularity\":1.0,"+ + "\"dvFloatPopularity\":1.0,\"dvDoublePopularity\":1.0,"+ + "\"dvStringPopularity\":1.0,\"isTrendy\":1.0,\"dvIsTrendy\":1.0}}");}@After@@ -133,7 +229,6 @@ public class TestFieldValueFeature extends TestRerankBase {assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='5'");}-@Testpublic void testIfADocumentDoesntHaveAFieldDefaultValueIsReturned() throws Exception {SolrQuery query = new SolrQuery();@@ -154,43 +249,54 @@ public class TestFieldValueFeature extends TestRerankBase {assertEquals("0.0", Float.toString(FIELD_VALUE_FEATURE_DEFAULT_VAL));assertJQ("/query" + query.toQueryString(), "/response/numFound/==1");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'[fv]':'popularity=0.0,dvIntPopularity=0.0,dvLongPopularity=0.0," +- "dvFloatPopularity=0.0,dvDoublePopularity=0.0," +- "dvStringPopularity=0.0,isTrendy=0.0,dvIsTrendy=0.0'}");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'[fv]':'popularity=0.0,dvIntPopularity=0.0,dvLongPopularity=0.0,"+ + "dvFloatPopularity=0.0,dvDoublePopularity=0.0,"+ + "dvStringPopularity=0.0,isTrendy=0.0,dvIsTrendy=0.0'}");}-@Testpublic void testIfADocumentDoesntHaveAFieldASetDefaultValueIsReturned() throws Exception {for (String field : FIELDS) {- final String fstore = "testIfADocumentDoesntHaveAFieldASetDefaultValueIsReturned"+field;+ final String fstore = "testIfADocumentDoesntHaveAFieldASetDefaultValueIsReturned" + field;- loadFeature(field+"42", FieldValueFeature.class.getName(), fstore,- "{\"field\":\""+field+"\",\"defaultValue\":\"42.0\"}");+ loadFeature(+ field + "42",+ FieldValueFeature.class.getName(),+ fstore,+ "{\"field\":\"" + field + "\",\"defaultValue\":\"42.0\"}");SolrQuery query = new SolrQuery();query.setQuery("id:42");query.add("fl", "*, score");query.add("rows", "4");- loadModel(field+"-model42", LinearModel.class.getName(),- new String[] {field+"42"}, fstore, "{\"weights\":{\""+field+"42\":1.0}}");+ loadModel(+ field + "-model42",+ LinearModel.class.getName(),+ new String[] {field + "42"},+ fstore,+ "{\"weights\":{\"" + field + "42\":1.0}}");assertJQ("/query" + query.toQueryString(), "/response/numFound/==1");assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='42'");query = new SolrQuery();query.setQuery("id:42");- query.add("rq", "{!ltr model="+field+"-model42 reRankDocs=4}");+ query.add("rq", "{!ltr model=" + field + "-model42 reRankDocs=4}");query.add("fl", "[fv]");assertJQ("/query" + query.toQueryString(), "/response/numFound/==1");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'[fv]':'"+FeatureLoggerTestUtils.toFeatureVector(field+"42","42.0")+"'}");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(field + "42", "42.0")+ + "'}");}}@Test- public void testIfADocumentDoesntHaveAFieldTheDefaultValueFromSchemaIsReturned() throws Exception {+ public void testIfADocumentDoesntHaveAFieldTheDefaultValueFromSchemaIsReturned()+ throws Exception {final String[] fieldsWithDefaultValues = {"dvIntField", "dvLongField", "dvFloatField"};final String[] defaultValues = {"-1.0", "-2.0", "-3.0"};@@ -198,23 +304,31 @@ public class TestFieldValueFeature extends TestRerankBase {final String field = fieldsWithDefaultValues[idx];final String defaultValue = defaultValues[idx];- final String fstore = "testIfADocumentDoesntHaveAFieldTheDefaultValueFromSchemaIsReturned"+field;+ final String fstore =+ "testIfADocumentDoesntHaveAFieldTheDefaultValueFromSchemaIsReturned" + field;assertU(adoc("id", "21"));assertU(commit());- loadFeature(field, FieldValueFeature.class.getName(), fstore,- "{\"field\":\""+field+"\"}");- loadModel(field+"-model", LinearModel.class.getName(),- new String[] {field}, fstore, "{\"weights\":{\"" + field + "\":1.0}}");+ loadFeature(+ field, FieldValueFeature.class.getName(), fstore, "{\"field\":\"" + field + "\"}");+ loadModel(+ field + "-model",+ LinearModel.class.getName(),+ new String[] {field},+ fstore,+ "{\"weights\":{\"" + field + "\":1.0}}");final SolrQuery query = new SolrQuery("id:21");- query.add("rq", "{!ltr model="+field+"-model reRankDocs=4}");+ query.add("rq", "{!ltr model=" + field + "-model reRankDocs=4}");query.add("fl", "[fv]");assertJQ("/query" + query.toQueryString(), "/response/numFound/==1");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'[fv]':'"+FeatureLoggerTestUtils.toFeatureVector(field, defaultValue)+"'}");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(field, defaultValue)+ + "'}");}}@@ -223,11 +337,18 @@ public class TestFieldValueFeature extends TestRerankBase {// this tests the case that we create a feature for a non-existent field// using a different fstore to avoid a clash with the other testsfinal String fstore = "testThatFieldValueFeatureScorerIsUsedAndDefaultIsReturned";- loadFeature("not-existing-field", ObservingFieldValueFeature.class.getName(), fstore,- "{\"field\":\"cowabunga\"}");-- loadModel("not-existing-field-model", LinearModel.class.getName(),- new String[] {"not-existing-field"}, fstore, "{\"weights\":{\"not-existing-field\":1.0}}");+ loadFeature(+ "not-existing-field",+ ObservingFieldValueFeature.class.getName(),+ fstore,+ "{\"field\":\"cowabunga\"}");++ loadModel(+ "not-existing-field-model",+ LinearModel.class.getName(),+ new String[] {"not-existing-field"},+ fstore,+ "{\"weights\":{\"not-existing-field\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("id:42");@@ -235,9 +356,14 @@ public class TestFieldValueFeature extends TestRerankBase {query.add("fl", "[fv]");ObservingFieldValueFeature.usedScorerClass = null; // to clear away any previous test's useassertJQ("/query" + query.toQueryString(), "/response/numFound/==1");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'[fv]':'"+FeatureLoggerTestUtils.toFeatureVector("not-existing-field",Float.toString(FIELD_VALUE_FEATURE_DEFAULT_VAL))+"'}");- assertEquals(FieldValueFeatureScorer.class.getName(), ObservingFieldValueFeature.usedScorerClass);+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(+ "not-existing-field", Float.toString(FIELD_VALUE_FEATURE_DEFAULT_VAL))+ + "'}");+ assertEquals(+ FieldValueFeatureScorer.class.getName(), ObservingFieldValueFeature.usedScorerClass);}@Test@@ -246,146 +372,224 @@ public class TestFieldValueFeature extends TestRerankBase {// this tests the case that no document contains docValues for the provided existing fieldfor (String field : fieldsWithoutDefaultValues) {- final String fstore = "testThatDefaultFieldValueScorerIsUsedAndDefaultIsReturned"+field;+ final String fstore = "testThatDefaultFieldValueScorerIsUsedAndDefaultIsReturned" + field;- loadFeature(field, ObservingFieldValueFeature.class.getName(), fstore,- "{\"field\":\""+field+"\"}");+ loadFeature(+ field,+ ObservingFieldValueFeature.class.getName(),+ fstore,+ "{\"field\":\"" + field + "\"}");- loadModel(field+"-model", LinearModel.class.getName(),- new String[] {field}, fstore, "{\"weights\":{\""+field+"\":1.0}}");+ loadModel(+ field + "-model",+ LinearModel.class.getName(),+ new String[] {field},+ fstore,+ "{\"weights\":{\"" + field + "\":1.0}}");final SolrQuery query = new SolrQuery("id:42");- query.add("rq", "{!ltr model="+field+"-model reRankDocs=4}");+ query.add("rq", "{!ltr model=" + field + "-model reRankDocs=4}");query.add("fl", "[fv]");ObservingFieldValueFeature.usedScorerClass = null; // to clear away any previous test's useassertJQ("/query" + query.toQueryString(), "/response/numFound/==1");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'[fv]':'"+FeatureLoggerTestUtils- .toFeatureVector(field,Float.toString(FIELD_VALUE_FEATURE_DEFAULT_VAL))+"'}");- assertEquals(DefaultValueFieldValueFeatureScorer.class.getName(), ObservingFieldValueFeature.usedScorerClass);+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(+ field, Float.toString(FIELD_VALUE_FEATURE_DEFAULT_VAL))+ + "'}");+ assertEquals(+ DefaultValueFieldValueFeatureScorer.class.getName(),+ ObservingFieldValueFeature.usedScorerClass);}}@Testpublic void testBooleanValue() throws Exception {final String fstore = "test_boolean_store";- loadFeature("trendy", FieldValueFeature.class.getName(), fstore,- "{\"field\":\"isTrendy\"}");+ loadFeature("trendy", FieldValueFeature.class.getName(), fstore, "{\"field\":\"isTrendy\"}");- loadModel("trendy-model", LinearModel.class.getName(),- new String[] {"trendy"}, fstore, "{\"weights\":{\"trendy\":1.0}}");+ loadModel(+ "trendy-model",+ LinearModel.class.getName(),+ new String[] {"trendy"},+ fstore,+ "{\"weights\":{\"trendy\":1.0}}");SolrQuery query = new SolrQuery();query.setQuery("id:4");query.add("rq", "{!ltr model=trendy-model reRankDocs=4}");query.add("fl", "[fv]");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'[fv]':'"+FeatureLoggerTestUtils.toFeatureVector("trendy","0.0")+"'}");-+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector("trendy", "0.0")+ + "'}");query = new SolrQuery();query.setQuery("id:5");query.add("rq", "{!ltr model=trendy-model reRankDocs=4}");query.add("fl", "[fv]");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'[fv]':'"+FeatureLoggerTestUtils.toFeatureVector("trendy","1.0")+"'}");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector("trendy", "1.0")+ + "'}");// check default value is falsequery = new SolrQuery();query.setQuery("id:2");query.add("rq", "{!ltr model=trendy-model reRankDocs=4}");query.add("fl", "[fv]");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'[fv]':'"+FeatureLoggerTestUtils.toFeatureVector("trendy","0.0")+"'}");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector("trendy", "0.0")+ + "'}");}@Testpublic void testThatExceptionIsThrownForUnsupportedType() throws Exception {final String fstore = "test_store";- assertU(adoc("id", "21", "title", "multivalued not supported", "dvStringPopularities", "wow value"));+ assertU(+ adoc(+ "id", "21", "title", "multivalued not supported", "dvStringPopularities", "wow value"));assertU(commit());- loadFeature("dvStringPopularities", FieldValueFeature.class.getName(), fstore,- "{\"field\":\"dvStringPopularities\"}");+ loadFeature(+ "dvStringPopularities",+ FieldValueFeature.class.getName(),+ fstore,+ "{\"field\":\"dvStringPopularities\"}");- loadModel("dvStringPopularities-model", LinearModel.class.getName(),- new String[] {"dvStringPopularities"}, fstore, "{\"weights\":{\"dvStringPopularities\":1.0}}");+ loadModel(+ "dvStringPopularities-model",+ LinearModel.class.getName(),+ new String[] {"dvStringPopularities"},+ fstore,+ "{\"weights\":{\"dvStringPopularities\":1.0}}");final SolrQuery query = new SolrQuery("id:21");query.add("rq", "{!ltr model=dvStringPopularities-model reRankDocs=4}");query.add("fl", "[fv]");- assertJQ("/query" + query.toQueryString(),+ assertJQ(+ "/query" + query.toQueryString(),"/error/msg/=='java.lang.IllegalArgumentException: Doc values type SORTED_SET of field dvStringPopularities is not supported'");}@Testpublic void testThatCorrectFieldValueFeatureIsUsedForDocValueTypes() throws Exception {final String[][] fieldsWithDifferentTypes = {- new String[]{"dvIntPopularity", "1", NumericDocValuesFieldValueFeatureScorer.class.getName()},- new String[]{"dvStringPopularity", "T", SortedDocValuesFieldValueFeatureScorer.class.getName()},- new String[]{"noDvFloatField", "1", FieldValueFeatureScorer.class.getName()},- new String[]{"noDvStrNumField", "T", FieldValueFeatureScorer.class.getName()}+ new String[] {+ "dvIntPopularity", "1", NumericDocValuesFieldValueFeatureScorer.class.getName()+ },+ new String[] {+ "dvStringPopularity", "T", SortedDocValuesFieldValueFeatureScorer.class.getName()+ },+ new String[] {"noDvFloatField", "1", FieldValueFeatureScorer.class.getName()},+ new String[] {"noDvStrNumField", "T", FieldValueFeatureScorer.class.getName()}};for (String[] fieldAndScorerClass : fieldsWithDifferentTypes) {final String field = fieldAndScorerClass[0];final String fieldValue = fieldAndScorerClass[1];- final String fstore = "testThatCorrectFieldValueFeatureIsUsedForDocValueTypes"+field;+ final String fstore = "testThatCorrectFieldValueFeatureIsUsedForDocValueTypes" + field;assertU(adoc("id", "21", field, fieldValue));assertU(commit());- loadFeature(field, ObservingFieldValueFeature.class.getName(), fstore,- "{\"field\":\""+field+"\"}");- loadModel(field+"-model", LinearModel.class.getName(),- new String[] {field}, fstore, "{\"weights\":{\"" + field + "\":1.0}}");+ loadFeature(+ field,+ ObservingFieldValueFeature.class.getName(),+ fstore,+ "{\"field\":\"" + field + "\"}");+ loadModel(+ field + "-model",+ LinearModel.class.getName(),+ new String[] {field},+ fstore,+ "{\"weights\":{\"" + field + "\":1.0}}");final SolrQuery query = new SolrQuery("id:21");- query.add("rq", "{!ltr model="+field+"-model reRankDocs=4}");+ query.add("rq", "{!ltr model=" + field + "-model reRankDocs=4}");query.add("fl", "[fv]");ObservingFieldValueFeature.usedScorerClass = null; // to clear away any previous test's useassertJQ("/query" + query.toQueryString(), "/response/numFound/==1");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/=={'[fv]':'"+FeatureLoggerTestUtils.toFeatureVector(field, "1.0")+"'}");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(field, "1.0")+ + "'}");assertEquals(fieldAndScorerClass[2], ObservingFieldValueFeature.usedScorerClass);}}@Testpublic void testParamsToMap() throws Exception {- final LinkedHashMap<String,Object> params = new LinkedHashMap<String,Object>();- params.put("field", "field"+random().nextInt(10));+ final LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();+ params.put("field", "field" + random().nextInt(10));doTestParamsToMap(FieldValueFeature.class.getName(), params);}@Testpublic void testThatStringValuesAreCorrectlyParsed() throws Exception {- for (String field : new String[] {"dvStrNumField" , "noDvStrNumField"}) {+ for (String field : new String[] {"dvStrNumField", "noDvStrNumField"}) {final String[][] inputsAndTests = {- new String[]{"T", "/response/docs/[0]/=={'[fv]':'" +- FeatureLoggerTestUtils.toFeatureVector(field, "1.0")+"'}"},- new String[]{"F", "/response/docs/[0]/=={'[fv]':'" +- FeatureLoggerTestUtils.toFeatureVector(field, "0.0")+"'}"},- new String[]{"-7324.427", "/response/docs/[0]/=={'[fv]':'" +- FeatureLoggerTestUtils.toFeatureVector(field, Float.toString(FIELD_VALUE_FEATURE_DEFAULT_VAL))+"'}"},- new String[]{"532", "/response/docs/[0]/=={'[fv]':'" +- FeatureLoggerTestUtils.toFeatureVector(field, Float.toString(FIELD_VALUE_FEATURE_DEFAULT_VAL))+"'}"},- new String[]{Float.toString(Float.NaN), "/response/docs/[0]/=={'[fv]':'" +- FeatureLoggerTestUtils.toFeatureVector(field, Float.toString(FIELD_VALUE_FEATURE_DEFAULT_VAL))+"'}"},- new String[]{"notanumber", "/response/docs/[0]/=={'[fv]':'" +- FeatureLoggerTestUtils.toFeatureVector(field, Float.toString(FIELD_VALUE_FEATURE_DEFAULT_VAL))+"'}"}+ new String[] {+ "T",+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(field, "1.0")+ + "'}"+ },+ new String[] {+ "F",+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(field, "0.0")+ + "'}"+ },+ new String[] {+ "-7324.427",+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(+ field, Float.toString(FIELD_VALUE_FEATURE_DEFAULT_VAL))+ + "'}"+ },+ new String[] {+ "532",+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(+ field, Float.toString(FIELD_VALUE_FEATURE_DEFAULT_VAL))+ + "'}"+ },+ new String[] {+ Float.toString(Float.NaN),+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(+ field, Float.toString(FIELD_VALUE_FEATURE_DEFAULT_VAL))+ + "'}"+ },+ new String[] {+ "notanumber",+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(+ field, Float.toString(FIELD_VALUE_FEATURE_DEFAULT_VAL))+ + "'}"+ }};- final String fstore = "testThatStringValuesAreCorrectlyParsed"+field;- loadFeature(field, FieldValueFeature.class.getName(), fstore,- "{\"field\":\"" + field + "\"}");- loadModel(field+"-model", LinearModel.class.getName(),- new String[]{field}, fstore,- "{\"weights\":{\""+field+"\":1.0}}");+ final String fstore = "testThatStringValuesAreCorrectlyParsed" + field;+ loadFeature(+ field, FieldValueFeature.class.getName(), fstore, "{\"field\":\"" + field + "\"}");+ loadModel(+ field + "-model",+ LinearModel.class.getName(),+ new String[] {field},+ fstore,+ "{\"weights\":{\"" + field + "\":1.0}}");for (String[] inputAndTest : inputsAndTests) {assertU(adoc("id", "21", field, inputAndTest[0]));@@ -404,20 +608,35 @@ public class TestFieldValueFeature extends TestRerankBase {public void testThatDateValuesAreCorrectlyParsed() throws Exception {for (String field : new String[] {"dvDateField", "noDvDateField"}) {final String[][] inputsAndTests = {- new String[]{"1970-01-01T00:00:00.000Z", "/response/docs/[0]/=={'[fv]':'" +- FeatureLoggerTestUtils.toFeatureVector(field, "0.0")+"'}"},- new String[]{"1970-01-01T00:00:00.001Z", "/response/docs/[0]/=={'[fv]':'" +- FeatureLoggerTestUtils.toFeatureVector(field, "1.0")+"'}"},- new String[]{"1970-01-01T00:00:01.234Z", "/response/docs/[0]/=={'[fv]':'" +- FeatureLoggerTestUtils.toFeatureVector(field, "1234.0")+"'}"}+ new String[] {+ "1970-01-01T00:00:00.000Z",+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(field, "0.0")+ + "'}"+ },+ new String[] {+ "1970-01-01T00:00:00.001Z",+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(field, "1.0")+ + "'}"+ },+ new String[] {+ "1970-01-01T00:00:01.234Z",+ "/response/docs/[0]/=={'[fv]':'"+ + FeatureLoggerTestUtils.toFeatureVector(field, "1234.0")+ + "'}"+ }};- final String fstore = "testThatDateValuesAreCorrectlyParsed"+field;- loadFeature(field, FieldValueFeature.class.getName(), fstore,- "{\"field\":\"" + field + "\"}");- loadModel(field+"-model", LinearModel.class.getName(),- new String[]{field}, fstore,- "{\"weights\":{\""+field+"\":1.0}}");+ final String fstore = "testThatDateValuesAreCorrectlyParsed" + field;+ loadFeature(+ field, FieldValueFeature.class.getName(), fstore, "{\"field\":\"" + field + "\"}");+ loadModel(+ field + "-model",+ LinearModel.class.getName(),+ new String[] {field},+ fstore,+ "{\"weights\":{\"" + field + "\":1.0}}");for (String[] inputAndTest : inputsAndTests) {assertU(adoc("id", "21", field, inputAndTest[0]));@@ -433,10 +652,10 @@ public class TestFieldValueFeature extends TestRerankBase {}/**- * This class is used to track which specific FieldValueFeature is used so that we can test, whether the- * fallback mechanism works correctly.+ * This class is used to track which specific FieldValueFeature is used so that we can test,+ * whether the fallback mechanism works correctly.*/- final public static class ObservingFieldValueFeature extends FieldValueFeature {+ public static final class ObservingFieldValueFeature extends FieldValueFeature {static String usedScorerClass;public ObservingFieldValueFeature(String name, Map<String, Object> params) {@@ -444,22 +663,30 @@ public class TestFieldValueFeature extends TestRerankBase {}@Override- public Feature.FeatureWeight createWeight(IndexSearcher searcher, boolean needsScores, SolrQueryRequest request,- Query originalQuery, Map<String, String[]> efi) throws IOException {+ public Feature.FeatureWeight createWeight(+ IndexSearcher searcher,+ boolean needsScores,+ SolrQueryRequest request,+ Query originalQuery,+ Map<String, String[]> efi)+ throws IOException {return new ObservingFieldValueFeatureWeight(searcher, request, originalQuery, efi);}public class ObservingFieldValueFeatureWeight extends FieldValueFeatureWeight {- public ObservingFieldValueFeatureWeight(IndexSearcher searcher, SolrQueryRequest request,- Query originalQuery, Map<String, String[]> efi) {+ public ObservingFieldValueFeatureWeight(+ IndexSearcher searcher,+ SolrQueryRequest request,+ Query originalQuery,+ Map<String, String[]> efi) {super(searcher, request, originalQuery, efi);}@Overridepublic FeatureScorer scorer(LeafReaderContext context) throws IOException {- FeatureScorer scorer = super.scorer(context);- usedScorerClass = scorer.getClass().getName();- return scorer;+ FeatureScorer scorer = super.scorer(context);+ usedScorerClass = scorer.getClass().getName();+ return scorer;}}}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFilterSolrFeature.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFilterSolrFeature.javaindex d42176e55e2..dad9dbcd3c3 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFilterSolrFeature.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFilterSolrFeature.java@@ -30,22 +30,41 @@ public class TestFilterSolrFeature extends TestRerankBase {public void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",- "1"));- assertU(adoc("id", "2", "title", "w2 2asd asdd didid", "description",- "w2 2asd asdd didid", "popularity", "2"));- assertU(adoc("id", "3", "title", "w1", "description", "w1", "popularity",- "3"));- assertU(adoc("id", "4", "title", "w1", "description", "w1", "popularity",- "4"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity",- "5"));- assertU(adoc("id", "6", "title", "w6 w2", "description", "w1 w2",- "popularity", "6"));- assertU(adoc("id", "7", "title", "w1 w2 w3 w4 w5", "description",- "w6 w2 w3 w4 w5 w8", "popularity", "88888"));- assertU(adoc("id", "8", "title", "w1 w1 w1 w2 w2 w8", "description",- "w1 w1 w1 w2 w2", "popularity", "88888"));+ assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity", "1"));+ assertU(+ adoc(+ "id",+ "2",+ "title",+ "w2 2asd asdd didid",+ "description",+ "w2 2asd asdd didid",+ "popularity",+ "2"));+ assertU(adoc("id", "3", "title", "w1", "description", "w1", "popularity", "3"));+ assertU(adoc("id", "4", "title", "w1", "description", "w1", "popularity", "4"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));+ assertU(adoc("id", "6", "title", "w6 w2", "description", "w1 w2", "popularity", "6"));+ assertU(+ adoc(+ "id",+ "7",+ "title",+ "w1 w2 w3 w4 w5",+ "description",+ "w6 w2 w3 w4 w5 w8",+ "popularity",+ "88888"));+ assertU(+ adoc(+ "id",+ "8",+ "title",+ "w1 w1 w1 w2 w2 w8",+ "description",+ "w1 w1 w1 w2 w2",+ "popularity",+ "88888"));assertU(commit());}@@ -56,11 +75,13 @@ public class TestFilterSolrFeature extends TestRerankBase {@Testpublic void testUserTermScoreWithFQ() throws Exception {- loadFeature("SomeTermFQ", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=popularity}88888\"]}");- loadFeature("SomeEfiFQ", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=title}${user_query}\"]}");- loadModel("Term-modelFQ", LinearModel.class.getName(),+ loadFeature(+ "SomeTermFQ", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=popularity}88888\"]}");+ loadFeature(+ "SomeEfiFQ", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=title}${user_query}\"]}");+ loadModel(+ "Term-modelFQ",+ LinearModel.class.getName(),new String[] {"SomeTermFQ", "SomeEfiFQ"},"{\"weights\":{\"SomeTermFQ\":1.6, \"SomeEfiFQ\":2.0}}");final SolrQuery query = new SolrQuery();@@ -68,8 +89,7 @@ public class TestFilterSolrFeature extends TestRerankBase {query.add("fl", "*, score");query.add("rows", "3");query.add("fq", "{!terms f=title}w1");- query.add("rq",- "{!ltr model=Term-modelFQ reRankDocs=5 efi.user_query='w5'}");+ query.add("rq", "{!ltr model=Term-modelFQ reRankDocs=5 efi.user_query='w5'}");assertJQ("/query" + query.toQueryString(), "/response/numFound/==5");assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==3.6");@@ -79,10 +99,9 @@ public class TestFilterSolrFeature extends TestRerankBase {@Testpublic void testBadFeature() throws Exception {// Missing q/fq- final String feature = getFeatureInJson("badFeature", "test",- SolrFeature.class.getName(), "{\"df\":\"foo\"]}");- assertJPut(ManagedFeatureStore.REST_END_POINT, feature,- "/responseHeader/status==500");+ final String feature =+ getFeatureInJson("badFeature", "test", SolrFeature.class.getName(), "{\"df\":\"foo\"]}");+ assertJPut(ManagedFeatureStore.REST_END_POINT, feature, "/responseHeader/status==500");}@Test@@ -97,13 +116,12 @@ public class TestFilterSolrFeature extends TestRerankBase {query.add("rq", "{!ltr reRankDocs=4 model=fqmodel efi.user_query=w2}");query.add("fl", "fv:[fv]");- final String docs0fv_csv= FeatureLoggerTestUtils.toFeatureVector(- "matchedTitle","1.0", "popularity","3.0");+ final String docs0fv_csv =+ FeatureLoggerTestUtils.toFeatureVector("matchedTitle", "1.0", "popularity", "3.0");assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='2'");assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='1'");assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='3'");- assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fv=='"+docs0fv_csv+"'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fv=='" + docs0fv_csv + "'");}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestNoMatchSolrFeature.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestNoMatchSolrFeature.javaindex 052733e74ca..03c1121cc85 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestNoMatchSolrFeature.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestNoMatchSolrFeature.java@@ -18,7 +18,6 @@ package org.apache.solr.ltr.feature;import java.util.ArrayList;import java.util.Map;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.common.util.Utils;import org.apache.solr.ltr.FeatureLoggerTestUtils;@@ -35,29 +34,51 @@ public class TestNoMatchSolrFeature extends TestRerankBase {public void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",- "1"));- assertU(adoc("id", "2", "title", "w2 2asd asdd didid", "description",- "w2 2asd asdd didid", "popularity", "2"));- assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity",- "3"));- assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity",- "4"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity",- "5"));- assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2",- "popularity", "6"));- assertU(adoc("id", "7", "title", "w1 w2 w3 w4 w5", "description",- "w1 w2 w3 w4 w5 w8", "popularity", "7"));- assertU(adoc("id", "8", "title", "w1 w1 w1 w2 w2 w8", "description",- "w1 w1 w1 w2 w2", "popularity", "8"));+ assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity", "1"));+ assertU(+ adoc(+ "id",+ "2",+ "title",+ "w2 2asd asdd didid",+ "description",+ "w2 2asd asdd didid",+ "popularity",+ "2"));+ assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));+ assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity", "4"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));+ assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2", "popularity", "6"));+ assertU(+ adoc(+ "id",+ "7",+ "title",+ "w1 w2 w3 w4 w5",+ "description",+ "w1 w2 w3 w4 w5 w8",+ "popularity",+ "7"));+ assertU(+ adoc(+ "id",+ "8",+ "title",+ "w1 w1 w1 w2 w2 w8",+ "description",+ "w1 w1 w1 w2 w2",+ "popularity",+ "8"));assertU(commit());- loadFeature("nomatchfeature", SolrFeature.class.getName(),+ loadFeature(+ "nomatchfeature",+ SolrFeature.class.getName(),"{\"q\":\"foobarbat12345\",\"df\":\"title\"}");- loadFeature("yesmatchfeature", SolrFeature.class.getName(),- "{\"q\":\"w1\",\"df\":\"title\"}");- loadFeature("nomatchfeature2", SolrFeature.class.getName(),+ loadFeature("yesmatchfeature", SolrFeature.class.getName(), "{\"q\":\"w1\",\"df\":\"title\"}");+ loadFeature(+ "nomatchfeature2",+ SolrFeature.class.getName(),"{\"q\":\"foobarbat12345\",\"df\":\"title\"}");loadModel("nomatchmodel",@@ -65,16 +86,26 @@ public class TestNoMatchSolrFeature extends TestRerankBase {new String[] {"nomatchfeature", "yesmatchfeature", "nomatchfeature2"},"{\"weights\":{\"nomatchfeature\":1.0,\"yesmatchfeature\":1.1,\"nomatchfeature2\":1.1}}");- loadFeature("nomatchfeature3", SolrFeature.class.getName(),+ loadFeature(+ "nomatchfeature3",+ SolrFeature.class.getName(),"{\"q\":\"foobarbat12345\",\"df\":\"title\"}");- loadModel("nomatchmodel2", LinearModel.class.getName(),+ loadModel(+ "nomatchmodel2",+ LinearModel.class.getName(),new String[] {"nomatchfeature3"},"{\"weights\":{\"nomatchfeature3\":1.0}}");- loadFeature("nomatchfeature4", SolrFeature.class.getName(),- "noMatchFeaturesStore", "{\"q\":\"foobarbat12345\",\"df\":\"title\"}");- loadModel("nomatchmodel3", LinearModel.class.getName(),- new String[] {"nomatchfeature4"}, "noMatchFeaturesStore",+ loadFeature(+ "nomatchfeature4",+ SolrFeature.class.getName(),+ "noMatchFeaturesStore",+ "{\"q\":\"foobarbat12345\",\"df\":\"title\"}");+ loadModel(+ "nomatchmodel3",+ LinearModel.class.getName(),+ new String[] {"nomatchfeature4"},+ "noMatchFeaturesStore","{\"weights\":{\"nomatchfeature4\":1.0}}");}@@ -84,7 +115,8 @@ public class TestNoMatchSolrFeature extends TestRerankBase {}@Test- public void test2NoMatch1YesMatchFeatureReturnsFvWith1FeatureAndDocScoreScaledByModel() throws Exception {+ public void test2NoMatch1YesMatchFeatureReturnsFvWith1FeatureAndDocScoreScaledByModel()+ throws Exception {// Tests model with all no matching features but 1final SolrQuery query = new SolrQuery();query.setQuery("*:*");@@ -97,63 +129,78 @@ public class TestNoMatchSolrFeature extends TestRerankBase {yesMatchFeatureQuery.setQuery("title:w1");yesMatchFeatureQuery.add("fl", "score");yesMatchFeatureQuery.add("rows", "4");- String res = restTestHarness.query("/query"- + yesMatchFeatureQuery.toQueryString());+ String res = restTestHarness.query("/query" + yesMatchFeatureQuery.toQueryString());@SuppressWarnings({"unchecked"})- final Map<String,Object> jsonParse = (Map<String,Object>) Utils- .fromJSONString(res);+ final Map<String, Object> jsonParse = (Map<String, Object>) Utils.fromJSONString(res);@SuppressWarnings({"unchecked"})- final Double doc0Score = (Double) ((Map<String,Object>) ((ArrayList<Object>) ((Map<String,Object>) jsonParse- .get("response")).get("docs")).get(0)).get("score");-- final String docs0fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "nomatchfeature","0.0",- "yesmatchfeature",doc0Score.toString(),- "nomatchfeature2","0.0");- final String docs1fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "nomatchfeature","0.0",- "yesmatchfeature","0.0",- "nomatchfeature2","0.0");- final String docs2fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "nomatchfeature","0.0",- "yesmatchfeature","0.0",- "nomatchfeature2","0.0");- final String docs3fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "nomatchfeature","0.0",- "yesmatchfeature","0.0",- "nomatchfeature2","0.0");-- final String docs0fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector(- "yesmatchfeature",doc0Score.toString());+ final Double doc0Score =+ (Double)+ ((Map<String, Object>)+ ((ArrayList<Object>)+ ((Map<String, Object>) jsonParse.get("response")).get("docs"))+ .get(0))+ .get("score");++ final String docs0fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "nomatchfeature", "0.0",+ "yesmatchfeature", doc0Score.toString(),+ "nomatchfeature2", "0.0");+ final String docs1fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "nomatchfeature", "0.0",+ "yesmatchfeature", "0.0",+ "nomatchfeature2", "0.0");+ final String docs2fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "nomatchfeature", "0.0",+ "yesmatchfeature", "0.0",+ "nomatchfeature2", "0.0");+ final String docs3fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "nomatchfeature", "0.0",+ "yesmatchfeature", "0.0",+ "nomatchfeature2", "0.0");++ final String docs0fv_sparse_csv =+ FeatureLoggerTestUtils.toFeatureVector("yesmatchfeature", doc0Score.toString());final String docs1fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector();final String docs2fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector();final String docs3fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector();- final String docs0fv_default_csv = chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);- final String docs1fv_default_csv = chooseDefaultFeatureVector(docs1fv_dense_csv, docs1fv_sparse_csv);- final String docs2fv_default_csv = chooseDefaultFeatureVector(docs2fv_dense_csv, docs2fv_sparse_csv);- final String docs3fv_default_csv = chooseDefaultFeatureVector(docs3fv_dense_csv, docs3fv_sparse_csv);+ final String docs0fv_default_csv =+ chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);+ final String docs1fv_default_csv =+ chooseDefaultFeatureVector(docs1fv_dense_csv, docs1fv_sparse_csv);+ final String docs2fv_default_csv =+ chooseDefaultFeatureVector(docs2fv_dense_csv, docs2fv_sparse_csv);+ final String docs3fv_default_csv =+ chooseDefaultFeatureVector(docs3fv_dense_csv, docs3fv_sparse_csv);assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='1'");- assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score=="- + (doc0Score * 1.1));- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/fv=='"+docs0fv_default_csv+"'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==" + (doc0Score * 1.1));+ assertJQ(+ "/query" + query.toQueryString(), "/response/docs/[0]/fv=='" + docs0fv_default_csv + "'");assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='2'");assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/score==0.0");- assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/fv=='"+docs1fv_default_csv+"'");+ assertJQ(+ "/query" + query.toQueryString(), "/response/docs/[1]/fv=='" + docs1fv_default_csv + "'");assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='3'");assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/score==0.0");- assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/fv=='"+docs2fv_default_csv+"'");+ assertJQ(+ "/query" + query.toQueryString(), "/response/docs/[2]/fv=='" + docs2fv_default_csv + "'");assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='4'");assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/score==0.0");- assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/fv=='"+docs3fv_default_csv+"'");+ assertJQ(+ "/query" + query.toQueryString(), "/response/docs/[3]/fv=='" + docs3fv_default_csv + "'");}@Test- public void test1NoMatchFeatureReturnsFvWith1MatchingFeatureFromStoreAndDocWith0Score() throws Exception {- // Tests model with all no matching features, but 1 feature store feature matching for extraction+ public void test1NoMatchFeatureReturnsFvWith1MatchingFeatureFromStoreAndDocWith0Score()+ throws Exception {+ // Tests model with all no matching features, but 1 feature store feature matching for+ // extractionfinal SolrQuery query = new SolrQuery();query.setQuery("*:*");query.add("fl", "*, score,fv:[fv]");@@ -164,57 +211,71 @@ public class TestNoMatchSolrFeature extends TestRerankBase {yesMatchFeatureQuery.setQuery("title:w1");yesMatchFeatureQuery.add("fl", "score");yesMatchFeatureQuery.add("rows", "4");- String res = restTestHarness.query("/query"- + yesMatchFeatureQuery.toQueryString());+ String res = restTestHarness.query("/query" + yesMatchFeatureQuery.toQueryString());@SuppressWarnings({"unchecked"})- final Map<String,Object> jsonParse = (Map<String,Object>) Utils- .fromJSONString(res);+ final Map<String, Object> jsonParse = (Map<String, Object>) Utils.fromJSONString(res);@SuppressWarnings({"unchecked"})- final Double doc0Score = (Double) ((Map<String,Object>) ((ArrayList<Object>) ((Map<String,Object>) jsonParse- .get("response")).get("docs")).get(0)).get("score");-- final String docs0fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "nomatchfeature","0.0",- "yesmatchfeature",doc0Score.toString(),- "nomatchfeature2","0.0",- "nomatchfeature3","0.0");- final String docs1fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "nomatchfeature","0.0",- "yesmatchfeature","0.0",- "nomatchfeature2","0.0",- "nomatchfeature3","0.0");- final String docs2fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "nomatchfeature","0.0",- "yesmatchfeature","0.0",- "nomatchfeature2","0.0",- "nomatchfeature3","0.0");- final String docs3fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "nomatchfeature","0.0",- "yesmatchfeature","0.0",- "nomatchfeature2","0.0",- "nomatchfeature3","0.0");-- final String docs0fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector(- "yesmatchfeature",doc0Score.toString());+ final Double doc0Score =+ (Double)+ ((Map<String, Object>)+ ((ArrayList<Object>)+ ((Map<String, Object>) jsonParse.get("response")).get("docs"))+ .get(0))+ .get("score");++ final String docs0fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "nomatchfeature", "0.0",+ "yesmatchfeature", doc0Score.toString(),+ "nomatchfeature2", "0.0",+ "nomatchfeature3", "0.0");+ final String docs1fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "nomatchfeature", "0.0",+ "yesmatchfeature", "0.0",+ "nomatchfeature2", "0.0",+ "nomatchfeature3", "0.0");+ final String docs2fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "nomatchfeature", "0.0",+ "yesmatchfeature", "0.0",+ "nomatchfeature2", "0.0",+ "nomatchfeature3", "0.0");+ final String docs3fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector(+ "nomatchfeature", "0.0",+ "yesmatchfeature", "0.0",+ "nomatchfeature2", "0.0",+ "nomatchfeature3", "0.0");++ final String docs0fv_sparse_csv =+ FeatureLoggerTestUtils.toFeatureVector("yesmatchfeature", doc0Score.toString());final String docs1fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector();final String docs2fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector();final String docs3fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector();- final String docs0fv_default_csv = chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);- final String docs1fv_default_csv = chooseDefaultFeatureVector(docs1fv_dense_csv, docs1fv_sparse_csv);- final String docs2fv_default_csv = chooseDefaultFeatureVector(docs2fv_dense_csv, docs2fv_sparse_csv);- final String docs3fv_default_csv = chooseDefaultFeatureVector(docs3fv_dense_csv, docs3fv_sparse_csv);+ final String docs0fv_default_csv =+ chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);+ final String docs1fv_default_csv =+ chooseDefaultFeatureVector(docs1fv_dense_csv, docs1fv_sparse_csv);+ final String docs2fv_default_csv =+ chooseDefaultFeatureVector(docs2fv_dense_csv, docs2fv_sparse_csv);+ final String docs3fv_default_csv =+ chooseDefaultFeatureVector(docs3fv_dense_csv, docs3fv_sparse_csv);assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==0.0");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/fv=='"+docs0fv_default_csv+"'");+ assertJQ(+ "/query" + query.toQueryString(), "/response/docs/[0]/fv=='" + docs0fv_default_csv + "'");assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/score==0.0");- assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/fv=='"+docs1fv_default_csv+"'");+ assertJQ(+ "/query" + query.toQueryString(), "/response/docs/[1]/fv=='" + docs1fv_default_csv + "'");assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/score==0.0");- assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/fv=='"+docs2fv_default_csv+"'");+ assertJQ(+ "/query" + query.toQueryString(), "/response/docs/[2]/fv=='" + docs2fv_default_csv + "'");assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/score==0.0");- assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/fv=='"+docs3fv_default_csv+"'");+ assertJQ(+ "/query" + query.toQueryString(), "/response/docs/[3]/fv=='" + docs3fv_default_csv + "'");}@Test@@ -227,14 +288,16 @@ public class TestNoMatchSolrFeature extends TestRerankBase {query.add("fv", "true");query.add("rq", "{!ltr model=nomatchmodel3 reRankDocs=4}");- final String docs0fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "nomatchfeature4","0.0");+ final String docs0fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector("nomatchfeature4", "0.0");final String docs0fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector();- final String docs0fv_default_csv = chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);+ final String docs0fv_default_csv =+ chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==0.0");- assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fv=='"+docs0fv_default_csv+"'");+ assertJQ(+ "/query" + query.toQueryString(), "/response/docs/[0]/fv=='" + docs0fv_default_csv + "'");}@Test@@ -254,15 +317,15 @@ public class TestNoMatchSolrFeature extends TestRerankBase {query.add("rows", "4");query.add("rq", "{!ltr model=nomatchmodel4 reRankDocs=4}");- final String docs0fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector(- "nomatchfeature4","0.0");+ final String docs0fv_dense_csv =+ FeatureLoggerTestUtils.toFeatureVector("nomatchfeature4", "0.0");final String docs0fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector();- final String docs0fv_default_csv = chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);+ final String docs0fv_default_csv =+ chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/score==0.0");- assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fv=='"+docs0fv_default_csv+"'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==0.0");+ assertJQ(+ "/query" + query.toQueryString(), "/response/docs/[0]/fv=='" + docs0fv_default_csv + "'");}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestOriginalScoreFeature.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestOriginalScoreFeature.javaindex 0a482ff295d..7d046e0c499 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestOriginalScoreFeature.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestOriginalScoreFeature.java@@ -19,7 +19,6 @@ package org.apache.solr.ltr.feature;import java.util.ArrayList;import java.util.LinkedHashMap;import java.util.Map;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.util.Utils;@@ -55,29 +54,36 @@ public class TestOriginalScoreFeature extends TestRerankBase {@Testpublic void testOriginalScore() throws Exception {loadFeature("score", OriginalScoreFeature.class.getName(), "{}");- loadModel("originalScore", LinearModel.class.getName(),- new String[] {"score"}, "{\"weights\":{\"score\":1.0}}");+ loadModel(+ "originalScore",+ LinearModel.class.getName(),+ new String[] {"score"},+ "{\"weights\":{\"score\":1.0}}");implTestOriginalScoreResponseDocsCheck("originalScore", "score", null, null);}@Testpublic void testOriginalScoreWithNonScoringFeatures() throws Exception {- loadFeature("origScore", OriginalScoreFeature.class.getName(),- "store2", "{}");- loadFeature("c2", ValueFeature.class.getName(), "store2",- "{\"value\":2.0}");-- loadModel("origScore", LinearModel.class.getName(),- new String[] {"origScore"}, "store2",+ loadFeature("origScore", OriginalScoreFeature.class.getName(), "store2", "{}");+ loadFeature("c2", ValueFeature.class.getName(), "store2", "{\"value\":2.0}");++ loadModel(+ "origScore",+ LinearModel.class.getName(),+ new String[] {"origScore"},+ "store2","{\"weights\":{\"origScore\":1.0}}");implTestOriginalScoreResponseDocsCheck("origScore", "origScore", "c2", "2.0");}- public static void implTestOriginalScoreResponseDocsCheck(String modelName,+ public static void implTestOriginalScoreResponseDocsCheck(+ String modelName,String origScoreFeatureName,- String nonScoringFeatureName, String nonScoringFeatureValue) throws Exception {+ String nonScoringFeatureName,+ String nonScoringFeatureValue)+ throws Exception {final SolrQuery query = new SolrQuery();query.setQuery("title:w1");@@ -91,28 +97,51 @@ public class TestOriginalScoreFeature extends TestRerankBase {final int doc3Id = 7;assertJQ("/query" + query.toQueryString(), "/response/numFound/==4");- assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='"+doc0Id+"'");- assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='"+doc1Id+"'");- assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='"+doc2Id+"'");- assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='"+doc3Id+"'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='" + doc0Id + "'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='" + doc1Id + "'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='" + doc2Id + "'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='" + doc3Id + "'");final String res = restTestHarness.query("/query" + query.toQueryString());@SuppressWarnings({"unchecked"})- final Map<String,Object> jsonParse = (Map<String,Object>) Utils- .fromJSONString (res);+ final Map<String, Object> jsonParse = (Map<String, Object>) Utils.fromJSONString(res);@SuppressWarnings({"unchecked"})- final String doc0Score = ((Double) ((Map<String,Object>) ((ArrayList<Object>) ((Map<String,Object>) jsonParse- .get("response")).get("docs")).get(0)).get("score")).toString();+ final String doc0Score =+ ((Double)+ ((Map<String, Object>)+ ((ArrayList<Object>)+ ((Map<String, Object>) jsonParse.get("response")).get("docs"))+ .get(0))+ .get("score"))+ .toString();@SuppressWarnings({"unchecked"})- final String doc1Score = ((Double) ((Map<String,Object>) ((ArrayList<Object>) ((Map<String,Object>) jsonParse- .get("response")).get("docs")).get(1)).get("score")).toString();+ final String doc1Score =+ ((Double)+ ((Map<String, Object>)+ ((ArrayList<Object>)+ ((Map<String, Object>) jsonParse.get("response")).get("docs"))+ .get(1))+ .get("score"))+ .toString();@SuppressWarnings({"unchecked"})- final String doc2Score = ((Double) ((Map<String,Object>) ((ArrayList<Object>) ((Map<String,Object>) jsonParse- .get("response")).get("docs")).get(2)).get("score")).toString();+ final String doc2Score =+ ((Double)+ ((Map<String, Object>)+ ((ArrayList<Object>)+ ((Map<String, Object>) jsonParse.get("response")).get("docs"))+ .get(2))+ .get("score"))+ .toString();@SuppressWarnings({"unchecked"})- final String doc3Score = ((Double) ((Map<String,Object>) ((ArrayList<Object>) ((Map<String,Object>) jsonParse- .get("response")).get("docs")).get(3)).get("score")).toString();+ final String doc3Score =+ ((Double)+ ((Map<String, Object>)+ ((ArrayList<Object>)+ ((Map<String, Object>) jsonParse.get("response")).get("docs"))+ .get(3))+ .get("score"))+ .toString();final boolean debugQuery = random().nextBoolean();if (debugQuery) {@@ -121,48 +150,105 @@ public class TestOriginalScoreFeature extends TestRerankBase {query.remove("fl");query.add("fl", "*, score, fv:[fv]");- query.add("rq", "{!ltr model="+modelName+" reRankDocs=4}");+ query.add("rq", "{!ltr model=" + modelName + " reRankDocs=4}");assertJQ("/query" + query.toQueryString(), "/response/numFound/==4");- assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='"+doc0Id+"'");- assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='"+doc1Id+"'");- assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='"+doc2Id+"'");- assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='"+doc3Id+"'");-- implTestOriginalScoreResponseDocsCheck(modelName, query, 0, doc0Id, origScoreFeatureName, doc0Score,- nonScoringFeatureName, nonScoringFeatureValue, debugQuery);- implTestOriginalScoreResponseDocsCheck(modelName, query, 1, doc1Id, origScoreFeatureName, doc1Score,- nonScoringFeatureName, nonScoringFeatureValue, debugQuery);- implTestOriginalScoreResponseDocsCheck(modelName, query, 2, doc2Id, origScoreFeatureName, doc2Score,- nonScoringFeatureName, nonScoringFeatureValue, debugQuery);- implTestOriginalScoreResponseDocsCheck(modelName, query, 3, doc3Id, origScoreFeatureName, doc3Score,- nonScoringFeatureName, nonScoringFeatureValue, debugQuery);+ assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='" + doc0Id + "'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='" + doc1Id + "'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='" + doc2Id + "'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='" + doc3Id + "'");++ implTestOriginalScoreResponseDocsCheck(+ modelName,+ query,+ 0,+ doc0Id,+ origScoreFeatureName,+ doc0Score,+ nonScoringFeatureName,+ nonScoringFeatureValue,+ debugQuery);+ implTestOriginalScoreResponseDocsCheck(+ modelName,+ query,+ 1,+ doc1Id,+ origScoreFeatureName,+ doc1Score,+ nonScoringFeatureName,+ nonScoringFeatureValue,+ debugQuery);+ implTestOriginalScoreResponseDocsCheck(+ modelName,+ query,+ 2,+ doc2Id,+ origScoreFeatureName,+ doc2Score,+ nonScoringFeatureName,+ nonScoringFeatureValue,+ debugQuery);+ implTestOriginalScoreResponseDocsCheck(+ modelName,+ query,+ 3,+ doc3Id,+ origScoreFeatureName,+ doc3Score,+ nonScoringFeatureName,+ nonScoringFeatureValue,+ debugQuery);}- private static void implTestOriginalScoreResponseDocsCheck(String modelName,- SolrQuery query, int docIdx, int docId,- String origScoreFeatureName, String origScoreFeatureValue,- String nonScoringFeatureName, String nonScoringFeatureValue,- boolean debugQuery) throws Exception {+ private static void implTestOriginalScoreResponseDocsCheck(+ String modelName,+ SolrQuery query,+ int docIdx,+ int docId,+ String origScoreFeatureName,+ String origScoreFeatureValue,+ String nonScoringFeatureName,+ String nonScoringFeatureValue,+ boolean debugQuery)+ throws Exception {final String fv;if (nonScoringFeatureName == null) {fv = FeatureLoggerTestUtils.toFeatureVector(origScoreFeatureName, origScoreFeatureValue);} else {- fv = FeatureLoggerTestUtils.toFeatureVector(origScoreFeatureName, origScoreFeatureValue, nonScoringFeatureName, nonScoringFeatureValue);+ fv =+ FeatureLoggerTestUtils.toFeatureVector(+ origScoreFeatureName,+ origScoreFeatureValue,+ nonScoringFeatureName,+ nonScoringFeatureValue);}- assertJQ("/query" + query.toQueryString(), "/response/docs/["+docIdx+"]/fv=='"+fv+"'");+ assertJQ("/query" + query.toQueryString(), "/response/docs/[" + docIdx + "]/fv=='" + fv + "'");if (debugQuery) {- assertJQ("/query" + query.toQueryString(),- "/debug/explain/"+docId+"=='\n"+origScoreFeatureValue+" = LinearModel(name="+modelName+",featureWeights=["+origScoreFeatureName+"=1.0]) model applied to features, sum of:\n "+origScoreFeatureValue+" = prod of:\n 1.0 = weight on feature\n "+origScoreFeatureValue+" = OriginalScoreFeature [query:"+query.getQuery()+"]\n'");+ assertJQ(+ "/query" + query.toQueryString(),+ "/debug/explain/"+ + docId+ + "=='\n"+ + origScoreFeatureValue+ + " = LinearModel(name="+ + modelName+ + ",featureWeights=["+ + origScoreFeatureName+ + "=1.0]) model applied to features, sum of:\n "+ + origScoreFeatureValue+ + " = prod of:\n 1.0 = weight on feature\n "+ + origScoreFeatureValue+ + " = OriginalScoreFeature [query:"+ + query.getQuery()+ + "]\n'");}}@Testpublic void testParamsToMap() throws Exception {- final LinkedHashMap<String,Object> params = new LinkedHashMap<String,Object>();+ final LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();doTestParamsToMap(OriginalScoreFeature.class.getName(), params);}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestRankingFeature.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestRankingFeature.javaindex eab96105684..b47929fbf27 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestRankingFeature.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestRankingFeature.java@@ -17,7 +17,6 @@package org.apache.solr.ltr.feature;import java.util.LinkedHashMap;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;@@ -25,29 +24,47 @@ import org.junit.After;import org.junit.Before;import org.junit.Test;-public class TestRankingFeature extends TestRerankBase {@Beforepublic void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",- "1"));- assertU(adoc("id", "2", "title", "w2 2asd asdd didid", "description",- "w2 2asd asdd didid", "popularity", "2"));- assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity",- "3"));- assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity",- "4"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity",- "5"));- assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2",- "popularity", "6"));- assertU(adoc("id", "7", "title", "w1 w2 w3 w4 w5", "description",- "w1 w2 w3 w4 w5 w8", "popularity", "7"));- assertU(adoc("id", "8", "title", "w1 w1 w1 w2 w2 w8", "description",- "w1 w1 w1 w2 w2", "popularity", "8"));+ assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity", "1"));+ assertU(+ adoc(+ "id",+ "2",+ "title",+ "w2 2asd asdd didid",+ "description",+ "w2 2asd asdd didid",+ "popularity",+ "2"));+ assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));+ assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity", "4"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));+ assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2", "popularity", "6"));+ assertU(+ adoc(+ "id",+ "7",+ "title",+ "w1 w2 w3 w4 w5",+ "description",+ "w1 w2 w3 w4 w5 w8",+ "popularity",+ "7"));+ assertU(+ adoc(+ "id",+ "8",+ "title",+ "w1 w1 w1 w2 w2 w8",+ "description",+ "w1 w1 w1 w2 w2",+ "popularity",+ "8"));assertU(commit());}@@ -59,15 +76,21 @@ public class TestRankingFeature extends TestRerankBase {@Testpublic void testRankingSolrFeature() throws Exception {// before();- loadFeature("powpularityS", SolrFeature.class.getName(),- "{\"q\":\"{!func}pow(popularity,2)\"}");- loadFeature("unpopularityS", SolrFeature.class.getName(),- "{\"q\":\"{!func}div(1,popularity)\"}");-- loadModel("powpularityS-model", LinearModel.class.getName(),- new String[] {"powpularityS"}, "{\"weights\":{\"powpularityS\":1.0}}");- loadModel("unpopularityS-model", LinearModel.class.getName(),- new String[] {"unpopularityS"}, "{\"weights\":{\"unpopularityS\":1.0}}");+ loadFeature(+ "powpularityS", SolrFeature.class.getName(), "{\"q\":\"{!func}pow(popularity,2)\"}");+ loadFeature(+ "unpopularityS", SolrFeature.class.getName(), "{\"q\":\"{!func}div(1,popularity)\"}");++ loadModel(+ "powpularityS-model",+ LinearModel.class.getName(),+ new String[] {"powpularityS"},+ "{\"weights\":{\"powpularityS\":1.0}}");+ loadModel(+ "unpopularityS-model",+ LinearModel.class.getName(),+ new String[] {"unpopularityS"},+ "{\"weights\":{\"unpopularityS\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:w1");@@ -105,27 +128,30 @@ public class TestRankingFeature extends TestRerankBase {assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='7'");assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='8'");- //bad solr ranking feature- loadFeature("powdesS", SolrFeature.class.getName(),- "{\"q\":\"{!func}pow(description,2)\"}");- loadModel("powdesS-model", LinearModel.class.getName(),- new String[] {"powdesS"}, "{\"weights\":{\"powdesS\":1.0}}");+ // bad solr ranking feature+ loadFeature("powdesS", SolrFeature.class.getName(), "{\"q\":\"{!func}pow(description,2)\"}");+ loadModel(+ "powdesS-model",+ LinearModel.class.getName(),+ new String[] {"powdesS"},+ "{\"weights\":{\"powdesS\":1.0}}");query.remove("rq");query.add("rq", "{!ltr model=powdesS-model reRankDocs=4}");- assertJQ("/query" + query.toQueryString(),- "/error/msg/=='"+FeatureException.class.getName()+": " +- "java.lang.UnsupportedOperationException: " +- "Unable to extract feature for powdesS'");-+ assertJQ(+ "/query" + query.toQueryString(),+ "/error/msg/=='"+ + FeatureException.class.getName()+ + ": "+ + "java.lang.UnsupportedOperationException: "+ + "Unable to extract feature for powdesS'");}@Testpublic void testParamsToMap() throws Exception {- final LinkedHashMap<String,Object> params = new LinkedHashMap<String,Object>();+ final LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();params.put("q", "{!func}pow(popularity,2)");doTestParamsToMap(SolrFeature.class.getName(), params);}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScoreWithQ.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScoreWithQ.javaindex 9b7e7683d16..4a4b4c4105c 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScoreWithQ.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScoreWithQ.java@@ -29,22 +29,41 @@ public class TestUserTermScoreWithQ extends TestRerankBase {public void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",- "1"));- assertU(adoc("id", "2", "title", "w2 2asd asdd didid", "description",- "w2 2asd asdd didid", "popularity", "2"));- assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity",- "3"));- assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity",- "4"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity",- "5"));- assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2",- "popularity", "6"));- assertU(adoc("id", "7", "title", "w1 w2 w3 w4 w5", "description",- "w1 w2 w3 w4 w5 w8", "popularity", "7"));- assertU(adoc("id", "8", "title", "w1 w1 w1 w2 w2 w8", "description",- "w1 w1 w1 w2 w2", "popularity", "8"));+ assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity", "1"));+ assertU(+ adoc(+ "id",+ "2",+ "title",+ "w2 2asd asdd didid",+ "description",+ "w2 2asd asdd didid",+ "popularity",+ "2"));+ assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));+ assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity", "4"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));+ assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2", "popularity", "6"));+ assertU(+ adoc(+ "id",+ "7",+ "title",+ "w1 w2 w3 w4 w5",+ "description",+ "w1 w2 w3 w4 w5 w8",+ "popularity",+ "7"));+ assertU(+ adoc(+ "id",+ "8",+ "title",+ "w1 w1 w1 w2 w2 w8",+ "description",+ "w1 w1 w1 w2 w2",+ "popularity",+ "8"));assertU(commit());}@@ -56,10 +75,12 @@ public class TestUserTermScoreWithQ extends TestRerankBase {@Testpublic void testUserTermScoreWithQ() throws Exception {// before();- loadFeature("SomeTermQ", SolrFeature.class.getName(),- "{\"q\":\"{!terms f=popularity}88888\"}");- loadModel("Term-modelQ", LinearModel.class.getName(),- new String[] {"SomeTermQ"}, "{\"weights\":{\"SomeTermQ\":1.0}}");+ loadFeature("SomeTermQ", SolrFeature.class.getName(), "{\"q\":\"{!terms f=popularity}88888\"}");+ loadModel(+ "Term-modelQ",+ LinearModel.class.getName(),+ new String[] {"SomeTermQ"},+ "{\"weights\":{\"SomeTermQ\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:w1");query.add("fl", "*, score");diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorerQuery.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorerQuery.javaindex 3b6b93d6392..e6034fd683d 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorerQuery.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorerQuery.java@@ -23,28 +23,47 @@ import org.junit.After;import org.junit.Before;import org.junit.Test;-public class TestUserTermScorerQuery extends TestRerankBase {+public class TestUserTermScorerQuery extends TestRerankBase {@Beforepublic void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",- "1"));- assertU(adoc("id", "2", "title", "w2 2asd asdd didid", "description",- "w2 2asd asdd didid", "popularity", "2"));- assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity",- "3"));- assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity",- "4"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity",- "5"));- assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2",- "popularity", "6"));- assertU(adoc("id", "7", "title", "w1 w2 w3 w4 w5", "description",- "w1 w2 w3 w4 w5 w8", "popularity", "7"));- assertU(adoc("id", "8", "title", "w1 w1 w1 w2 w2 w8", "description",- "w1 w1 w1 w2 w2", "popularity", "8"));+ assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity", "1"));+ assertU(+ adoc(+ "id",+ "2",+ "title",+ "w2 2asd asdd didid",+ "description",+ "w2 2asd asdd didid",+ "popularity",+ "2"));+ assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));+ assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity", "4"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));+ assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2", "popularity", "6"));+ assertU(+ adoc(+ "id",+ "7",+ "title",+ "w1 w2 w3 w4 w5",+ "description",+ "w1 w2 w3 w4 w5 w8",+ "popularity",+ "7"));+ assertU(+ adoc(+ "id",+ "8",+ "title",+ "w1 w1 w1 w2 w2 w8",+ "description",+ "w1 w1 w1 w2 w2",+ "popularity",+ "8"));assertU(commit());}@@ -56,17 +75,20 @@ public class TestUserTermScorerQuery extends TestRerankBase {@Testpublic void testUserTermScorerQuery() throws Exception {// before();- loadFeature("matchedTitleDFExt", SolrFeature.class.getName(),+ loadFeature(+ "matchedTitleDFExt",+ SolrFeature.class.getName(),"{\"q\":\"${user_query}\",\"df\":\"title\"}");- loadModel("Term-matchedTitleDFExt", LinearModel.class.getName(),+ loadModel(+ "Term-matchedTitleDFExt",+ LinearModel.class.getName(),new String[] {"matchedTitleDFExt"},"{\"weights\":{\"matchedTitleDFExt\":1.1}}");final SolrQuery query = new SolrQuery();query.setQuery("title:w1");query.add("fl", "*, score");query.add("rows", "4");- query.add("rq",- "{!ltr model=Term-matchedTitleDFExt reRankDocs=4 efi.user_query=w8}");+ query.add("rq", "{!ltr model=Term-matchedTitleDFExt reRankDocs=4 efi.user_query=w8}");assertJQ("/query" + query.toQueryString(), "/response/numFound/==4");assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='8'");diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorereQDF.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorereQDF.javaindex b5882d5e8e2..08783690ff2 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorereQDF.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorereQDF.java@@ -29,22 +29,41 @@ public class TestUserTermScorereQDF extends TestRerankBase {public void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",- "1"));- assertU(adoc("id", "2", "title", "w2 2asd asdd didid", "description",- "w2 2asd asdd didid", "popularity", "2"));- assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity",- "3"));- assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity",- "4"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity",- "5"));- assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2",- "popularity", "6"));- assertU(adoc("id", "7", "title", "w1 w2 w3 w4 w5", "description",- "w1 w2 w3 w4 w5 w8", "popularity", "7"));- assertU(adoc("id", "8", "title", "w1 w1 w1 w2 w2 w8", "description",- "w1 w1 w1 w2 w2", "popularity", "8"));+ assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity", "1"));+ assertU(+ adoc(+ "id",+ "2",+ "title",+ "w2 2asd asdd didid",+ "description",+ "w2 2asd asdd didid",+ "popularity",+ "2"));+ assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));+ assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity", "4"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));+ assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2", "popularity", "6"));+ assertU(+ adoc(+ "id",+ "7",+ "title",+ "w1 w2 w3 w4 w5",+ "description",+ "w1 w2 w3 w4 w5 w8",+ "popularity",+ "7"));+ assertU(+ adoc(+ "id",+ "8",+ "title",+ "w1 w1 w1 w2 w2 w8",+ "description",+ "w1 w1 w1 w2 w2",+ "popularity",+ "8"));assertU(commit());}@@ -56,9 +75,10 @@ public class TestUserTermScorereQDF extends TestRerankBase {@Testpublic void testUserTermScorerQWithDF() throws Exception {// before();- loadFeature("matchedTitleDF", SolrFeature.class.getName(),- "{\"q\":\"w5\",\"df\":\"title\"}");- loadModel("Term-matchedTitleDF", LinearModel.class.getName(),+ loadFeature("matchedTitleDF", SolrFeature.class.getName(), "{\"q\":\"w5\",\"df\":\"title\"}");+ loadModel(+ "Term-matchedTitleDF",+ LinearModel.class.getName(),new String[] {"matchedTitleDF"},"{\"weights\":{\"matchedTitleDF\":1.0}}");final SolrQuery query = new SolrQuery();diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestValueFeature.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestValueFeature.javaindex 9bfdcdc948e..03e57c29008 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestValueFeature.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestValueFeature.java@@ -17,7 +17,6 @@package org.apache.solr.ltr.feature;import java.util.LinkedHashMap;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;@@ -57,10 +56,9 @@ public class TestValueFeature extends TestRerankBase {@Testpublic void testRerankingWithConstantValueFeatureReplacesDocScore() throws Exception {- loadFeature("c3", ValueFeature.class.getName(), "c3",- "{\"value\":2}");- loadModel("m3", LinearModel.class.getName(), new String[] {"c3"},- "c3", "{\"weights\":{\"c3\":1.0}}");+ loadFeature("c3", ValueFeature.class.getName(), "c3", "{\"value\":2}");+ loadModel(+ "m3", LinearModel.class.getName(), new String[] {"c3"}, "c3", "{\"weights\":{\"c3\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:w1");@@ -77,10 +75,9 @@ public class TestValueFeature extends TestRerankBase {@Testpublic void testRerankingWithEfiValueFeatureReplacesDocScore() throws Exception {- loadFeature("c6", ValueFeature.class.getName(), "c6",- "{\"value\":\"${val6}\"}");- loadModel("m6", LinearModel.class.getName(), new String[] {"c6"},- "c6", "{\"weights\":{\"c6\":1.0}}");+ loadFeature("c6", ValueFeature.class.getName(), "c6", "{\"value\":\"${val6}\"}");+ loadModel(+ "m6", LinearModel.class.getName(), new String[] {"c6"}, "c6", "{\"weights\":{\"c6\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:w1");@@ -95,13 +92,11 @@ public class TestValueFeature extends TestRerankBase {assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/score==2.0");}-@Testpublic void testValueFeatureImplicitlyNotRequiredShouldReturnOkStatusCode() throws Exception {- loadFeature("c5", ValueFeature.class.getName(), "c5",- "{\"value\":\"${val6}\"}");- loadModel("m5", LinearModel.class.getName(), new String[] {"c5"},- "c5", "{\"weights\":{\"c5\":1.0}}");+ loadFeature("c5", ValueFeature.class.getName(), "c5", "{\"value\":\"${val6}\"}");+ loadModel(+ "m5", LinearModel.class.getName(), new String[] {"c5"}, "c5", "{\"weights\":{\"c5\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:w1");@@ -115,10 +110,10 @@ public class TestValueFeature extends TestRerankBase {@Testpublic void testValueFeatureExplictlyNotRequiredShouldReturnOkStatusCode() throws Exception {- loadFeature("c7", ValueFeature.class.getName(), "c7",- "{\"value\":\"${val7}\",\"required\":false}");- loadModel("m7", LinearModel.class.getName(), new String[] {"c7"},- "c7", "{\"weights\":{\"c7\":1.0}}");+ loadFeature(+ "c7", ValueFeature.class.getName(), "c7", "{\"value\":\"${val7}\",\"required\":false}");+ loadModel(+ "m7", LinearModel.class.getName(), new String[] {"c7"}, "c7", "{\"weights\":{\"c7\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:w1");@@ -132,10 +127,10 @@ public class TestValueFeature extends TestRerankBase {@Testpublic void testValueFeatureRequiredShouldReturn400StatusCode() throws Exception {- loadFeature("c8", ValueFeature.class.getName(), "c8",- "{\"value\":\"${val8}\",\"required\":true}");- loadModel("m8", LinearModel.class.getName(), new String[] {"c8"},- "c8", "{\"weights\":{\"c8\":1.0}}");+ loadFeature(+ "c8", ValueFeature.class.getName(), "c8", "{\"value\":\"${val8}\",\"required\":true}");+ loadModel(+ "m8", LinearModel.class.getName(), new String[] {"c8"}, "c8", "{\"weights\":{\"c8\":1.0}}");final SolrQuery query = new SolrQuery();query.setQuery("title:w1");@@ -149,12 +144,11 @@ public class TestValueFeature extends TestRerankBase {@Testpublic void testParamsToMap() throws Exception {- final LinkedHashMap<String,Object> params = new LinkedHashMap<String,Object>();- params.put("value", "${val"+random().nextInt(10)+"}");+ final LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();+ params.put("value", "${val" + random().nextInt(10) + "}");if (random().nextBoolean()) {params.put("required", random().nextBoolean());}doTestParamsToMap(ValueFeature.class.getName(), params);}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/interleaving/TestLTRQParserInterleaving.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/interleaving/TestLTRQParserInterleaving.javaindex ebaeae1e1c3..ad30023663d 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/interleaving/TestLTRQParserInterleaving.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/interleaving/TestLTRQParserInterleaving.java@@ -17,7 +17,6 @@package org.apache.solr.ltr.interleaving;import java.util.Random;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.feature.SolrFeature;@@ -32,22 +31,41 @@ public class TestLTRQParserInterleaving extends TestRerankBase {public void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "w1", "description", "w5", "popularity",- "1"));- assertU(adoc("id", "2", "title", "w2 2asd asdd didid", "description",- "w2 2asd asdd didid", "popularity", "2"));- assertU(adoc("id", "3", "title", "w1", "description", "w5", "popularity",- "3"));- assertU(adoc("id", "4", "title", "w1", "description", "w1", "popularity",- "6"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity",- "5"));- assertU(adoc("id", "6", "title", "w6 w2", "description", "w1 w2",- "popularity", "6"));- assertU(adoc("id", "7", "title", "w1 w2 w3 w4 w5", "description",- "w6 w2 w3 w4 w5 w8", "popularity", "88888"));- assertU(adoc("id", "8", "title", "w1 w1 w1 w2 w2 w8", "description",- "w1 w1 w1 w2 w2 w5", "popularity", "88888"));+ assertU(adoc("id", "1", "title", "w1", "description", "w5", "popularity", "1"));+ assertU(+ adoc(+ "id",+ "2",+ "title",+ "w2 2asd asdd didid",+ "description",+ "w2 2asd asdd didid",+ "popularity",+ "2"));+ assertU(adoc("id", "3", "title", "w1", "description", "w5", "popularity", "3"));+ assertU(adoc("id", "4", "title", "w1", "description", "w1", "popularity", "6"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));+ assertU(adoc("id", "6", "title", "w6 w2", "description", "w1 w2", "popularity", "6"));+ assertU(+ adoc(+ "id",+ "7",+ "title",+ "w1 w2 w3 w4 w5",+ "description",+ "w6 w2 w3 w4 w5 w8",+ "popularity",+ "88888"));+ assertU(+ adoc(+ "id",+ "8",+ "title",+ "w1 w1 w1 w2 w2 w8",+ "description",+ "w1 w1 w1 w2 w2 w5",+ "popularity",+ "88888"));assertU(commit());loadFeaturesAndModelsForInterleaving();@@ -59,31 +77,45 @@ public class TestLTRQParserInterleaving extends TestRerankBase {}protected void loadFeaturesAndModelsForInterleaving() throws Exception {- loadFeature("featureA1", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=popularity}88888\"]}");- loadFeature("featureA2", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=title}${user_query}\"]}");- loadFeature("featureAB", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=title}${user_query}\"]}");- loadFeature("featureB1", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=popularity}6\"]}");- loadFeature("featureB2", SolrFeature.class.getName(),+ loadFeature(+ "featureA1", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=popularity}88888\"]}");+ loadFeature(+ "featureA2", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=title}${user_query}\"]}");+ loadFeature(+ "featureAB", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=title}${user_query}\"]}");+ loadFeature("featureB1", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=popularity}6\"]}");+ loadFeature(+ "featureB2",+ SolrFeature.class.getName(),"{\"fq\":[\"{!terms f=description}${user_query}\"]}");- loadFeature("featureC1", SolrFeature.class.getName(),"featureStore2",+ loadFeature(+ "featureC1",+ SolrFeature.class.getName(),+ "featureStore2","{\"fq\":[\"{!terms f=popularity}6\"]}");- loadFeature("featureC2", SolrFeature.class.getName(),"featureStore2",+ loadFeature(+ "featureC2",+ SolrFeature.class.getName(),+ "featureStore2","{\"fq\":[\"{!terms f=popularity}1\"]}");- loadModel("modelA", LinearModel.class.getName(),- new String[]{"featureA1", "featureA2", "featureAB"},+ loadModel(+ "modelA",+ LinearModel.class.getName(),+ new String[] {"featureA1", "featureA2", "featureAB"},"{\"weights\":{\"featureA1\":3.0, \"featureA2\":9.0, \"featureAB\":27.0}}");- loadModel("modelB", LinearModel.class.getName(),- new String[]{"featureB1", "featureB2", "featureAB"},+ loadModel(+ "modelB",+ LinearModel.class.getName(),+ new String[] {"featureB1", "featureB2", "featureAB"},"{\"weights\":{\"featureB1\":2.0, \"featureB2\":4.0, \"featureAB\":8.0}}");- loadModel("modelC", LinearModel.class.getName(),- new String[]{"featureC1", "featureC2"},"featureStore2",+ loadModel(+ "modelC",+ LinearModel.class.getName(),+ new String[] {"featureC1", "featureC2"},+ "featureStore2","{\"weights\":{\"featureC1\":5.0, \"featureC2\":25.0}}");}@@ -95,7 +127,8 @@ public class TestLTRQParserInterleaving extends TestRerankBase {query.add("fl", "*, score");query.add("rows", "4");query.add("fv", "true");- query.add("rq", "{!ltr model=modelA model=modelB interleavingAlgorithm=unsupported reRankDocs=100}");+ query.add(+ "rq", "{!ltr model=modelA model=modelB interleavingAlgorithm=unsupported reRankDocs=100}");final String res = restTestHarness.query("/query" + query.toQueryString());assert (res.contains("Unknown Interleaving algorithm: unsupported"));@@ -131,7 +164,8 @@ public class TestLTRQParserInterleaving extends TestRerankBase {@Testpublic void defaultAlgorithm_shouldApplyTeamDraftInterleaving() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]final SolrQuery query = new SolrQuery();query.setQuery("*:*");@@ -139,8 +173,7 @@ public class TestLTRQParserInterleaving extends TestRerankBase {query.add("rows", "10");query.add("debugQuery", "true");query.add("fq", "{!terms f=title}w1"); // 1,3,4,7,8- query.add("rq",- "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");+ query.add("rq", "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");/*Doc1 = "featureB2=1.0", ScoreA(0), ScoreB(4)@@ -150,25 +183,30 @@ public class TestLTRQParserInterleaving extends TestRerankBase {Doc8 = "featureA1=1.0,featureB2=1.0", ScoreA(3), ScoreB(4)ModelARerankedList = [7,8,1,3,4]ModelBRerankedList = [7,1,3,8,4]-+Random Boolean Choices Generation from Seed: [0,1,1]*/- String[] expectedInterleavingPicks = new String[]{"modelA", "modelB", "modelB", "modelA", "modelB"};- int[] expectedInterleaved = new int[]{7, 1, 3, 8, 4};+ String[] expectedInterleavingPicks =+ new String[] {"modelA", "modelB", "modelB", "modelA", "modelB"};+ int[] expectedInterleaved = new int[] {7, 1, 3, 8, 4};String[] tests = new String[11];tests[0] = "/response/numFound/==5";for (int i = 1; i <= 5; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 5] = "/response/docs/[" + (i - 1) + "]/interleavingPick==" + expectedInterleavingPicks[(i - 1)];+ tests[i + 5] =+ "/response/docs/["+ + (i - 1)+ + "]/interleavingPick=="+ + expectedInterleavingPicks[(i - 1)];}assertJQ("/query" + query.toQueryString(), tests);-}-+@Testpublic void teamDraftAlgorithm_shouldApplyTeamDraftInterleaving() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]final SolrQuery query = new SolrQuery();query.setQuery("*:*");@@ -176,7 +214,8 @@ public class TestLTRQParserInterleaving extends TestRerankBase {query.add("rows", "10");query.add("debugQuery", "true");query.add("fq", "{!terms f=title}w1"); // 1,3,4,7,8- query.add("rq",+ query.add(+ "rq","{!ltr model=modelA model=modelB reRankDocs=10 interleavingAlgorithm=TeamDraft efi.user_query='w5'}");/*@@ -187,20 +226,23 @@ public class TestLTRQParserInterleaving extends TestRerankBase {Doc8 = "featureA1=1.0,featureB2=1.0", ScoreA(3), ScoreB(4)ModelARerankedList = [7,8,1,3,4]ModelBRerankedList = [7,1,3,8,4]-+Random Boolean Choices Generation from Seed: [0,1,1]*/- String[] expectedInterleavingPicks = new String[]{"modelA", "modelB", "modelB", "modelA", "modelB"};- int[] expectedInterleaved = new int[]{7, 1, 3, 8, 4};+ String[] expectedInterleavingPicks =+ new String[] {"modelA", "modelB", "modelB", "modelA", "modelB"};+ int[] expectedInterleaved = new int[] {7, 1, 3, 8, 4};String[] tests = new String[11];tests[0] = "/response/numFound/==5";for (int i = 1; i <= 5; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 5] = "/response/docs/[" + (i - 1) + "]/interleavingPick==" + expectedInterleavingPicks[(i - 1)];+ tests[i + 5] =+ "/response/docs/["+ + (i - 1)+ + "]/interleavingPick=="+ + expectedInterleavingPicks[(i - 1)];}assertJQ("/query" + query.toQueryString(), tests);-}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/interleaving/algorithms/TeamDraftInterleavingTest.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/interleaving/algorithms/TeamDraftInterleavingTest.javaindex 0f484a5df76..e7cfe334167 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/interleaving/algorithms/TeamDraftInterleavingTest.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/interleaving/algorithms/TeamDraftInterleavingTest.java@@ -17,73 +17,67 @@package org.apache.solr.ltr.interleaving.algorithms;+import static org.hamcrest.CoreMatchers.is;+import static org.hamcrest.MatcherAssert.assertThat;+import static org.junit.Assert.assertTrue;import java.util.ArrayList;import java.util.Random;import java.util.Set;-import org.apache.lucene.search.ScoreDoc;import org.apache.solr.ltr.interleaving.InterleavingResult;import org.junit.Before;import org.junit.Test;-import static org.hamcrest.MatcherAssert.assertThat;-import static org.hamcrest.CoreMatchers.is;-import static org.junit.Assert.assertTrue;-public class TeamDraftInterleavingTest {private TeamDraftInterleaving toTest;- private ScoreDoc[] rerankedA,rerankedB;- private ScoreDoc a1,a2,a3,a4,a5;- private ScoreDoc b1,b2,b3,b4,b5;+ private ScoreDoc[] rerankedA, rerankedB;+ private ScoreDoc a1, a2, a3, a4, a5;+ private ScoreDoc b1, b2, b3, b4, b5;-@Beforepublic void setup() {toTest = new TeamDraftInterleaving();- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]}protected void initDifferentOrderRerankLists() {- a1 = new ScoreDoc(1,10,1);- a2 = new ScoreDoc(5,7,1);- a3 = new ScoreDoc(4,6,1);- a4 = new ScoreDoc(2,5,1);- a5 = new ScoreDoc(3,4,1);- rerankedA = new ScoreDoc[]{a1,a2,a3,a4,a5};-- b1 = new ScoreDoc(1,10,1);- b2 = new ScoreDoc(4,7,1);- b3 = new ScoreDoc(5,6,1);- b4 = new ScoreDoc(3,5,1);- b5 = new ScoreDoc(2,4,1);- rerankedB = new ScoreDoc[]{b1,b2,b3,b4,b5};+ a1 = new ScoreDoc(1, 10, 1);+ a2 = new ScoreDoc(5, 7, 1);+ a3 = new ScoreDoc(4, 6, 1);+ a4 = new ScoreDoc(2, 5, 1);+ a5 = new ScoreDoc(3, 4, 1);+ rerankedA = new ScoreDoc[] {a1, a2, a3, a4, a5};++ b1 = new ScoreDoc(1, 10, 1);+ b2 = new ScoreDoc(4, 7, 1);+ b3 = new ScoreDoc(5, 6, 1);+ b4 = new ScoreDoc(3, 5, 1);+ b5 = new ScoreDoc(2, 4, 1);+ rerankedB = new ScoreDoc[] {b1, b2, b3, b4, b5};}- /**- * Random Boolean Choices Generation from Seed: [0,1,1]- */+ /** Random Boolean Choices Generation from Seed: [0,1,1] */@Testpublic void interleaving_twoDifferentLists_shouldInterleaveTeamDraft() {initDifferentOrderRerankLists();InterleavingResult interleaved = toTest.interleave(rerankedA, rerankedB);ScoreDoc[] interleavedResults = interleaved.getInterleavedResults();-- assertThat(interleavedResults.length,is(5));-- assertThat(interleavedResults[0],is(a1));- assertThat(interleavedResults[1],is(b2));-- assertThat(interleavedResults[2],is(b3));- assertThat(interleavedResults[3],is(a4));-- assertThat(interleavedResults[4],is(b4));++ assertThat(interleavedResults.length, is(5));++ assertThat(interleavedResults[0], is(a1));+ assertThat(interleavedResults[1], is(b2));++ assertThat(interleavedResults[2], is(b3));+ assertThat(interleavedResults[3], is(a4));++ assertThat(interleavedResults[4], is(b4));}- /**- * Random Boolean Choices Generation from Seed: [0,1,1]- */+ /** Random Boolean Choices Generation from Seed: [0,1,1] */@Testpublic void interleaving_twoDifferentLists_shouldBuildCorrectInterleavingPicks() {initDifferentOrderRerankLists();@@ -94,8 +88,8 @@ public class TeamDraftInterleavingTest {Set<Integer> modelAPicks = interleavingPicks.get(0);Set<Integer> modelBPicks = interleavingPicks.get(1);- assertThat(modelAPicks.size(),is(2));- assertThat(modelBPicks.size(),is(3));+ assertThat(modelAPicks.size(), is(2));+ assertThat(modelBPicks.size(), is(3));assertTrue(modelAPicks.contains(a1.doc));assertTrue(modelAPicks.contains(a4.doc));@@ -106,24 +100,22 @@ public class TeamDraftInterleavingTest {}protected void initIdenticalOrderRerankLists() {- a1 = new ScoreDoc(1,10,1);- a2 = new ScoreDoc(5,7,1);- a3 = new ScoreDoc(4,6,1);- a4 = new ScoreDoc(2,5,1);- a5 = new ScoreDoc(3,4,1);- rerankedA = new ScoreDoc[]{a1,a2,a3,a4,a5};-- b1 = new ScoreDoc(1,10,1);- b2 = new ScoreDoc(5,7,1);- b3 = new ScoreDoc(4,6,1);- b4 = new ScoreDoc(2,5,1);- b5 = new ScoreDoc(3,4,1);- rerankedB = new ScoreDoc[]{b1,b2,b3,b4,b5};+ a1 = new ScoreDoc(1, 10, 1);+ a2 = new ScoreDoc(5, 7, 1);+ a3 = new ScoreDoc(4, 6, 1);+ a4 = new ScoreDoc(2, 5, 1);+ a5 = new ScoreDoc(3, 4, 1);+ rerankedA = new ScoreDoc[] {a1, a2, a3, a4, a5};++ b1 = new ScoreDoc(1, 10, 1);+ b2 = new ScoreDoc(5, 7, 1);+ b3 = new ScoreDoc(4, 6, 1);+ b4 = new ScoreDoc(2, 5, 1);+ b5 = new ScoreDoc(3, 4, 1);+ rerankedB = new ScoreDoc[] {b1, b2, b3, b4, b5};}- /**- * Random Boolean Choices Generation from Seed: [0,1,1]- */+ /** Random Boolean Choices Generation from Seed: [0,1,1] */@Testpublic void interleaving_identicalRerankLists_shouldInterleaveTeamDraft() {initIdenticalOrderRerankLists();@@ -131,20 +123,18 @@ public class TeamDraftInterleavingTest {InterleavingResult interleaved = toTest.interleave(rerankedA, rerankedB);ScoreDoc[] interleavedResults = interleaved.getInterleavedResults();- assertThat(interleavedResults.length,is(5));+ assertThat(interleavedResults.length, is(5));- assertThat(interleavedResults[0],is(a1));- assertThat(interleavedResults[1],is(b2));+ assertThat(interleavedResults[0], is(a1));+ assertThat(interleavedResults[1], is(b2));- assertThat(interleavedResults[2],is(b3));- assertThat(interleavedResults[3],is(a4));+ assertThat(interleavedResults[2], is(b3));+ assertThat(interleavedResults[3], is(a4));- assertThat(interleavedResults[4],is(b5));+ assertThat(interleavedResults[4], is(b5));}- /**- * Random Boolean Choices Generation from Seed: [0,1,1]- */+ /** Random Boolean Choices Generation from Seed: [0,1,1] */@Testpublic void interleaving_identicalRerankLists_shouldBuildCorrectInterleavingPicks() {initIdenticalOrderRerankLists();@@ -155,8 +145,8 @@ public class TeamDraftInterleavingTest {Set<Integer> modelAPicks = interleavingPicks.get(0);Set<Integer> modelBPicks = interleavingPicks.get(1);- assertThat(modelAPicks.size(),is(2));- assertThat(modelBPicks.size(),is(3));+ assertThat(modelAPicks.size(), is(2));+ assertThat(modelBPicks.size(), is(3));assertTrue(modelAPicks.contains(a1.doc));assertTrue(modelAPicks.contains(a4.doc));@@ -165,6 +155,4 @@ public class TeamDraftInterleavingTest {assertTrue(modelBPicks.contains(b3.doc));assertTrue(modelBPicks.contains(b5.doc));}-}-diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestAdapterModel.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestAdapterModel.javaindex b0f8b1f28fd..37426c1cc1a 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestAdapterModel.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestAdapterModel.java@@ -28,7 +28,6 @@ import java.io.OutputStreamWriter;import java.nio.charset.StandardCharsets;import java.util.List;import java.util.Map;-import org.apache.lucene.index.LeafReaderContext;import org.apache.lucene.search.Explanation;import org.apache.solr.client.solrj.SolrQuery;@@ -53,30 +52,34 @@ public class TestAdapterModel extends TestRerankBase {setuptest(false);numDocs = random().nextInt(10);- for (int ii=1; ii <= numDocs; ++ii) {+ for (int ii = 1; ii <= numDocs; ++ii) {String id = Integer.toString(ii);- assertU(adoc("id", id, "popularity", ii+"00"));+ assertU(adoc("id", id, "popularity", ii + "00"));}assertU(commit());- loadFeature("popularity", FieldValueFeature.class.getName(), "test", "{\"field\":\"popularity\"}");+ loadFeature(+ "popularity", FieldValueFeature.class.getName(), "test", "{\"field\":\"popularity\"}");scoreValue = random().nextFloat();final File scoreValueFile = new File(tmpConfDir, "scoreValue.txt");- try (BufferedWriter writer = new BufferedWriter(- new OutputStreamWriter(new FileOutputStream(scoreValueFile), StandardCharsets.UTF_8))) {+ try (BufferedWriter writer =+ new BufferedWriter(+ new OutputStreamWriter(new FileOutputStream(scoreValueFile), StandardCharsets.UTF_8))) {writer.write(Float.toString(scoreValue));}scoreValueFile.deleteOnExit();- final String modelJson = getModelInJson(- "answerModel",- CustomModel.class.getName(),- new String[] { "popularity" },- "test",- "{\"answerFileName\":\"" + scoreValueFile.getName() + "\"}");+ final String modelJson =+ getModelInJson(+ "answerModel",+ CustomModel.class.getName(),+ new String[] {"popularity"},+ "test",+ "{\"answerFileName\":\"" + scoreValueFile.getName() + "\"}");assertJPut(ManagedModelStore.REST_END_POINT, modelJson, "/responseHeader/status==0");}+@Afterpublic void cleanup() throws Exception {aftertest();@@ -84,14 +87,14 @@ public class TestAdapterModel extends TestRerankBase {@Testpublic void test() throws Exception {- final int rows = random().nextInt(numDocs+1); // 0..numDocs+ final int rows = random().nextInt(numDocs + 1); // 0..numDocsfinal SolrQuery query = new SolrQuery("*:*");query.setRows(rows);query.setFields("*,score");query.add("rq", "{!ltr model=answerModel}");final String[] tests = new String[rows];- for (int ii=0; ii<rows; ++ii) {- tests[ii] = "/response/docs/["+ii+"]/score=="+scoreValue;+ for (int ii = 0; ii < rows; ++ii) {+ tests[ii] = "/response/docs/[" + ii + "]/score==" + scoreValue;}assertJQ("/query" + query.toQueryString(), tests);}@@ -99,20 +102,23 @@ public class TestAdapterModel extends TestRerankBase {public static class CustomModel extends AdapterModel {/**- * answerFileName is part of the LTRScoringModel params map- * and therefore here it does not individually- * influence the class hashCode, equals, etc.+ * answerFileName is part of the LTRScoringModel params map and therefore here it does not+ * individually influence the class hashCode, equals, etc.*/private String answerFileName;/**- * answerValue is obtained from answerFileName- * and therefore here it does not individually+ * answerValue is obtained from answerFileName and therefore here it does not individually* influence the class hashCode, equals, etc.*/private float answerValue;- public CustomModel(String name, List<Feature> features, List<Normalizer> norms, String featureStoreName,- List<Feature> allFeatures, Map<String,Object> params) {+ public CustomModel(+ String name,+ List<Feature> features,+ List<Normalizer> norms,+ String featureStoreName,+ List<Feature> allFeatures,+ Map<String, Object> params) {super(name, features, norms, featureStoreName, allFeatures, params);}@@ -124,20 +130,20 @@ public class TestAdapterModel extends TestRerankBase {protected void validate() throws ModelException {super.validate();if (answerFileName == null) {- throw new ModelException("no answerFileName configured for model "+name);+ throw new ModelException("no answerFileName configured for model " + name);}}public void init(SolrResourceLoader solrResourceLoader) throws ModelException {super.init(solrResourceLoader);- try (- InputStream is = solrResourceLoader.openResource(answerFileName);+ try (InputStream is = solrResourceLoader.openResource(answerFileName);InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);- BufferedReader br = new BufferedReader(isr)- ) {+ BufferedReader br = new BufferedReader(isr)) {answerValue = Float.parseFloat(br.readLine());} catch (IOException e) {- throw new ModelException("Failed to get the answerValue from the given answerFileName (" + answerFileName + ")", e);+ throw new ModelException(+ "Failed to get the answerValue from the given answerFileName (" + answerFileName + ")",+ e);}}@@ -147,12 +153,13 @@ public class TestAdapterModel extends TestRerankBase {}@Override- public Explanation explain(LeafReaderContext context, int doc, float finalScore,+ public Explanation explain(+ LeafReaderContext context,+ int doc,+ float finalScore,List<Explanation> featureExplanations) {- return Explanation.match(finalScore, toString()- + " model, always returns "+Float.toString(answerValue)+".");+ return Explanation.match(+ finalScore, toString() + " model, always returns " + Float.toString(answerValue) + ".");}-}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestDefaultWrapperModel.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestDefaultWrapperModel.javaindex 00ed14d8ad5..4ded7d4a897 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestDefaultWrapperModel.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestDefaultWrapperModel.java@@ -24,7 +24,6 @@ import java.io.OutputStreamWriter;import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.List;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.feature.Feature;@@ -37,7 +36,7 @@ import org.junit.Test;public class TestDefaultWrapperModel extends TestRerankBase {- final private static String featureStoreName = "test";+ private static final String featureStoreName = "test";private static File baseModelFile = null;static List<Feature> features = null;@@ -52,25 +51,30 @@ public class TestDefaultWrapperModel extends TestRerankBase {assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));assertU(commit());- loadFeature("popularity", FieldValueFeature.class.getName(), "test", "{\"field\":\"popularity\"}");+ loadFeature(+ "popularity", FieldValueFeature.class.getName(), "test", "{\"field\":\"popularity\"}");loadFeature("const", ValueFeature.class.getName(), "test", "{\"value\":5}");features = new ArrayList<>();features.add(getManagedFeatureStore().getFeatureStore("test").get("popularity"));features.add(getManagedFeatureStore().getFeatureStore("test").get("const"));- final String baseModelJson = getModelInJson("linear", LinearModel.class.getName(),- new String[] {"popularity", "const"},- featureStoreName,- "{\"weights\":{\"popularity\":-1.0, \"const\":1.0}}");+ final String baseModelJson =+ getModelInJson(+ "linear",+ LinearModel.class.getName(),+ new String[] {"popularity", "const"},+ featureStoreName,+ "{\"weights\":{\"popularity\":-1.0, \"const\":1.0}}");// prepare the base model as a file resourcebaseModelFile = new File(tmpConfDir, "baseModel.json");- try (BufferedWriter writer = new BufferedWriter(- new OutputStreamWriter(new FileOutputStream(baseModelFile), StandardCharsets.UTF_8))) {+ try (BufferedWriter writer =+ new BufferedWriter(+ new OutputStreamWriter(new FileOutputStream(baseModelFile), StandardCharsets.UTF_8))) {writer.write(baseModelJson);}baseModelFile.deleteOnExit();}-+@Afterpublic void cleanup() throws Exception {features = null;@@ -78,16 +82,17 @@ public class TestDefaultWrapperModel extends TestRerankBase {aftertest();}- private static String getDefaultWrapperModelInJson(String wrapperModelName, String[] features, String params) {- return getModelInJson(wrapperModelName, DefaultWrapperModel.class.getName(),- features, featureStoreName, params);+ private static String getDefaultWrapperModelInJson(+ String wrapperModelName, String[] features, String params) {+ return getModelInJson(+ wrapperModelName, DefaultWrapperModel.class.getName(), features, featureStoreName, params);}@Testpublic void testLoadModelFromResource() throws Exception {- String wrapperModelJson = getDefaultWrapperModelInJson("fileWrapper",- new String[0],- "{\"resource\":\"" + baseModelFile.getName() + "\"}");+ String wrapperModelJson =+ getDefaultWrapperModelInJson(+ "fileWrapper", new String[0], "{\"resource\":\"" + baseModelFile.getName() + "\"}");assertJPut(ManagedModelStore.REST_END_POINT, wrapperModelJson, "/responseHeader/status==0");final SolrQuery query = new SolrQuery();@@ -95,58 +100,73 @@ public class TestDefaultWrapperModel extends TestRerankBase {query.add("rows", "3");query.add("fl", "*,score");query.add("rq", "{!ltr reRankDocs=3 model=fileWrapper}");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/id==\"3\"", "/response/docs/[0]/score==2.0",- "/response/docs/[1]/id==\"4\"", "/response/docs/[1]/score==1.0",- "/response/docs/[2]/id==\"5\"", "/response/docs/[2]/score==0.0");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/id==\"3\"",+ "/response/docs/[0]/score==2.0",+ "/response/docs/[1]/id==\"4\"",+ "/response/docs/[1]/score==1.0",+ "/response/docs/[2]/id==\"5\"",+ "/response/docs/[2]/score==0.0");}@Testpublic void testLoadNestedWrapperModel() throws Exception {- String otherWrapperModelJson = getDefaultWrapperModelInJson("otherNestedWrapper",- new String[0],- "{\"resource\":\"" + baseModelFile.getName() + "\"}");+ String otherWrapperModelJson =+ getDefaultWrapperModelInJson(+ "otherNestedWrapper",+ new String[0],+ "{\"resource\":\"" + baseModelFile.getName() + "\"}");File otherWrapperModelFile = new File(tmpConfDir, "nestedWrapperModel.json");- try (BufferedWriter writer = new BufferedWriter(- new OutputStreamWriter(new FileOutputStream(otherWrapperModelFile), StandardCharsets.UTF_8))) {+ try (BufferedWriter writer =+ new BufferedWriter(+ new OutputStreamWriter(+ new FileOutputStream(otherWrapperModelFile), StandardCharsets.UTF_8))) {writer.write(otherWrapperModelJson);}- String wrapperModelJson = getDefaultWrapperModelInJson("nestedWrapper",- new String[0],- "{\"resource\":\"" + otherWrapperModelFile.getName() + "\"}");+ String wrapperModelJson =+ getDefaultWrapperModelInJson(+ "nestedWrapper",+ new String[0],+ "{\"resource\":\"" + otherWrapperModelFile.getName() + "\"}");assertJPut(ManagedModelStore.REST_END_POINT, wrapperModelJson, "/responseHeader/status==0");final SolrQuery query = new SolrQuery();query.setQuery("{!func}pow(popularity,2)");query.add("rows", "3");query.add("fl", "*,score");query.add("rq", "{!ltr reRankDocs=3 model=nestedWrapper}");- assertJQ("/query" + query.toQueryString(),- "/response/docs/[0]/id==\"3\"", "/response/docs/[0]/score==2.0",- "/response/docs/[1]/id==\"4\"", "/response/docs/[1]/score==1.0",- "/response/docs/[2]/id==\"5\"", "/response/docs/[2]/score==0.0");+ assertJQ(+ "/query" + query.toQueryString(),+ "/response/docs/[0]/id==\"3\"",+ "/response/docs/[0]/score==2.0",+ "/response/docs/[1]/id==\"4\"",+ "/response/docs/[1]/score==1.0",+ "/response/docs/[2]/id==\"5\"",+ "/response/docs/[2]/score==0.0");}@Testpublic void testLoadModelFromUnknownResource() throws Exception {- String wrapperModelJson = getDefaultWrapperModelInJson("unknownWrapper",- new String[0],- "{\"resource\":\"unknownModel.json\"}");- assertJPut(ManagedModelStore.REST_END_POINT, wrapperModelJson,- "/responseHeader/status==400",- "/error/msg==\"org.apache.solr.ltr.model.ModelException: "- + "Failed to fetch the wrapper model from given resource (unknownModel.json)\"");+ String wrapperModelJson =+ getDefaultWrapperModelInJson(+ "unknownWrapper", new String[0], "{\"resource\":\"unknownModel.json\"}");+ assertJPut(+ ManagedModelStore.REST_END_POINT,+ wrapperModelJson,+ "/responseHeader/status==400",+ "/error/msg==\"org.apache.solr.ltr.model.ModelException: "+ + "Failed to fetch the wrapper model from given resource (unknownModel.json)\"");}@Testpublic void testLoadModelWithEmptyParams() throws Exception {- String wrapperModelJson = getDefaultWrapperModelInJson("invalidWrapper",- new String[0],- "{}");- assertJPut(ManagedModelStore.REST_END_POINT, wrapperModelJson,- "/responseHeader/status==400",- "/error/msg==\"org.apache.solr.ltr.model.ModelException: "- + "no resource configured for model invalidWrapper\"");+ String wrapperModelJson = getDefaultWrapperModelInJson("invalidWrapper", new String[0], "{}");+ assertJPut(+ ManagedModelStore.REST_END_POINT,+ wrapperModelJson,+ "/responseHeader/status==400",+ "/error/msg==\"org.apache.solr.ltr.model.ModelException: "+ + "no resource configured for model invalidWrapper\"");}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.javaindex f528af3e0ec..55beac1d143 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java@@ -21,7 +21,6 @@ import java.util.Collections;import java.util.HashMap;import java.util.List;import java.util.Map;-import org.apache.solr.common.SolrException;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.feature.Feature;@@ -35,24 +34,34 @@ import org.junit.Test;public class TestLinearModel extends TestRerankBase {- public static LTRScoringModel createLinearModel(String name, List<Feature> features,+ public static LTRScoringModel createLinearModel(+ String name,+ List<Feature> features,List<Normalizer> norms,- String featureStoreName, List<Feature> allFeatures,- Map<String,Object> params) throws ModelException {- final LTRScoringModel model = LTRScoringModel.getInstance(solrResourceLoader,- LinearModel.class.getName(),- name,- features, norms, featureStoreName, allFeatures, params);+ String featureStoreName,+ List<Feature> allFeatures,+ Map<String, Object> params)+ throws ModelException {+ final LTRScoringModel model =+ LTRScoringModel.getInstance(+ solrResourceLoader,+ LinearModel.class.getName(),+ name,+ features,+ norms,+ featureStoreName,+ allFeatures,+ params);return model;}- public static Map<String,Object> makeFeatureWeights(List<Feature> features) {+ public static Map<String, Object> makeFeatureWeights(List<Feature> features) {return makeFeatureWeights(features, 0.1);}- public static Map<String,Object> makeFeatureWeights(List<Feature> features, Number weight) {- final Map<String,Object> nameParams = new HashMap<String,Object>();- final HashMap<String,Number> modelWeights = new HashMap<String,Number>();+ public static Map<String, Object> makeFeatureWeights(List<Feature> features, Number weight) {+ final Map<String, Object> nameParams = new HashMap<String, Object>();+ final HashMap<String, Number> modelWeights = new HashMap<String, Number>();for (final Feature feat : features) {modelWeights.put(feat.getName(), weight);}@@ -69,31 +78,29 @@ public class TestLinearModel extends TestRerankBase {// loadFeatures("features-store-test-model.json");store = getManagedModelStore();fstore = getManagedFeatureStore().getFeatureStore("test");-}+@Afterpublic void cleanup() throws Exception {store = null;fstore = null;aftertest();}-+@Testpublic void getInstanceTest() {- final Map<String,Object> weights = new HashMap<>();+ final Map<String, Object> weights = new HashMap<>();weights.put("constant1", 1d);weights.put("constant5", 1d);- Map<String,Object> params = new HashMap<String,Object>();- final List<Feature> features = getFeatures(new String[] {- "constant1", "constant5"});+ Map<String, Object> params = new HashMap<String, Object>();+ final List<Feature> features = getFeatures(new String[] {"constant1", "constant5"});final List<Normalizer> norms =new ArrayList<Normalizer>(- Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));+ Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));params.put("weights", weights);- final LTRScoringModel ltrScoringModel = createLinearModel("test1",- features, norms, "test", fstore.getFeatures(),- params);+ final LTRScoringModel ltrScoringModel =+ createLinearModel("test1", features, norms, "test", fstore.getFeatures(), params);store.addModel(ltrScoringModel);final LTRScoringModel m = store.getModel("test1");@@ -105,41 +112,46 @@ public class TestLinearModel extends TestRerankBase {final ModelException expectedException =new ModelException("Model test2 doesn't contain any weights");- final List<Feature> features = getFeatures(new String[]- {"constant1", "constant5"});+ final List<Feature> features = getFeatures(new String[] {"constant1", "constant5"});final List<Normalizer> norms =- new ArrayList<>(Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));- ModelException ex = expectThrows(ModelException.class, () -> {- createLinearModel("test2",- features, norms, "test", fstore.getFeatures(), null);- });+ new ArrayList<>(Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));+ ModelException ex =+ expectThrows(+ ModelException.class,+ () -> {+ createLinearModel("test2", features, norms, "test", fstore.getFeatures(), null);+ });assertEquals(expectedException.toString(), ex.toString());}@Testpublic void existingNameTest() {final SolrException expectedException =- new SolrException(SolrException.ErrorCode.BAD_REQUEST,- ModelException.class.getName()+": model 'test3' already exists. Please use a different name");+ new SolrException(+ SolrException.ErrorCode.BAD_REQUEST,+ ModelException.class.getName()+ + ": model 'test3' already exists. Please use a different name");- final List<Feature> features = getFeatures(new String[]- {"constant1", "constant5"});+ final List<Feature> features = getFeatures(new String[] {"constant1", "constant5"});final List<Normalizer> norms =- new ArrayList<>(Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));- final Map<String,Object> weights = new HashMap<>();+ new ArrayList<>(Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));+ final Map<String, Object> weights = new HashMap<>();weights.put("constant1", 1d);weights.put("constant5", 1d);- Map<String,Object> params = new HashMap<>();+ Map<String, Object> params = new HashMap<>();params.put("weights", weights);- SolrException ex = expectThrows(SolrException.class, () -> {- final LTRScoringModel ltrScoringModel = createLinearModel("test3",- features, norms, "test", fstore.getFeatures(), params);- store.addModel(ltrScoringModel);- final LTRScoringModel m = store.getModel("test3");- assertEquals(ltrScoringModel, m);- store.addModel(ltrScoringModel);- });+ SolrException ex =+ expectThrows(+ SolrException.class,+ () -> {+ final LTRScoringModel ltrScoringModel =+ createLinearModel("test3", features, norms, "test", fstore.getFeatures(), params);+ store.addModel(ltrScoringModel);+ final LTRScoringModel m = store.getModel("test3");+ assertEquals(ltrScoringModel, m);+ store.addModel(ltrScoringModel);+ });assertEquals(expectedException.toString(), ex.toString());}@@ -147,64 +159,64 @@ public class TestLinearModel extends TestRerankBase {public void duplicateFeatureTest() {final ModelException expectedException =new ModelException("duplicated feature constant1 in model test4");- final List<Feature> features = getFeatures(new String[]- {"constant1", "constant1"});+ final List<Feature> features = getFeatures(new String[] {"constant1", "constant1"});final List<Normalizer> norms =- new ArrayList<>(Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));- final Map<String,Object> weights = new HashMap<>();+ new ArrayList<>(Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));+ final Map<String, Object> weights = new HashMap<>();weights.put("constant1", 1d);weights.put("constant5", 1d);- Map<String,Object> params = new HashMap<>();+ Map<String, Object> params = new HashMap<>();params.put("weights", weights);- ModelException ex = expectThrows(ModelException.class, () -> {- final LTRScoringModel ltrScoringModel = createLinearModel("test4",- features, norms, "test", fstore.getFeatures(), params);- store.addModel(ltrScoringModel);- });+ ModelException ex =+ expectThrows(+ ModelException.class,+ () -> {+ final LTRScoringModel ltrScoringModel =+ createLinearModel("test4", features, norms, "test", fstore.getFeatures(), params);+ store.addModel(ltrScoringModel);+ });assertEquals(expectedException.toString(), ex.toString());-}@Testpublic void missingFeatureWeightTest() {final ModelException expectedException =new ModelException("Model test5 lacks weight(s) for [constant5]");- final List<Feature> features = getFeatures(new String[]- {"constant1", "constant5"});+ final List<Feature> features = getFeatures(new String[] {"constant1", "constant5"});final List<Normalizer> norms =- new ArrayList<>(Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));+ new ArrayList<>(Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));- final Map<String,Object> weights = new HashMap<>();+ final Map<String, Object> weights = new HashMap<>();weights.put("constant1", 1d);weights.put("constant5missing", 1d);- Map<String,Object> params = new HashMap<>();+ Map<String, Object> params = new HashMap<>();params.put("weights", weights);- ModelException ex = expectThrows(ModelException.class, () -> {- createLinearModel("test5",- features, norms, "test", fstore.getFeatures(), params);- });+ ModelException ex =+ expectThrows(+ ModelException.class,+ () -> {+ createLinearModel("test5", features, norms, "test", fstore.getFeatures(), params);+ });assertEquals(expectedException.toString(), ex.toString());}@Testpublic void integerAndLongFeatureWeights_shouldCreateModel() {- final List<Feature> features = getFeatures(new String[]- {"constant1", "constant5"});+ final List<Feature> features = getFeatures(new String[] {"constant1", "constant5"});final List<Normalizer> norms =- new ArrayList<>(Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));+ new ArrayList<>(Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));- final Map<String,Object> weights = new HashMap<>();+ final Map<String, Object> weights = new HashMap<>();weights.put("constant1", 100L);weights.put("constant5", 1);- Map<String,Object> params = new HashMap<>();+ Map<String, Object> params = new HashMap<>();params.put("weights", weights);- final LTRScoringModel ltrScoringModel = createLinearModel("test6",- features, norms, "test", fstore.getFeatures(),- params);+ final LTRScoringModel ltrScoringModel =+ createLinearModel("test6", features, norms, "test", fstore.getFeatures(), params);store.addModel(ltrScoringModel);final LTRScoringModel m = store.getModel("test6");@@ -217,44 +229,51 @@ public class TestLinearModel extends TestRerankBase {new ModelException("no features declared for model test6");final List<Feature> features = getFeatures(new String[] {});final List<Normalizer> norms =- new ArrayList<>(Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));- final Map<String,Object> weights = new HashMap<>();+ new ArrayList<>(Collections.nCopies(features.size(), IdentityNormalizer.INSTANCE));+ final Map<String, Object> weights = new HashMap<>();weights.put("constant1", 1d);weights.put("constant5missing", 1d);- Map<String,Object> params = new HashMap<>();+ Map<String, Object> params = new HashMap<>();params.put("weights", weights);- ModelException ex = expectThrows(ModelException.class, () -> {- final LTRScoringModel ltrScoringModel = createLinearModel("test6",- features, norms, "test", fstore.getFeatures(),- params);- store.addModel(ltrScoringModel);- });+ ModelException ex =+ expectThrows(+ ModelException.class,+ () -> {+ final LTRScoringModel ltrScoringModel =+ createLinearModel("test6", features, norms, "test", fstore.getFeatures(), params);+ store.addModel(ltrScoringModel);+ });assertEquals(expectedException.toString(), ex.toString());}@Test- public void notExistentStore_shouldThrowMeaningFulException(){+ public void notExistentStore_shouldThrowMeaningFulException() {final ModelException expectedException =new ModelException("Missing or empty feature store: not_existent_store");- ModelException ex = expectThrows(ModelException.class, () -> {- createModelFromFiles("linear-model_notExistentStore.json",- "features-store-test-model.json");- });+ ModelException ex =+ expectThrows(+ ModelException.class,+ () -> {+ createModelFromFiles(+ "linear-model_notExistentStore.json", "features-store-test-model.json");+ });assertEquals(expectedException.toString(), ex.toString());}@Test- public void notExistentFeature_shouldThrowMeaningFulException(){+ public void notExistentFeature_shouldThrowMeaningFulException() {final ModelException expectedException =new ModelException("Feature: notExist1 not found in store: test");- ModelException ex = expectThrows(ModelException.class, () -> {- createModelFromFiles("linear-model_notExistentFeature.json",- "features-store-test-model.json");- });+ ModelException ex =+ expectThrows(+ ModelException.class,+ () -> {+ createModelFromFiles(+ "linear-model_notExistentFeature.json", "features-store-test-model.json");+ });assertEquals(expectedException.toString(), ex.toString());}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestMultipleAdditiveTreesModel.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestMultipleAdditiveTreesModel.javaindex 4ae25df2e06..d96c02318e5 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestMultipleAdditiveTreesModel.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestMultipleAdditiveTreesModel.java@@ -16,25 +16,25 @@*/package org.apache.solr.ltr.model;+import static org.hamcrest.core.StringContains.containsString;+import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.junit.After;import org.junit.Before;import org.junit.Test;-import static org.hamcrest.core.StringContains.containsString;-public class TestMultipleAdditiveTreesModel extends TestRerankBase {@Beforepublic void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity","1"));- assertU(adoc("id", "2", "title", "w2", "description", "w2", "popularity","2"));- assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity","3"));- assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity","4"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity","5"));+ assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity", "1"));+ assertU(adoc("id", "2", "title", "w2", "description", "w2", "popularity", "2"));+ assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));+ assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity", "4"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));assertU(commit());}@@ -43,7 +43,6 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {aftertest();}-@Testpublic void testMultipleAdditiveTrees() throws Exception {loadFeatures("multipleadditivetreesmodel_features.json");@@ -53,7 +52,8 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {doTestMultipleAdditiveTreesExplain();}- private void doTestMultipleAdditiveTreesScoringWithAndWithoutEfiFeatureMatches() throws Exception {+ private void doTestMultipleAdditiveTreesScoringWithAndWithoutEfiFeatureMatches()+ throws Exception {final SolrQuery query = new SolrQuery();query.setQuery("*:*");@@ -67,7 +67,8 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {// No match scores since user_query not passed in to external feature info// and feature depended on it.- query.add("rq", "{!ltr reRankDocs=3 model=multipleadditivetreesmodel efi.user_query=dsjkafljjk}");+ query.add(+ "rq", "{!ltr reRankDocs=3 model=multipleadditivetreesmodel efi.user_query=dsjkafljjk}");assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==-120.0");assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/score==-120.0");@@ -90,8 +91,7 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {query.add("fl", "*,score,[fv]");query.add("rows", "3");- query.add("rq",- "{!ltr reRankDocs=3 model=multipleadditivetreesmodel efi.user_query=w3}");+ query.add("rq", "{!ltr reRankDocs=3 model=multipleadditivetreesmodel efi.user_query=w3}");// test out the explain feature, make sure it returns somethingquery.setParam("debugQuery", "on");@@ -122,10 +122,14 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {public void multipleAdditiveTreesTestNoParams() throws Exception {final ModelException expectedException =new ModelException("no trees declared for model multipleadditivetreesmodel_no_params");- Exception ex = expectThrows(Exception.class, () -> {- createModelFromFiles("multipleadditivetreesmodel_no_params.json",- "multipleadditivetreesmodel_features.json");- });+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ createModelFromFiles(+ "multipleadditivetreesmodel_no_params.json",+ "multipleadditivetreesmodel_features.json");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}@@ -134,10 +138,14 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {public void multipleAdditiveTreesTestEmptyParams() throws Exception {final ModelException expectedException =new ModelException("no trees declared for model multipleadditivetreesmodel_no_trees");- Exception ex = expectThrows(Exception.class, () -> {- createModelFromFiles("multipleadditivetreesmodel_no_trees.json",- "multipleadditivetreesmodel_features.json");- });+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ createModelFromFiles(+ "multipleadditivetreesmodel_no_trees.json",+ "multipleadditivetreesmodel_features.json");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}@@ -146,10 +154,14 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {public void multipleAdditiveTreesTestNoWeight() throws Exception {final ModelException expectedException =new ModelException("MultipleAdditiveTreesModel tree doesn't contain a weight");- Exception ex = expectThrows(Exception.class, () -> {- createModelFromFiles("multipleadditivetreesmodel_no_weight.json",- "multipleadditivetreesmodel_features.json");- });+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ createModelFromFiles(+ "multipleadditivetreesmodel_no_weight.json",+ "multipleadditivetreesmodel_features.json");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}@@ -158,10 +170,14 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {public void multipleAdditiveTreesTestTreesParamDoesNotContatinTree() throws Exception {final ModelException expectedException =new ModelException("MultipleAdditiveTreesModel tree doesn't contain a tree");- Exception ex = expectThrows(Exception.class, () -> {- createModelFromFiles("multipleadditivetreesmodel_no_tree.json",- "multipleadditivetreesmodel_features.json");- });+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ createModelFromFiles(+ "multipleadditivetreesmodel_no_tree.json",+ "multipleadditivetreesmodel_features.json");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}@@ -170,10 +186,14 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {public void multipleAdditiveTreesTestNoFeaturesSpecified() throws Exception {final ModelException expectedException =new ModelException("no features declared for model multipleadditivetreesmodel_no_features");- Exception ex = expectThrows(Exception.class, () -> {- createModelFromFiles("multipleadditivetreesmodel_no_features.json",- "multipleadditivetreesmodel_features.json");- });+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ createModelFromFiles(+ "multipleadditivetreesmodel_no_features.json",+ "multipleadditivetreesmodel_features.json");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}@@ -182,10 +202,14 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {public void multipleAdditiveTreesTestNoRight() throws Exception {final ModelException expectedException =new ModelException("MultipleAdditiveTreesModel tree node is missing right");- Exception ex = expectThrows(Exception.class, () -> {- createModelFromFiles("multipleadditivetreesmodel_no_right.json",- "multipleadditivetreesmodel_features.json");- });+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ createModelFromFiles(+ "multipleadditivetreesmodel_no_right.json",+ "multipleadditivetreesmodel_features.json");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}@@ -194,10 +218,14 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {public void multipleAdditiveTreesTestNoLeft() throws Exception {final ModelException expectedException =new ModelException("MultipleAdditiveTreesModel tree node is missing left");- Exception ex = expectThrows(Exception.class, () -> {- createModelFromFiles("multipleadditivetreesmodel_no_left.json",- "multipleadditivetreesmodel_features.json");- });+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ createModelFromFiles(+ "multipleadditivetreesmodel_no_left.json",+ "multipleadditivetreesmodel_features.json");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}@@ -206,10 +234,14 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {public void multipleAdditiveTreesTestNoThreshold() throws Exception {final ModelException expectedException =new ModelException("MultipleAdditiveTreesModel tree node is missing threshold");- Exception ex = expectThrows(Exception.class, () -> {- createModelFromFiles("multipleadditivetreesmodel_no_threshold.json",- "multipleadditivetreesmodel_features.json");- });+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ createModelFromFiles(+ "multipleadditivetreesmodel_no_threshold.json",+ "multipleadditivetreesmodel_features.json");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}@@ -217,37 +249,49 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {@Testpublic void multipleAdditiveTreesTestMissingTreeFeature() throws Exception {final ModelException expectedException =- new ModelException("MultipleAdditiveTreesModel tree node is leaf with left=-100.0 and right=75.0");-- ModelException ex = expectThrows(ModelException.class, () -> {- createModelFromFiles("multipleadditivetreesmodel_no_feature.json",- "multipleadditivetreesmodel_features.json");- });+ new ModelException(+ "MultipleAdditiveTreesModel tree node is leaf with left=-100.0 and right=75.0");++ ModelException ex =+ expectThrows(+ ModelException.class,+ () -> {+ createModelFromFiles(+ "multipleadditivetreesmodel_no_feature.json",+ "multipleadditivetreesmodel_features.json");+ });assertEquals(expectedException.toString(), ex.toString());}@Test- public void multipleAdditiveTreesTestMissingFeatureStore(){+ public void multipleAdditiveTreesTestMissingFeatureStore() {final ModelException expectedException =new ModelException("Missing or empty feature store: not_existent_store");- ModelException ex = expectThrows(ModelException.class, () -> {- createModelFromFiles("multipleadditivetreesmodel_notExistentStore.json",- "multipleadditivetreesmodel_features.json");- });+ ModelException ex =+ expectThrows(+ ModelException.class,+ () -> {+ createModelFromFiles(+ "multipleadditivetreesmodel_notExistentStore.json",+ "multipleadditivetreesmodel_features.json");+ });assertEquals(expectedException.toString(), ex.toString());}@Test- public void multipleAdditiveTreesTestUnknownFeature(){+ public void multipleAdditiveTreesTestUnknownFeature() {final ModelException expectedException =new ModelException("Feature: notExist1 not found in store: _DEFAULT_");- ModelException ex = expectThrows(ModelException.class, () -> {- createModelFromFiles("multipleadditivetreesmodel_unknownFeature.json",- "multipleadditivetreesmodel_features.json");- });+ ModelException ex =+ expectThrows(+ ModelException.class,+ () -> {+ createModelFromFiles(+ "multipleadditivetreesmodel_unknownFeature.json",+ "multipleadditivetreesmodel_features.json");+ });assertEquals(expectedException.toString(), ex.toString());}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestNeuralNetworkModel.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestNeuralNetworkModel.javaindex 6eea812325c..b1ba7e89168 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestNeuralNetworkModel.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestNeuralNetworkModel.java@@ -21,7 +21,6 @@ import java.util.Collections;import java.util.HashMap;import java.util.List;import java.util.Map;-import org.apache.lucene.search.Explanation;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.feature.Feature;@@ -34,27 +33,37 @@ import org.junit.Test;public class TestNeuralNetworkModel extends TestRerankBase {- public static LTRScoringModel createNeuralNetworkModel(String name, List<Feature> features,+ public static LTRScoringModel createNeuralNetworkModel(+ String name,+ List<Feature> features,List<Normalizer> norms,- String featureStoreName, List<Feature> allFeatures,- Map<String,Object> params) throws ModelException {- return LTRScoringModel.getInstance(solrResourceLoader,+ String featureStoreName,+ List<Feature> allFeatures,+ Map<String, Object> params)+ throws ModelException {+ return LTRScoringModel.getInstance(+ solrResourceLoader,NeuralNetworkModel.class.getName(),name,- features, norms, featureStoreName, allFeatures, params);+ features,+ norms,+ featureStoreName,+ allFeatures,+ params);}@Beforepublic void setup() throws Exception {setuptest(false);}-+@Afterpublic void after() throws Exception {aftertest();}- protected static Map<String,Object> createLayerParams(double[][] matrix, double[] bias, String activation) {+ protected static Map<String, Object> createLayerParams(+ double[][] matrix, double[] bias, String activation) {final ArrayList<ArrayList<Double>> matrixList = new ArrayList<ArrayList<Double>>();for (int row = 0; row < matrix.length; row++) {@@ -69,7 +78,7 @@ public class TestNeuralNetworkModel extends TestRerankBase {biasList.add(bias[i]);}- final Map<String,Object> layer = new HashMap<String,Object>();+ final Map<String, Object> layer = new HashMap<String, Object>();layer.put("matrix", matrixList);layer.put("bias", biasList);layer.put("activation", activation);@@ -93,36 +102,41 @@ public class TestNeuralNetworkModel extends TestRerankBase {final double layer1Node3Weight3 = 11.0;final double layer1Node3Weight4 = 12.0;- double[][] matrixOne = { { layer1Node1Weight1, layer1Node1Weight2, layer1Node1Weight3, layer1Node1Weight4 },- { layer1Node2Weight1, layer1Node2Weight2, layer1Node2Weight3, layer1Node2Weight4 },- { layer1Node3Weight1, layer1Node3Weight2, layer1Node3Weight3, layer1Node3Weight4 } };+ double[][] matrixOne = {+ {layer1Node1Weight1, layer1Node1Weight2, layer1Node1Weight3, layer1Node1Weight4},+ {layer1Node2Weight1, layer1Node2Weight2, layer1Node2Weight3, layer1Node2Weight4},+ {layer1Node3Weight1, layer1Node3Weight2, layer1Node3Weight3, layer1Node3Weight4}+ };final double layer1Node1Bias = 13.0;final double layer1Node2Bias = 14.0;final double layer1Node3Bias = 15.0;- double[] biasOne = { layer1Node1Bias, layer1Node2Bias, layer1Node3Bias };+ double[] biasOne = {layer1Node1Bias, layer1Node2Bias, layer1Node3Bias};final double outputNodeWeight1 = 16.0;final double outputNodeWeight2 = 17.0;final double outputNodeWeight3 = 18.0;- double[][] matrixTwo = { { outputNodeWeight1, outputNodeWeight2, outputNodeWeight3 } };+ double[][] matrixTwo = {{outputNodeWeight1, outputNodeWeight2, outputNodeWeight3}};final double outputNodeBias = 19.0;- double[] biasTwo = { outputNodeBias };+ double[] biasTwo = {outputNodeBias};- Map<String,Object> params = new HashMap<String,Object>();- ArrayList<Map<String,Object>> layers = new ArrayList<Map<String,Object>>();+ Map<String, Object> params = new HashMap<String, Object>();+ ArrayList<Map<String, Object>> layers = new ArrayList<Map<String, Object>>();layers.add(createLayerParams(matrixOne, biasOne, "relu"));layers.add(createLayerParams(matrixTwo, biasTwo, "relu"));params.put("layers", layers);- final List<Feature> allFeaturesInStore- = getFeatures(new String[] {"constantOne", "constantTwo", "constantThree", "constantFour", "constantFive"});+ final List<Feature> allFeaturesInStore =+ getFeatures(+ new String[] {+ "constantOne", "constantTwo", "constantThree", "constantFour", "constantFive"+ });final List<Feature> featuresInModel = new ArrayList<>(allFeaturesInStore);Collections.shuffle(featuresInModel, random()); // store and model order of features can vary@@ -131,23 +145,24 @@ public class TestNeuralNetworkModel extends TestRerankBase {final List<Normalizer> norms =new ArrayList<Normalizer>(- Collections.nCopies(featuresInModel.size(),IdentityNormalizer.INSTANCE));- final LTRScoringModel ltrScoringModel = createNeuralNetworkModel("test_score",- featuresInModel, norms, "test_score", allFeaturesInStore, params);+ Collections.nCopies(featuresInModel.size(), IdentityNormalizer.INSTANCE));+ final LTRScoringModel ltrScoringModel =+ createNeuralNetworkModel(+ "test_score", featuresInModel, norms, "test_score", allFeaturesInStore, params);{// pretend all features scored zero- float[] testVec = { 0.0f, 0.0f, 0.0f, 0.0f };+ float[] testVec = {0.0f, 0.0f, 0.0f, 0.0f};// with all zero inputs the layer1 node outputs are layer1 node biases onlyfinal double layer1Node1Output = layer1Node1Bias;final double layer1Node2Output = layer1Node2Bias;final double layer1Node3Output = layer1Node3Bias;// with just one layer the output node calculation is easyfinal double outputNodeOutput =- (layer1Node1Output*outputNodeWeight1) +- (layer1Node2Output*outputNodeWeight2) +- (layer1Node3Output*outputNodeWeight3) +- outputNodeBias;+ (layer1Node1Output * outputNodeWeight1)+ + (layer1Node2Output * outputNodeWeight2)+ + (layer1Node3Output * outputNodeWeight3)+ + outputNodeBias;assertEquals(735.0, outputNodeOutput, 0.001);// and the expected score is that of the output nodefinal double expectedScore = outputNodeOutput;@@ -157,17 +172,32 @@ public class TestNeuralNetworkModel extends TestRerankBase {{// pretend all features scored one- float[] testVec = { 1.0f, 1.0f, 1.0f, 1.0f };+ float[] testVec = {1.0f, 1.0f, 1.0f, 1.0f};// with all one inputs the layer1 node outputs are simply sum of weights and biases- final double layer1Node1Output = layer1Node1Weight1 + layer1Node1Weight2 + layer1Node1Weight3 + layer1Node1Weight4 + layer1Node1Bias;- final double layer1Node2Output = layer1Node2Weight1 + layer1Node2Weight2 + layer1Node2Weight3 + layer1Node2Weight4 + layer1Node2Bias;- final double layer1Node3Output = layer1Node3Weight1 + layer1Node3Weight2 + layer1Node3Weight3 + layer1Node3Weight4 + layer1Node3Bias;+ final double layer1Node1Output =+ layer1Node1Weight1+ + layer1Node1Weight2+ + layer1Node1Weight3+ + layer1Node1Weight4+ + layer1Node1Bias;+ final double layer1Node2Output =+ layer1Node2Weight1+ + layer1Node2Weight2+ + layer1Node2Weight3+ + layer1Node2Weight4+ + layer1Node2Bias;+ final double layer1Node3Output =+ layer1Node3Weight1+ + layer1Node3Weight2+ + layer1Node3Weight3+ + layer1Node3Weight4+ + layer1Node3Bias;// with just one layer the output node calculation is easyfinal double outputNodeOutput =- (layer1Node1Output*outputNodeWeight1) +- (layer1Node2Output*outputNodeWeight2) +- (layer1Node3Output*outputNodeWeight3) +- outputNodeBias;+ (layer1Node1Output * outputNodeWeight1)+ + (layer1Node2Output * outputNodeWeight2)+ + (layer1Node3Output * outputNodeWeight3)+ + outputNodeBias;assertEquals(2093.0, outputNodeOutput, 0.001);// and the expected score is that of the output nodefinal double expectedScore = outputNodeOutput;@@ -183,17 +213,36 @@ public class TestNeuralNetworkModel extends TestRerankBase {final float input4 = random().nextFloat();float[] testVec = {input1, input2, input3, input4};// the layer1 node outputs are sum of input-times-weight plus bias- final double layer1Node1Output = input1*layer1Node1Weight1 + input2*layer1Node1Weight2 + input3*layer1Node1Weight3 + input4*layer1Node1Weight4 + layer1Node1Bias;- final double layer1Node2Output = input1*layer1Node2Weight1 + input2*layer1Node2Weight2 + input3*layer1Node2Weight3 + input4*layer1Node2Weight4 + layer1Node2Bias;- final double layer1Node3Output = input1*layer1Node3Weight1 + input2*layer1Node3Weight2 + input3*layer1Node3Weight3 + input4*layer1Node3Weight4 + layer1Node3Bias;+ final double layer1Node1Output =+ input1 * layer1Node1Weight1+ + input2 * layer1Node1Weight2+ + input3 * layer1Node1Weight3+ + input4 * layer1Node1Weight4+ + layer1Node1Bias;+ final double layer1Node2Output =+ input1 * layer1Node2Weight1+ + input2 * layer1Node2Weight2+ + input3 * layer1Node2Weight3+ + input4 * layer1Node2Weight4+ + layer1Node2Bias;+ final double layer1Node3Output =+ input1 * layer1Node3Weight1+ + input2 * layer1Node3Weight2+ + input3 * layer1Node3Weight3+ + input4 * layer1Node3Weight4+ + layer1Node3Bias;// with just one layer the output node calculation is easyfinal double outputNodeOutput =- (layer1Node1Output*outputNodeWeight1) +- (layer1Node2Output*outputNodeWeight2) +- (layer1Node3Output*outputNodeWeight3) +- outputNodeBias;- assertTrue("outputNodeOutput="+outputNodeOutput, 735.0 <= outputNodeOutput); // inputs between zero and one produced output greater than 74- assertTrue("outputNodeOutput="+outputNodeOutput, outputNodeOutput <= 2093.0); // inputs between zero and one produced output less than 294+ (layer1Node1Output * outputNodeWeight1)+ + (layer1Node2Output * outputNodeWeight2)+ + (layer1Node3Output * outputNodeWeight3)+ + outputNodeBias;+ assertTrue(+ "outputNodeOutput=" + outputNodeOutput,+ 735.0 <= outputNodeOutput); // inputs between zero and one produced output greater than 74+ assertTrue(+ "outputNodeOutput=" + outputNodeOutput,+ outputNodeOutput <= 2093.0); // inputs between zero and one produced output less than 294// and the expected score is that of the output nodefinal double expectedScore = outputNodeOutput;float score = ltrScoringModel.score(testVec);@@ -204,11 +253,15 @@ public class TestNeuralNetworkModel extends TestRerankBase {@Testpublic void badActivationTest() throws Exception {final ModelException expectedException =- new ModelException("Invalid activation function (\"sig\") in layer 0 of model \"neuralnetworkmodel_bad_activation\".");- Exception ex = expectThrows(Exception.class, () -> {- createModelFromFiles("neuralnetworkmodel_bad_activation.json",- "neuralnetworkmodel_features.json");- });+ new ModelException(+ "Invalid activation function (\"sig\") in layer 0 of model \"neuralnetworkmodel_bad_activation\".");+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ createModelFromFiles(+ "neuralnetworkmodel_bad_activation.json", "neuralnetworkmodel_features.json");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}@@ -216,12 +269,16 @@ public class TestNeuralNetworkModel extends TestRerankBase {@Testpublic void biasDimensionMismatchTest() throws Exception {final ModelException expectedException =- new ModelException("Dimension mismatch in model \"neuralnetworkmodel_mismatch_bias\". " +- "Layer 0 has 2 bias weights but 3 weight matrix rows.");- Exception ex = expectThrows(Exception.class, () -> {- createModelFromFiles("neuralnetworkmodel_mismatch_bias.json",- "neuralnetworkmodel_features.json");- });+ new ModelException(+ "Dimension mismatch in model \"neuralnetworkmodel_mismatch_bias\". "+ + "Layer 0 has 2 bias weights but 3 weight matrix rows.");+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ createModelFromFiles(+ "neuralnetworkmodel_mismatch_bias.json", "neuralnetworkmodel_features.json");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}@@ -229,12 +286,16 @@ public class TestNeuralNetworkModel extends TestRerankBase {@Testpublic void inputDimensionMismatchTest() throws Exception {final ModelException expectedException =- new ModelException("Dimension mismatch in model \"neuralnetworkmodel_mismatch_input\". The input has " +- "4 features, but the weight matrix for layer 0 has 3 columns.");- Exception ex = expectThrows(Exception.class, () -> {- createModelFromFiles("neuralnetworkmodel_mismatch_input.json",- "neuralnetworkmodel_features.json");- });+ new ModelException(+ "Dimension mismatch in model \"neuralnetworkmodel_mismatch_input\". The input has "+ + "4 features, but the weight matrix for layer 0 has 3 columns.");+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ createModelFromFiles(+ "neuralnetworkmodel_mismatch_input.json", "neuralnetworkmodel_features.json");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}@@ -242,25 +303,33 @@ public class TestNeuralNetworkModel extends TestRerankBase {@Testpublic void layerDimensionMismatchTest() throws Exception {final ModelException expectedException =- new ModelException("Dimension mismatch in model \"neuralnetworkmodel_mismatch_layers\". The weight matrix " +- "for layer 0 has 2 rows, but the weight matrix for layer 1 has 3 columns.");- Exception ex = expectThrows(Exception.class, () -> {- createModelFromFiles("neuralnetworkmodel_mismatch_layers.json",- "neuralnetworkmodel_features.json");- });+ new ModelException(+ "Dimension mismatch in model \"neuralnetworkmodel_mismatch_layers\". The weight matrix "+ + "for layer 0 has 2 rows, but the weight matrix for layer 1 has 3 columns.");+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ createModelFromFiles(+ "neuralnetworkmodel_mismatch_layers.json", "neuralnetworkmodel_features.json");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}-+@Testpublic void tooManyRowsTest() throws Exception {final ModelException expectedException =- new ModelException("Dimension mismatch in model \"neuralnetworkmodel_too_many_rows\". " +- "Layer 1 has 1 bias weights but 2 weight matrix rows.");- Exception ex = expectThrows(Exception.class, () -> {- createModelFromFiles("neuralnetworkmodel_too_many_rows.json",- "neuralnetworkmodel_features.json");- });+ new ModelException(+ "Dimension mismatch in model \"neuralnetworkmodel_too_many_rows\". "+ + "Layer 1 has 1 bias weights but 2 weight matrix rows.");+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ createModelFromFiles(+ "neuralnetworkmodel_too_many_rows.json", "neuralnetworkmodel_features.json");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}@@ -268,30 +337,37 @@ public class TestNeuralNetworkModel extends TestRerankBase {@Testpublic void testExplain() throws Exception {- final LTRScoringModel model = createModelFromFiles("neuralnetworkmodel_explainable.json",- "neuralnetworkmodel_features.json");+ final LTRScoringModel model =+ createModelFromFiles(+ "neuralnetworkmodel_explainable.json", "neuralnetworkmodel_features.json");- final float[] featureValues = { 1.2f, 3.4f, 5.6f, 7.8f };+ final float[] featureValues = {1.2f, 3.4f, 5.6f, 7.8f};final List<Explanation> explanations = new ArrayList<Explanation>();- for (int ii=0; ii<featureValues.length; ++ii)- {+ for (int ii = 0; ii < featureValues.length; ++ii) {explanations.add(Explanation.match(featureValues[ii], ""));}final float finalScore = model.score(featureValues);final Explanation explanation = model.explain(null, 0, finalScore, explanations);- assertEquals(finalScore+" = (name=neuralnetworkmodel_explainable"+- ",featureValues=[constantOne=1.2,constantTwo=3.4,constantThree=5.6,constantFour=7.8]"+- ",layers=[(matrix=2x4,activation=relu),(matrix=1x2,activation=identity)]"+- ")\n",+ assertEquals(+ finalScore+ + " = (name=neuralnetworkmodel_explainable"+ + ",featureValues=[constantOne=1.2,constantTwo=3.4,constantThree=5.6,constantFour=7.8]"+ + ",layers=[(matrix=2x4,activation=relu),(matrix=1x2,activation=identity)]"+ + ")\n",explanation.toString());}public static class CustomNeuralNetworkModel extends NeuralNetworkModel {- public CustomNeuralNetworkModel(String name, List<Feature> features, List<Normalizer> norms,- String featureStoreName, List<Feature> allFeatures, Map<String,Object> params) {+ public CustomNeuralNetworkModel(+ String name,+ List<Feature> features,+ List<Normalizer> norms,+ String featureStoreName,+ List<Feature> allFeatures,+ Map<String, Object> params) {super(name, features, norms, featureStoreName, allFeatures, params);}@@ -301,12 +377,13 @@ public class TestNeuralNetworkModel extends TestRerankBase {super.setActivation(o);switch (this.activationStr) {case "answer":- this.activation = new Activation() {- @Override- public float apply(float in) {- return in * 42f;- }- };+ this.activation =+ new Activation() {+ @Override+ public float apply(float in) {+ return in * 42f;+ }+ };break;default:break;@@ -319,38 +396,37 @@ public class TestNeuralNetworkModel extends TestRerankBase {protected Layer createLayer(Object o) {final DefaultLayer layer = new DefaultLayer();if (o != null) {- SolrPluginUtils.invokeSetters(layer, ((Map<String,Object>) o).entrySet());+ SolrPluginUtils.invokeSetters(layer, ((Map<String, Object>) o).entrySet());}return layer;}-}@Testpublic void testCustom() throws Exception {- final LTRScoringModel model = createModelFromFiles("neuralnetworkmodel_custom.json",- "neuralnetworkmodel_features.json");+ final LTRScoringModel model =+ createModelFromFiles("neuralnetworkmodel_custom.json", "neuralnetworkmodel_features.json");final float featureValue1 = 4f;final float featureValue2 = 2f;- final float[] featureValues = { featureValue1, featureValue2 };+ final float[] featureValues = {featureValue1, featureValue2};- final double expectedScore = (featureValue1+featureValue2) * 42f;+ final double expectedScore = (featureValue1 + featureValue2) * 42f;float actualScore = model.score(featureValues);assertEquals(expectedScore, actualScore, 0.001);final List<Explanation> explanations = new ArrayList<Explanation>();- for (int ii=0; ii<featureValues.length; ++ii)- {+ for (int ii = 0; ii < featureValues.length; ++ii) {explanations.add(Explanation.match(featureValues[ii], ""));}final Explanation explanation = model.explain(null, 0, actualScore, explanations);- assertEquals(actualScore+" = (name=neuralnetworkmodel_custom"+- ",featureValues=[constantFour=4.0,constantTwo=2.0]"+- ",layers=[(matrix=1x2,activation=answer)]"+- ")\n",+ assertEquals(+ actualScore+ + " = (name=neuralnetworkmodel_custom"+ + ",featureValues=[constantFour=4.0,constantTwo=2.0]"+ + ",layers=[(matrix=1x2,activation=answer)]"+ + ")\n",explanation.toString());}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestWrapperModel.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestWrapperModel.javaindex af083e70ac4..119f6ba5e14 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestWrapperModel.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/model/TestWrapperModel.java@@ -23,7 +23,6 @@ import java.util.Arrays;import java.util.Collections;import java.util.List;import java.util.Map;-import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.feature.Feature;import org.apache.solr.ltr.feature.ValueFeature;@@ -42,7 +41,13 @@ public class TestWrapperModel extends TestRerankBase {}private StubWrapperModel(String name, List<Feature> features, List<Normalizer> norms) {- super(name, features, norms, FeatureStore.DEFAULT_FEATURE_STORE_NAME, features, Collections.emptyMap());+ super(+ name,+ features,+ norms,+ FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ features,+ Collections.emptyMap());}@Override@@ -51,13 +56,13 @@ public class TestWrapperModel extends TestRerankBase {}}- private static LTRScoringModel createMockWrappedModel(String featureStoreName,- List<Feature> features, List<Normalizer> norms) {- LTRScoringModel wrappedModel = Mockito.mock(LTRScoringModel.class);- Mockito.doReturn(featureStoreName).when(wrappedModel).getFeatureStoreName();- Mockito.doReturn(features).when(wrappedModel).getFeatures();- Mockito.doReturn(norms).when(wrappedModel).getNorms();- return wrappedModel;+ private static LTRScoringModel createMockWrappedModel(+ String featureStoreName, List<Feature> features, List<Normalizer> norms) {+ LTRScoringModel wrappedModel = Mockito.mock(LTRScoringModel.class);+ Mockito.doReturn(featureStoreName).when(wrappedModel).getFeatureStoreName();+ Mockito.doReturn(features).when(wrappedModel).getFeatures();+ Mockito.doReturn(norms).when(wrappedModel).getNorms();+ return wrappedModel;}@Test@@ -66,14 +71,20 @@ public class TestWrapperModel extends TestRerankBase {wrapperModel.validate();// wrapper model with features- WrapperModel wrapperModelWithFeatures = new StubWrapperModel("testModel",- Collections.singletonList(new ValueFeature("val", Collections.emptyMap())), Collections.emptyList());+ WrapperModel wrapperModelWithFeatures =+ new StubWrapperModel(+ "testModel",+ Collections.singletonList(new ValueFeature("val", Collections.emptyMap())),+ Collections.emptyList());ModelException e = expectThrows(ModelException.class, wrapperModelWithFeatures::validate);assertEquals("features must be empty for the wrapper model testModel", e.getMessage());// wrapper model with norms- WrapperModel wrapperModelWithNorms = new StubWrapperModel("testModel",- Collections.emptyList(), Collections.singletonList(IdentityNormalizer.INSTANCE));+ WrapperModel wrapperModelWithNorms =+ new StubWrapperModel(+ "testModel",+ Collections.emptyList(),+ Collections.singletonList(IdentityNormalizer.INSTANCE));e = expectThrows(ModelException.class, wrapperModelWithNorms::validate);assertEquals("norms must be empty for the wrapper model testModel", e.getMessage());@@ -81,55 +92,51 @@ public class TestWrapperModel extends TestRerankBase {// update valid model{- LTRScoringModel wrappedModel =- createMockWrappedModel(FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ LTRScoringModel wrappedModel =+ createMockWrappedModel(+ FeatureStore.DEFAULT_FEATURE_STORE_NAME,Arrays.asList(new ValueFeature("v1", Collections.emptyMap()),new ValueFeature("v2", Collections.emptyMap())),- Arrays.asList(- IdentityNormalizer.INSTANCE,- IdentityNormalizer.INSTANCE)- );+ Arrays.asList(IdentityNormalizer.INSTANCE, IdentityNormalizer.INSTANCE));wrapperModel.updateModel(wrappedModel);}// update invalid model (feature store mismatch){- LTRScoringModel wrappedModel =- createMockWrappedModel("wrappedFeatureStore",+ LTRScoringModel wrappedModel =+ createMockWrappedModel(+ "wrappedFeatureStore",Arrays.asList(new ValueFeature("v1", Collections.emptyMap()),new ValueFeature("v2", Collections.emptyMap())),- Arrays.asList(- IdentityNormalizer.INSTANCE,- IdentityNormalizer.INSTANCE)- );+ Arrays.asList(IdentityNormalizer.INSTANCE, IdentityNormalizer.INSTANCE));e = expectThrows(ModelException.class, () -> wrapperModel.updateModel(wrappedModel));- assertEquals("wrapper feature store name (_DEFAULT_) must match the wrapped feature store name (wrappedFeatureStore)", e.getMessage());+ assertEquals(+ "wrapper feature store name (_DEFAULT_) must match the wrapped feature store name (wrappedFeatureStore)",+ e.getMessage());}// update invalid model (no features){- LTRScoringModel wrappedModel =- createMockWrappedModel(FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ LTRScoringModel wrappedModel =+ createMockWrappedModel(+ FeatureStore.DEFAULT_FEATURE_STORE_NAME,Collections.emptyList(),- Arrays.asList(- IdentityNormalizer.INSTANCE,- IdentityNormalizer.INSTANCE)- );+ Arrays.asList(IdentityNormalizer.INSTANCE, IdentityNormalizer.INSTANCE));e = expectThrows(ModelException.class, () -> wrapperModel.updateModel(wrappedModel));assertEquals("no features declared for model testModel", e.getMessage());}// update invalid model (no norms){- LTRScoringModel wrappedModel =- createMockWrappedModel(FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ LTRScoringModel wrappedModel =+ createMockWrappedModel(+ FeatureStore.DEFAULT_FEATURE_STORE_NAME,Arrays.asList(new ValueFeature("v1", Collections.emptyMap()),new ValueFeature("v2", Collections.emptyMap())),- Collections.emptyList()- );+ Collections.emptyList());e = expectThrows(ModelException.class, () -> wrapperModel.updateModel(wrappedModel));assertEquals("counted 2 features and 0 norms in model testModel", e.getMessage());}@@ -152,21 +159,28 @@ public class TestWrapperModel extends TestRerankBase {++overridableMethodCount;if (Arrays.asList(- "getName", // the wrapper model's name is its own name i.e. _not_ the name of the wrapped model- "getFeatureStoreName", // wrapper and wrapped model feature store should match, so need not override- "getParams" // the wrapper model's params are its own params i.e. _not_ the params of the wrapped model- ).contains(superClassMethod.getName())) {- assertThrows("WrapperModel need not override '" + superClassMethod.getName() + "'",- NoSuchMethodException.class, () -> {- WrapperModel.class.getDeclaredMethod(superClassMethod.getName(), superClassMethod.getParameterTypes());- }- );+ "getName", // the wrapper model's name is its own name i.e. _not_ the name of the+ // wrapped model+ "getFeatureStoreName", // wrapper and wrapped model feature store should match, so+ // need not override+ "getParams" // the wrapper model's params are its own params i.e. _not_ the params of+ // the wrapped model+ )+ .contains(superClassMethod.getName())) {+ assertThrows(+ "WrapperModel need not override '" + superClassMethod.getName() + "'",+ NoSuchMethodException.class,+ () -> {+ WrapperModel.class.getDeclaredMethod(+ superClassMethod.getName(), superClassMethod.getParameterTypes());+ });} else {try {- final Method subClassMethod = WrapperModel.class.getDeclaredMethod(- superClassMethod.getName(),- superClassMethod.getParameterTypes());- assertEquals("getReturnType() difference",+ final Method subClassMethod =+ WrapperModel.class.getDeclaredMethod(+ superClassMethod.getName(), superClassMethod.getParameterTypes());+ assertEquals(+ "getReturnType() difference",superClassMethod.getReturnType(),subClassMethod.getReturnType());} catch (NoSuchMethodException e) {diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/norm/TestMinMaxNormalizer.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/norm/TestMinMaxNormalizer.javaindex 52e39b538e6..33ca6fb9445 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/norm/TestMinMaxNormalizer.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/norm/TestMinMaxNormalizer.java@@ -16,93 +16,81 @@*/package org.apache.solr.ltr.norm;+import static org.junit.Assert.assertEquals;+import static org.junit.Assert.assertTrue;+import java.nio.file.Paths;import java.util.HashMap;import java.util.Map;-import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.core.SolrResourceLoader;import org.junit.Test;-import static org.junit.Assert.assertEquals;-import static org.junit.Assert.assertTrue;-public class TestMinMaxNormalizer {- private final SolrResourceLoader solrResourceLoader = new SolrResourceLoader(Paths.get("").toAbsolutePath());+ private final SolrResourceLoader solrResourceLoader =+ new SolrResourceLoader(Paths.get("").toAbsolutePath());- private Normalizer implTestMinMax(Map<String,Object> params,- float expectedMin, float expectedMax) {- final Normalizer n = Normalizer.getInstance(- solrResourceLoader,- MinMaxNormalizer.class.getName(),- params);+ private Normalizer implTestMinMax(+ Map<String, Object> params, float expectedMin, float expectedMax) {+ final Normalizer n =+ Normalizer.getInstance(solrResourceLoader, MinMaxNormalizer.class.getName(), params);assertTrue(n instanceof MinMaxNormalizer);- final MinMaxNormalizer mmn = (MinMaxNormalizer)n;+ final MinMaxNormalizer mmn = (MinMaxNormalizer) n;assertEquals(mmn.getMin(), expectedMin, 0.0);assertEquals(mmn.getMax(), expectedMax, 0.0);- assertEquals("{min="+expectedMin+", max="+expectedMax+"}", mmn.paramsToMap().toString());+ assertEquals(+ "{min=" + expectedMin + ", max=" + expectedMax + "}", mmn.paramsToMap().toString());return n;}@Testpublic void testInvalidMinMaxNoParams() {- implTestMinMax(new HashMap<String,Object>(),- Float.NEGATIVE_INFINITY,- Float.POSITIVE_INFINITY);+ implTestMinMax(new HashMap<String, Object>(), Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY);}@Testpublic void testInvalidMinMaxMissingMax() {- final Map<String,Object> params = new HashMap<String,Object>();+ final Map<String, Object> params = new HashMap<String, Object>();params.put("min", "0.0f");- implTestMinMax(params,- 0.0f,- Float.POSITIVE_INFINITY);+ implTestMinMax(params, 0.0f, Float.POSITIVE_INFINITY);}@Testpublic void testInvalidMinMaxMissingMin() {- final Map<String,Object> params = new HashMap<String,Object>();+ final Map<String, Object> params = new HashMap<String, Object>();params.put("max", "0.0f");- implTestMinMax(params,- Float.NEGATIVE_INFINITY,- 0.0f);+ implTestMinMax(params, Float.NEGATIVE_INFINITY, 0.0f);}@Testpublic void testMinMaxNormalizerMinLargerThanMax() {- final Map<String,Object> params = new HashMap<String,Object>();+ final Map<String, Object> params = new HashMap<String, Object>();params.put("min", "10.0f");params.put("max", "0.0f");- implTestMinMax(params,- 10.0f,- 0.0f);+ implTestMinMax(params, 10.0f, 0.0f);}@Testpublic void testMinMaxNormalizerMinEqualToMax() {- final Map<String,Object> params = new HashMap<String,Object>();+ final Map<String, Object> params = new HashMap<String, Object>();params.put("min", "10.0f");params.put("max", "10.0f");final NormalizerException expectedException =- new NormalizerException("MinMax Normalizer delta must not be zero "- + "| min = 10.0,max = 10.0,delta = 0.0");- NormalizerException ex = SolrTestCaseJ4.expectThrows(NormalizerException.class,- () -> implTestMinMax(params, 10.0f, 10.0f)- );+ new NormalizerException(+ "MinMax Normalizer delta must not be zero " + "| min = 10.0,max = 10.0,delta = 0.0");+ NormalizerException ex =+ SolrTestCaseJ4.expectThrows(+ NormalizerException.class, () -> implTestMinMax(params, 10.0f, 10.0f));assertEquals(expectedException.toString(), ex.toString());}@Testpublic void testNormalizer() {- final Map<String,Object> params = new HashMap<String,Object>();+ final Map<String, Object> params = new HashMap<String, Object>();params.put("min", "5.0f");params.put("max", "10.0f");- final Normalizer n =- implTestMinMax(params,- 5.0f,- 10.0f);+ final Normalizer n = implTestMinMax(params, 5.0f, 10.0f);float value = 8;assertEquals((value - 5f) / (10f - 5f), n.normalize(value), 0.0001);@@ -122,11 +110,13 @@ public class TestMinMaxNormalizer {n1.setMin(5.0f);n1.setMax(10.0f);- final Map<String,Object> params = n1.paramsToMap();- final MinMaxNormalizer n2 = (MinMaxNormalizer) Normalizer.getInstance(- new SolrResourceLoader(Paths.get("").toAbsolutePath()),- MinMaxNormalizer.class.getName(),- params);+ final Map<String, Object> params = n1.paramsToMap();+ final MinMaxNormalizer n2 =+ (MinMaxNormalizer)+ Normalizer.getInstance(+ new SolrResourceLoader(Paths.get("").toAbsolutePath()),+ MinMaxNormalizer.class.getName(),+ params);assertEquals(n1.getMin(), n2.getMin(), 1e-6);assertEquals(n1.getMax(), n2.getMax(), 1e-6);}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/norm/TestStandardNormalizer.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/norm/TestStandardNormalizer.javaindex bc9433741c8..5342cb58ccb 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/norm/TestStandardNormalizer.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/norm/TestStandardNormalizer.java@@ -16,108 +16,98 @@*/package org.apache.solr.ltr.norm;+import static org.junit.Assert.assertEquals;+import static org.junit.Assert.assertTrue;+import java.nio.file.Paths;import java.util.HashMap;import java.util.Map;-import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.core.SolrResourceLoader;import org.junit.Test;-import static org.junit.Assert.assertEquals;-import static org.junit.Assert.assertTrue;-public class TestStandardNormalizer {- private final SolrResourceLoader solrResourceLoader = new SolrResourceLoader(Paths.get("").toAbsolutePath());+ private final SolrResourceLoader solrResourceLoader =+ new SolrResourceLoader(Paths.get("").toAbsolutePath());- private Normalizer implTestStandard(Map<String,Object> params,- float expectedAvg, float expectedStd) {- final Normalizer n = Normalizer.getInstance(- solrResourceLoader,- StandardNormalizer.class.getName(),- params);+ private Normalizer implTestStandard(+ Map<String, Object> params, float expectedAvg, float expectedStd) {+ final Normalizer n =+ Normalizer.getInstance(solrResourceLoader, StandardNormalizer.class.getName(), params);assertTrue(n instanceof StandardNormalizer);- final StandardNormalizer sn = (StandardNormalizer)n;+ final StandardNormalizer sn = (StandardNormalizer) n;assertEquals(sn.getAvg(), expectedAvg, 0.0);assertEquals(sn.getStd(), expectedStd, 0.0);- assertEquals("{avg="+expectedAvg+", std="+expectedStd+"}", sn.paramsToMap().toString());+ assertEquals("{avg=" + expectedAvg + ", std=" + expectedStd + "}", sn.paramsToMap().toString());return n;}@Testpublic void testNormalizerNoParams() {- implTestStandard(new HashMap<String,Object>(),- 0.0f,- 1.0f);+ implTestStandard(new HashMap<String, Object>(), 0.0f, 1.0f);}@Testpublic void testInvalidSTD() {- final Map<String,Object> params = new HashMap<String,Object>();+ final Map<String, Object> params = new HashMap<String, Object>();params.put("std", "0f");final NormalizerException expectedException =- new NormalizerException("Standard Normalizer standard deviation must be positive "- + "| avg = 0.0,std = 0.0");- NormalizerException ex = SolrTestCaseJ4.expectThrows(NormalizerException.class,- () -> implTestStandard(params, 0.0f, 0.0f)- );+ new NormalizerException(+ "Standard Normalizer standard deviation must be positive " + "| avg = 0.0,std = 0.0");+ NormalizerException ex =+ SolrTestCaseJ4.expectThrows(+ NormalizerException.class, () -> implTestStandard(params, 0.0f, 0.0f));assertEquals(expectedException.toString(), ex.toString());}@Testpublic void testInvalidSTD2() {- final Map<String,Object> params = new HashMap<String,Object>();+ final Map<String, Object> params = new HashMap<String, Object>();params.put("std", "-1f");final NormalizerException expectedException =- new NormalizerException("Standard Normalizer standard deviation must be positive "- + "| avg = 0.0,std = -1.0");+ new NormalizerException(+ "Standard Normalizer standard deviation must be positive " + "| avg = 0.0,std = -1.0");- NormalizerException ex = SolrTestCaseJ4.expectThrows(NormalizerException.class,- () -> implTestStandard(params, 0.0f, -1f)- );+ NormalizerException ex =+ SolrTestCaseJ4.expectThrows(+ NormalizerException.class, () -> implTestStandard(params, 0.0f, -1f));assertEquals(expectedException.toString(), ex.toString());}@Testpublic void testInvalidSTD3() {- final Map<String,Object> params = new HashMap<String,Object>();+ final Map<String, Object> params = new HashMap<String, Object>();params.put("avg", "1f");params.put("std", "0f");final NormalizerException expectedException =- new NormalizerException("Standard Normalizer standard deviation must be positive "- + "| avg = 1.0,std = 0.0");+ new NormalizerException(+ "Standard Normalizer standard deviation must be positive " + "| avg = 1.0,std = 0.0");- NormalizerException ex = SolrTestCaseJ4.expectThrows(NormalizerException.class,- () -> implTestStandard(params, 1f, 0f)- );+ NormalizerException ex =+ SolrTestCaseJ4.expectThrows(+ NormalizerException.class, () -> implTestStandard(params, 1f, 0f));assertEquals(expectedException.toString(), ex.toString());}@Testpublic void testNormalizer() {- Map<String,Object> params = new HashMap<String,Object>();+ Map<String, Object> params = new HashMap<String, Object>();params.put("avg", "0f");params.put("std", "1f");- final Normalizer identity =- implTestStandard(params,- 0f,- 1f);+ final Normalizer identity = implTestStandard(params, 0f, 1f);float value = 8;assertEquals(value, identity.normalize(value), 0.0001);value = 150;assertEquals(value, identity.normalize(value), 0.0001);- params = new HashMap<String,Object>();+ params = new HashMap<String, Object>();params.put("avg", "10f");params.put("std", "1.5f");- final Normalizer norm = Normalizer.getInstance(- solrResourceLoader,- StandardNormalizer.class.getName(),- params);+ final Normalizer norm =+ Normalizer.getInstance(solrResourceLoader, StandardNormalizer.class.getName(), params);- for (final float v : new float[] {10f, 20f, 25f, 30f, 31f, 40f, 42f, 100f,- 10000000f}) {+ for (final float v : new float[] {10f, 20f, 25f, 30f, 31f, 40f, 42f, 100f, 10000000f}) {assertEquals((v - 10f) / (1.5f), norm.normalize(v), 0.0001);}}@@ -129,10 +119,12 @@ public class TestStandardNormalizer {n1.setStd(3.0f);final Map<String, Object> params = n1.paramsToMap();- final StandardNormalizer n2 = (StandardNormalizer) Normalizer.getInstance(- new SolrResourceLoader(Paths.get("").toAbsolutePath()),- StandardNormalizer.class.getName(),- params);+ final StandardNormalizer n2 =+ (StandardNormalizer)+ Normalizer.getInstance(+ new SolrResourceLoader(Paths.get("").toAbsolutePath()),+ StandardNormalizer.class.getName(),+ params);assertEquals(n1.getAvg(), n2.getAvg(), 1e-6);assertEquals(n1.getStd(), n2.getStd(), 1e-6);}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/response/transform/TestFeatureLoggerTransformer.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/response/transform/TestFeatureLoggerTransformer.javaindex c7da81c7169..cd1067dd7f3 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/response/transform/TestFeatureLoggerTransformer.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/response/transform/TestFeatureLoggerTransformer.java@@ -17,7 +17,6 @@package org.apache.solr.ltr.response.transform;import java.util.Random;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.feature.SolrFeature;@@ -32,25 +31,42 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {public void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "w1", "description", "w5", "popularity",- "1"));- assertU(adoc("id", "2", "title", "w2 2asd asdd didid", "description",- "w2 2asd asdd didid", "popularity", "2"));- assertU(adoc("id", "3", "title", "w1", "description", "w5", "popularity",- "3"));- assertU(adoc("id", "4", "title", "w1", "description", "w1", "popularity",- "6"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity",- "5"));- assertU(adoc("id", "6", "title", "w6 w2", "description", "w1 w2",- "popularity", "6"));- assertU(adoc("id", "7", "title", "w1 w2 w3 w4 w5", "description",- "w6 w2 w3 w4 w5 w8", "popularity", "88888"));- assertU(adoc("id", "8", "title", "w1 w1 w1 w2 w2 w8", "description",- "w1 w1 w1 w2 w2 w5", "popularity", "88888"));+ assertU(adoc("id", "1", "title", "w1", "description", "w5", "popularity", "1"));+ assertU(+ adoc(+ "id",+ "2",+ "title",+ "w2 2asd asdd didid",+ "description",+ "w2 2asd asdd didid",+ "popularity",+ "2"));+ assertU(adoc("id", "3", "title", "w1", "description", "w5", "popularity", "3"));+ assertU(adoc("id", "4", "title", "w1", "description", "w1", "popularity", "6"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));+ assertU(adoc("id", "6", "title", "w6 w2", "description", "w1 w2", "popularity", "6"));+ assertU(+ adoc(+ "id",+ "7",+ "title",+ "w1 w2 w3 w4 w5",+ "description",+ "w6 w2 w3 w4 w5 w8",+ "popularity",+ "88888"));+ assertU(+ adoc(+ "id",+ "8",+ "title",+ "w1 w1 w1 w2 w2 w8",+ "description",+ "w1 w1 w1 w2 w2 w5",+ "popularity",+ "88888"));assertU(commit());--}@After@@ -59,39 +75,57 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {}protected void loadFeaturesAndModels() throws Exception {- loadFeature("featureA1", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=popularity}88888\"]}");- loadFeature("featureA2", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=title}${user_query}\"]}");- loadFeature("featureAB", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=title}${user_query}\"]}");- loadFeature("featureB1", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=popularity}6\"]}");- loadFeature("featureB2", SolrFeature.class.getName(),+ loadFeature(+ "featureA1", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=popularity}88888\"]}");+ loadFeature(+ "featureA2", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=title}${user_query}\"]}");+ loadFeature(+ "featureAB", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=title}${user_query}\"]}");+ loadFeature("featureB1", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=popularity}6\"]}");+ loadFeature(+ "featureB2",+ SolrFeature.class.getName(),"{\"fq\":[\"{!terms f=description}${user_query}\"]}");- loadFeature("featureC1", SolrFeature.class.getName(),"featureStore2",+ loadFeature(+ "featureC1",+ SolrFeature.class.getName(),+ "featureStore2","{\"fq\":[\"{!terms f=popularity}6\"]}");- loadFeature("featureC2", SolrFeature.class.getName(),"featureStore2",+ loadFeature(+ "featureC2",+ SolrFeature.class.getName(),+ "featureStore2","{\"fq\":[\"{!terms f=description}${user_query}\"]}");- loadFeature("featureC3", SolrFeature.class.getName(),"featureStore2",+ loadFeature(+ "featureC3",+ SolrFeature.class.getName(),+ "featureStore2","{\"fq\":[\"{!terms f=description}${user_query}\"]}");- loadModel("modelA", LinearModel.class.getName(),- new String[]{"featureA1", "featureA2", "featureAB"},+ loadModel(+ "modelA",+ LinearModel.class.getName(),+ new String[] {"featureA1", "featureA2", "featureAB"},"{\"weights\":{\"featureA1\":3.0, \"featureA2\":9.0, \"featureAB\":27.0}}");- loadModel("modelB", LinearModel.class.getName(),- new String[]{"featureB1", "featureB2", "featureAB"},+ loadModel(+ "modelB",+ LinearModel.class.getName(),+ new String[] {"featureB1", "featureB2", "featureAB"},"{\"weights\":{\"featureB1\":2.0, \"featureB2\":4.0, \"featureAB\":8.0}}");-- loadModel("modelC", LinearModel.class.getName(),- new String[]{"featureC1", "featureC2"},"featureStore2",++ loadModel(+ "modelC",+ LinearModel.class.getName(),+ new String[] {"featureC1", "featureC2"},+ "featureStore2","{\"weights\":{\"featureC1\":5.0, \"featureC2\":25.0}}");}-+@Testpublic void interleaving_featureTransformer_shouldWorkInSparseFormat() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]loadFeaturesAndModels();final SolrQuery query = new SolrQuery();@@ -100,8 +134,7 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {query.add("rows", "10");query.add("debugQuery", "true");query.add("fq", "{!terms f=title}w1"); // 1,3,4,7,8- query.add("rq",- "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");+ query.add("rq", "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");/*Doc1 = "featureB2=1.0", ScoreA(0), ScoreB(4)@@ -111,24 +144,33 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {Doc8 = "featureA1=1.0,featureB2=1.0", ScoreA(3), ScoreB(4)ModelARerankedList = [7,8,1,3,4]ModelBRerankedList = [7,1,3,8,4]-+Random Boolean Choices Generation from Seed: [0,1,1]*/- String[] expectedFeatureVectors = new String[]{"featureA1\\=1.0\\,featureA2\\=1.0\\,featureAB\\=1.0\\,featureB2\\=1.0", "featureB2\\=1.0", "featureB2\\=1.0", "featureA1\\=1.0\\,featureB2\\=1.0", "featureB1\\=1.0"};- int[] expectedInterleaved = new int[]{7, 1, 3, 8, 4};+ String[] expectedFeatureVectors =+ new String[] {+ "featureA1\\=1.0\\,featureA2\\=1.0\\,featureAB\\=1.0\\,featureB2\\=1.0",+ "featureB2\\=1.0",+ "featureB2\\=1.0",+ "featureA1\\=1.0\\,featureB2\\=1.0",+ "featureB1\\=1.0"+ };+ int[] expectedInterleaved = new int[] {7, 1, 3, 8, 4};String[] tests = new String[11];tests[0] = "/response/numFound/==5";for (int i = 1; i <= 5; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 5] = "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];+ tests[i + 5] =+ "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];}assertJQ("/query" + query.toQueryString(), tests);}@Testpublic void interleaving_featureTransformer_shouldWorkInDenseFormat() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]loadFeaturesAndModels();final SolrQuery query = new SolrQuery();@@ -137,8 +179,7 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {query.add("rows", "10");query.add("debugQuery", "true");query.add("fq", "{!terms f=title}w1"); // 1,3,4,7,8- query.add("rq",- "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");+ query.add("rq", "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");/*Doc1 = "featureB2=1.0", ScoreA(0), ScoreB(4)@@ -148,28 +189,34 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {Doc8 = "featureA1=1.0,featureB2=1.0", ScoreA(3), ScoreB(4)ModelARerankedList = [7,8,1,3,4]ModelBRerankedList = [7,1,3,8,4]-+Random Boolean Choices Generation from Seed: [0,1,1]*/- String[] expectedFeatureVectors = new String[]{"featureA1\\=1.0\\,featureA2\\=1.0\\,featureAB\\=1.0\\,featureB1\\=0.0\\,featureB2\\=1.0",- "featureA1\\=0.0\\,featureA2\\=0.0\\,featureAB\\=0.0\\,featureB1\\=0.0\\,featureB2\\=1.0",- "featureA1\\=0.0\\,featureA2\\=0.0\\,featureAB\\=0.0\\,featureB1\\=0.0\\,featureB2\\=1.0",- "featureA1\\=1.0\\,featureA2\\=0.0\\,featureAB\\=0.0\\,featureB1\\=0.0\\,featureB2\\=1.0",- "featureA1\\=0.0\\,featureA2\\=0.0\\,featureAB\\=0.0\\,featureB1\\=1.0\\,featureB2\\=0.0"};- int[] expectedInterleaved = new int[]{7, 1, 3, 8, 4};+ String[] expectedFeatureVectors =+ new String[] {+ "featureA1\\=1.0\\,featureA2\\=1.0\\,featureAB\\=1.0\\,featureB1\\=0.0\\,featureB2\\=1.0",+ "featureA1\\=0.0\\,featureA2\\=0.0\\,featureAB\\=0.0\\,featureB1\\=0.0\\,featureB2\\=1.0",+ "featureA1\\=0.0\\,featureA2\\=0.0\\,featureAB\\=0.0\\,featureB1\\=0.0\\,featureB2\\=1.0",+ "featureA1\\=1.0\\,featureA2\\=0.0\\,featureAB\\=0.0\\,featureB1\\=0.0\\,featureB2\\=1.0",+ "featureA1\\=0.0\\,featureA2\\=0.0\\,featureAB\\=0.0\\,featureB1\\=1.0\\,featureB2\\=0.0"+ };+ int[] expectedInterleaved = new int[] {7, 1, 3, 8, 4};String[] tests = new String[11];tests[0] = "/response/numFound/==5";for (int i = 1; i <= 5; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 5] = "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];+ tests[i + 5] =+ "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];}assertJQ("/query" + query.toQueryString(), tests);}@Test- public void interleaving_explicitNewFeatureStore_shouldExtractAllFeaturesFromNewStore() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ public void interleaving_explicitNewFeatureStore_shouldExtractAllFeaturesFromNewStore()+ throws Exception {+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]loadFeaturesAndModels();final SolrQuery query = new SolrQuery();@@ -178,8 +225,7 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {query.add("rows", "10");query.add("debugQuery", "true");query.add("fq", "{!terms f=title}w1"); // 1,3,4,7,8- query.add("rq",- "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");+ query.add("rq", "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");/*Doc1 = "featureB2=1.0", ScoreA(0), ScoreB(4)@@ -189,29 +235,35 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {Doc8 = "featureA1=1.0,featureB2=1.0", ScoreA(3), ScoreB(4)ModelARerankedList = [7,8,1,3,4]ModelBRerankedList = [7,1,3,8,4]-+Random Boolean Choices Generation from Seed: [0,1,1]*/- String[] expectedFeatureVectors = new String[]{- "featureC1\\=0.0\\,featureC2\\=1.0\\,featureC3\\=1.0",- "featureC1\\=0.0\\,featureC2\\=1.0\\,featureC3\\=1.0",- "featureC1\\=0.0\\,featureC2\\=1.0\\,featureC3\\=1.0",- "featureC1\\=0.0\\,featureC2\\=1.0\\,featureC3\\=1.0",- "featureC1\\=1.0\\,featureC2\\=0.0\\,featureC3\\=0.0"};- int[] expectedInterleaved = new int[]{7, 1, 3, 8, 4};+ String[] expectedFeatureVectors =+ new String[] {+ "featureC1\\=0.0\\,featureC2\\=1.0\\,featureC3\\=1.0",+ "featureC1\\=0.0\\,featureC2\\=1.0\\,featureC3\\=1.0",+ "featureC1\\=0.0\\,featureC2\\=1.0\\,featureC3\\=1.0",+ "featureC1\\=0.0\\,featureC2\\=1.0\\,featureC3\\=1.0",+ "featureC1\\=1.0\\,featureC2\\=0.0\\,featureC3\\=0.0"+ };+ int[] expectedInterleaved = new int[] {7, 1, 3, 8, 4};String[] tests = new String[16];tests[0] = "/response/numFound/==5";for (int i = 1; i <= 5; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 10] = "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];+ tests[i + 10] =+ "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];}assertJQ("/query" + query.toQueryString(), tests);}-+@Test- public void interleaving_withOriginalRankingAndExplicitFeatureStore_shouldReturnNewCalculatedFeatureVector() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ public void+ interleaving_withOriginalRankingAndExplicitFeatureStore_shouldReturnNewCalculatedFeatureVector()+ throws Exception {+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]loadFeaturesAndModels();final SolrQuery query = new SolrQuery();@@ -220,8 +272,8 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {query.add("rows", "10");query.add("debugQuery", "true");query.add("fq", "{!terms f=title}w1"); // 1,3,4,7,8- query.add("rq",- "{!ltr model=modelA model=_OriginalRanking_ reRankDocs=10 efi.user_query='w5'}");+ query.add(+ "rq", "{!ltr model=modelA model=_OriginalRanking_ reRankDocs=10 efi.user_query='w5'}");/*Doc1 = "featureB2=1.0", ScoreA(0)@@ -229,32 +281,35 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {Doc4 = "featureB1=1.0", ScoreA(0)Doc7 ="featureA1=1.0,featureA2=1.0,featureAB=1.0,featureB2=1.0", ScoreA(39)Doc8 = "featureA1=1.0,featureB2=1.0", ScoreA(3)-+ModelARerankedList = [7,8,1,3,4]_OriginalRanking_ = [1,3,4,7,8]-+Random Boolean Choices Generation from Seed: [0,1,1]*/- String[] expectedFeatureVectors = new String[]{- "featureC2\\=1.0\\,featureC3\\=1.0",- "featureC2\\=1.0\\,featureC3\\=1.0",- "featureC2\\=1.0\\,featureC3\\=1.0",- "featureC2\\=1.0\\,featureC3\\=1.0",- "featureC1\\=1.0"};- int[] expectedInterleaved = new int[]{7, 1, 3, 8, 4};+ String[] expectedFeatureVectors =+ new String[] {+ "featureC2\\=1.0\\,featureC3\\=1.0",+ "featureC2\\=1.0\\,featureC3\\=1.0",+ "featureC2\\=1.0\\,featureC3\\=1.0",+ "featureC2\\=1.0\\,featureC3\\=1.0",+ "featureC1\\=1.0"+ };+ int[] expectedInterleaved = new int[] {7, 1, 3, 8, 4};String[] tests = new String[16];tests[0] = "/response/numFound/==5";for (int i = 1; i <= 5; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";if (expectedFeatureVectors[(i - 1)] != null) {- tests[i + 10] = "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];+ tests[i + 10] =+ "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];}}assertJQ("/query" + query.toQueryString(), tests);- int[] nullFeatureVectorIndexes = new int[]{1, 2, 4};+ int[] nullFeatureVectorIndexes = new int[] {1, 2, 4};for (int index : nullFeatureVectorIndexes) {TeamDraftInterleaving.setRANDOM(new Random(10101010));String[] nullFeatureVectorTests = new String[1];@@ -265,14 +320,14 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {assertEquals("Path not found: /response/docs/[" + index + "]/features", e.getMessage());continue;}-}-}@Test- public void interleaving_modelsFromDifferentFeatureStores_shouldLogFeaturesCorrectly() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ public void interleaving_modelsFromDifferentFeatureStores_shouldLogFeaturesCorrectly()+ throws Exception {+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]loadFeaturesAndModels();final SolrQuery query = new SolrQuery();@@ -281,8 +336,7 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {query.add("rows", "10");query.add("debugQuery", "true");query.add("fq", "{!terms f=title}w1"); // 1,3,4,7,8- query.add("rq",- "{!ltr model=modelA model=modelC reRankDocs=10 efi.user_query='w5'}");+ query.add("rq", "{!ltr model=modelA model=modelC reRankDocs=10 efi.user_query='w5'}");/*Doc1 = "featureC2=1.0", ScoreA(0), ScoreC(25)@@ -292,29 +346,35 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {Doc8 = "featureA1=1.0,featureC2=1.0", ScoreA(3), ScoreC(25)ModelARerankedList = [7,8,1,3,4]ModelCRerankedList = [1,3,8,4,7]-+Random Boolean Choices Generation from Seed: [0,1,1]*/- String[] expectedFeatureVectors = new String[]{- "featureA1\\=1.0\\,featureA2\\=1.0\\,featureAB\\=1.0\\,featureB2\\=1.0",- "featureC2\\=1.0\\,featureC3\\=1.0",- "featureC2\\=1.0\\,featureC3\\=1.0",- "featureA1\\=1.0\\,featureB2\\=1.0",- "featureC1\\=1.0"};- int[] expectedInterleaved = new int[]{7, 1, 3, 8, 4};+ String[] expectedFeatureVectors =+ new String[] {+ "featureA1\\=1.0\\,featureA2\\=1.0\\,featureAB\\=1.0\\,featureB2\\=1.0",+ "featureC2\\=1.0\\,featureC3\\=1.0",+ "featureC2\\=1.0\\,featureC3\\=1.0",+ "featureA1\\=1.0\\,featureB2\\=1.0",+ "featureC1\\=1.0"+ };+ int[] expectedInterleaved = new int[] {7, 1, 3, 8, 4};String[] tests = new String[16];tests[0] = "/response/numFound/==5";for (int i = 1; i <= 5; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 10] = "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];+ tests[i + 10] =+ "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];}assertJQ("/query" + query.toQueryString(), tests);}@Test- public void interleaving_featureLoggerFromNewFeatureStoreWithDifferentEfi_shouldReturnNewCalculatedFeatureVector() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ public void+ interleaving_featureLoggerFromNewFeatureStoreWithDifferentEfi_shouldReturnNewCalculatedFeatureVector()+ throws Exception {+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]loadFeaturesAndModels();final SolrQuery query = new SolrQuery();@@ -323,8 +383,7 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {query.add("rows", "10");query.add("debugQuery", "true");query.add("fq", "{!terms f=title}w1"); // 1,3,4,7,8- query.add("rq",- "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");+ query.add("rq", "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");/*Doc1 = "featureB2=1.0", ScoreA(0), ScoreB(4)@@ -334,29 +393,28 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {Doc8 = "featureA1=1.0,featureB2=1.0", ScoreA(3), ScoreB(4)ModelARerankedList = [7,8,1,3,4]ModelBRerankedList = [7,1,3,8,4]-+Random Boolean Choices Generation from Seed: [0,1,1]*/- String[] expectedFeatureVectors = new String[]{- "featureC2\\=1.0\\,featureC3\\=1.0",- "",- "",- "",- ""};- int[] expectedInterleaved = new int[]{7, 1, 3, 8, 4};+ String[] expectedFeatureVectors =+ new String[] {"featureC2\\=1.0\\,featureC3\\=1.0", "", "", "", ""};+ int[] expectedInterleaved = new int[] {7, 1, 3, 8, 4};String[] tests = new String[16];tests[0] = "/response/numFound/==5";for (int i = 1; i <= 5; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 10] = "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];+ tests[i + 10] =+ "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];}assertJQ("/query" + query.toQueryString(), tests);}@Test- public void interleaving_explicitFeatureStoreReusableFromModel_shouldLogFeaturesCorrectly() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ public void interleaving_explicitFeatureStoreReusableFromModel_shouldLogFeaturesCorrectly()+ throws Exception {+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]loadFeaturesAndModels();final SolrQuery query = new SolrQuery();@@ -365,8 +423,7 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {query.add("rows", "10");query.add("debugQuery", "true");query.add("fq", "{!terms f=title}w1"); // 1,3,4,7,8- query.add("rq",- "{!ltr model=modelA model=modelC reRankDocs=10 efi.user_query='w5'}");+ query.add("rq", "{!ltr model=modelA model=modelC reRankDocs=10 efi.user_query='w5'}");/*Doc1 = "featureC2=1.0", ScoreA(0), ScoreC(25)@@ -376,25 +433,26 @@ public class TestFeatureLoggerTransformer extends TestRerankBase {Doc8 = "featureA1=1.0,featureC2=1.0", ScoreA(3), ScoreC(25)ModelARerankedList = [7,8,1,3,4]ModelCRerankedList = [1,3,8,4,7]-+Random Boolean Choices Generation from Seed: [0,1,1]*/- String[] expectedFeatureVectors = new String[]{- "featureC2\\=1.0\\,featureC3\\=1.0",- "featureC2\\=1.0\\,featureC3\\=1.0",- "featureC2\\=1.0\\,featureC3\\=1.0",- "featureC2\\=1.0\\,featureC3\\=1.0",- "featureC1\\=1.0"};- int[] expectedInterleaved = new int[]{7, 1, 3, 8, 4};+ String[] expectedFeatureVectors =+ new String[] {+ "featureC2\\=1.0\\,featureC3\\=1.0",+ "featureC2\\=1.0\\,featureC3\\=1.0",+ "featureC2\\=1.0\\,featureC3\\=1.0",+ "featureC2\\=1.0\\,featureC3\\=1.0",+ "featureC1\\=1.0"+ };+ int[] expectedInterleaved = new int[] {7, 1, 3, 8, 4};String[] tests = new String[16];tests[0] = "/response/numFound/==5";for (int i = 1; i <= 5; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 10] = "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];+ tests[i + 10] =+ "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];}assertJQ("/query" + query.toQueryString(), tests);}--}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/response/transform/TestInterleavingTransformer.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/response/transform/TestInterleavingTransformer.javaindex f4601a73635..8a50e5dde07 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/response/transform/TestInterleavingTransformer.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/response/transform/TestInterleavingTransformer.java@@ -17,7 +17,6 @@package org.apache.solr.ltr.response.transform;import java.util.Random;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.feature.SolrFeature;@@ -32,25 +31,42 @@ public class TestInterleavingTransformer extends TestRerankBase {public void before() throws Exception {setuptest(false);- assertU(adoc("id", "1", "title", "w1", "description", "w5", "popularity",- "1"));- assertU(adoc("id", "2", "title", "w2 2asd asdd didid", "description",- "w2 2asd asdd didid", "popularity", "2"));- assertU(adoc("id", "3", "title", "w1", "description", "w5", "popularity",- "3"));- assertU(adoc("id", "4", "title", "w1", "description", "w1", "popularity",- "6"));- assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity",- "5"));- assertU(adoc("id", "6", "title", "w6 w2", "description", "w1 w2",- "popularity", "6"));- assertU(adoc("id", "7", "title", "w1 w2 w3 w4 w5", "description",- "w6 w2 w3 w4 w5 w8", "popularity", "88888"));- assertU(adoc("id", "8", "title", "w1 w1 w1 w2 w2 w8", "description",- "w1 w1 w1 w2 w2 w5", "popularity", "88888"));+ assertU(adoc("id", "1", "title", "w1", "description", "w5", "popularity", "1"));+ assertU(+ adoc(+ "id",+ "2",+ "title",+ "w2 2asd asdd didid",+ "description",+ "w2 2asd asdd didid",+ "popularity",+ "2"));+ assertU(adoc("id", "3", "title", "w1", "description", "w5", "popularity", "3"));+ assertU(adoc("id", "4", "title", "w1", "description", "w1", "popularity", "6"));+ assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));+ assertU(adoc("id", "6", "title", "w6 w2", "description", "w1 w2", "popularity", "6"));+ assertU(+ adoc(+ "id",+ "7",+ "title",+ "w1 w2 w3 w4 w5",+ "description",+ "w6 w2 w3 w4 w5 w8",+ "popularity",+ "88888"));+ assertU(+ adoc(+ "id",+ "8",+ "title",+ "w1 w1 w1 w2 w2 w8",+ "description",+ "w1 w1 w1 w2 w2 w5",+ "popularity",+ "88888"));assertU(commit());--}@After@@ -59,37 +75,52 @@ public class TestInterleavingTransformer extends TestRerankBase {}protected void loadFeaturesAndModelsForInterleaving() throws Exception {- loadFeature("featureA1", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=popularity}88888\"]}");- loadFeature("featureA2", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=title}${user_query}\"]}");- loadFeature("featureAB", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=title}${user_query}\"]}");- loadFeature("featureB1", SolrFeature.class.getName(),- "{\"fq\":[\"{!terms f=popularity}6\"]}");- loadFeature("featureB2", SolrFeature.class.getName(),+ loadFeature(+ "featureA1", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=popularity}88888\"]}");+ loadFeature(+ "featureA2", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=title}${user_query}\"]}");+ loadFeature(+ "featureAB", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=title}${user_query}\"]}");+ loadFeature("featureB1", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=popularity}6\"]}");+ loadFeature(+ "featureB2",+ SolrFeature.class.getName(),"{\"fq\":[\"{!terms f=description}${user_query}\"]}");- loadFeature("featureC1", SolrFeature.class.getName(),"featureStore2",+ loadFeature(+ "featureC1",+ SolrFeature.class.getName(),+ "featureStore2","{\"fq\":[\"{!terms f=popularity}6\"]}");- loadFeature("featureC2", SolrFeature.class.getName(),"featureStore2",+ loadFeature(+ "featureC2",+ SolrFeature.class.getName(),+ "featureStore2","{\"fq\":[\"{!terms f=popularity}1\"]}");- loadModel("modelA", LinearModel.class.getName(),- new String[]{"featureA1", "featureA2", "featureAB"},+ loadModel(+ "modelA",+ LinearModel.class.getName(),+ new String[] {"featureA1", "featureA2", "featureAB"},"{\"weights\":{\"featureA1\":3.0, \"featureA2\":9.0, \"featureAB\":27.0}}");- loadModel("modelB", LinearModel.class.getName(),- new String[]{"featureB1", "featureB2", "featureAB"},+ loadModel(+ "modelB",+ LinearModel.class.getName(),+ new String[] {"featureB1", "featureB2", "featureAB"},"{\"weights\":{\"featureB1\":2.0, \"featureB2\":4.0, \"featureAB\":8.0}}");- loadModel("modelC", LinearModel.class.getName(),- new String[]{"featureC1", "featureC2"},"featureStore2",+ loadModel(+ "modelC",+ LinearModel.class.getName(),+ new String[] {"featureC1", "featureC2"},+ "featureStore2","{\"weights\":{\"featureC1\":5.0, \"featureC2\":25.0}}");}@Testpublic void interleavingTransformer_shouldReturnInterleavingPickInTheResults() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]loadFeaturesAndModelsForInterleaving();final SolrQuery query = new SolrQuery();@@ -98,8 +129,7 @@ public class TestInterleavingTransformer extends TestRerankBase {query.add("rows", "10");query.add("debugQuery", "true");query.add("fq", "{!terms f=title}w1"); // 1,3,4,7,8- query.add("rq",- "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");+ query.add("rq", "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");/*Doc1 = "featureB2=1.0", ScoreA(0), ScoreB(4)@@ -109,25 +139,31 @@ public class TestInterleavingTransformer extends TestRerankBase {Doc8 = "featureA1=1.0,featureB2=1.0", ScoreA(3), ScoreB(4)ModelARerankedList = [7,8,1,3,4]ModelBRerankedList = [7,1,3,8,4]-+Random Boolean Choices Generation from Seed: [0,1,1]*/- String[] expectedInterleavingPicks = new String[]{"modelA", "modelB", "modelB", "modelA", "modelB"};- int[] expectedInterleaved = new int[]{7, 1, 3, 8, 4};+ String[] expectedInterleavingPicks =+ new String[] {"modelA", "modelB", "modelB", "modelA", "modelB"};+ int[] expectedInterleaved = new int[] {7, 1, 3, 8, 4};String[] tests = new String[11];tests[0] = "/response/numFound/==5";for (int i = 1; i <= 5; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 5] = "/response/docs/[" + (i - 1) + "]/interleavingPick==" + expectedInterleavingPicks[(i - 1)];+ tests[i + 5] =+ "/response/docs/["+ + (i - 1)+ + "]/interleavingPick=="+ + expectedInterleavingPicks[(i - 1)];}assertJQ("/query" + query.toQueryString(), tests);-}@Test- public void interleavingTransformerWithOriginalRanking_shouldReturnInterleavingPickInTheResults() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ public void interleavingTransformerWithOriginalRanking_shouldReturnInterleavingPickInTheResults()+ throws Exception {+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]loadFeaturesAndModelsForInterleaving();final SolrQuery query = new SolrQuery();@@ -136,8 +172,8 @@ public class TestInterleavingTransformer extends TestRerankBase {query.add("rows", "10");query.add("debugQuery", "true");query.add("fq", "{!terms f=title}w1"); // 1,3,4,7,8- query.add("rq",- "{!ltr model=modelA model=_OriginalRanking_ reRankDocs=10 efi.user_query='w5'}");+ query.add(+ "rq", "{!ltr model=modelA model=_OriginalRanking_ reRankDocs=10 efi.user_query='w5'}");/*Doc1 = "featureB2=1.0", ScoreA(0)@@ -145,31 +181,36 @@ public class TestInterleavingTransformer extends TestRerankBase {Doc4 = "featureB1=1.0", ScoreA(0)Doc7 ="featureA1=1.0,featureA2=1.0,featureAB=1.0,featureB2=1.0", ScoreA(39)Doc8 = "featureA1=1.0,featureB2=1.0", ScoreA(3)-+ModelARerankedList = [7,8,1,3,4]OriginalRanking = [1,3,4,7,8]-+Random Boolean Choices Generation from Seed: [0,1,1]*/- String[] expectedInterleavingPicks = new String[]{"modelA", "_OriginalRanking_", "_OriginalRanking_", "modelA", "_OriginalRanking_"};- int[] expectedInterleaved = new int[]{7, 1, 3, 8, 4};+ String[] expectedInterleavingPicks =+ new String[] {+ "modelA", "_OriginalRanking_", "_OriginalRanking_", "modelA", "_OriginalRanking_"+ };+ int[] expectedInterleaved = new int[] {7, 1, 3, 8, 4};String[] tests = new String[11];tests[0] = "/response/numFound/==5";for (int i = 1; i <= 5; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 5] = "/response/docs/[" + (i - 1) + "]/interleavingPick==" + expectedInterleavingPicks[(i - 1)];+ tests[i + 5] =+ "/response/docs/["+ + (i - 1)+ + "]/interleavingPick=="+ + expectedInterleavingPicks[(i - 1)];}assertJQ("/query" + query.toQueryString(), tests);-}--@Testpublic void interleavingTransformer_shouldBeCompatibleWithFeatureTransformer() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]loadFeaturesAndModelsForInterleaving();final SolrQuery query = new SolrQuery();@@ -178,8 +219,7 @@ public class TestInterleavingTransformer extends TestRerankBase {query.add("rows", "10");query.add("debugQuery", "true");query.add("fq", "{!terms f=title}w1"); // 1,3,4,7,8- query.add("rq",- "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");+ query.add("rq", "{!ltr model=modelA model=modelB reRankDocs=10 efi.user_query='w5'}");/*Doc1 = "featureB2=1.0", ScoreA(0), ScoreB(4)@@ -189,31 +229,41 @@ public class TestInterleavingTransformer extends TestRerankBase {Doc8 = "featureA1=1.0,featureB2=1.0", ScoreA(3), ScoreB(4)ModelARerankedList = [7,8,1,3,4]ModelBRerankedList = [7,1,3,8,4]-+Random Boolean Choices Generation from Seed: [0,1,1]*/- String[] expectedFeatureVectors = new String[]{- "featureA1\\=1.0\\,featureA2\\=1.0\\,featureAB\\=1.0\\,featureB2\\=1.0",- "featureB2\\=1.0",- "featureB2\\=1.0",- "featureA1\\=1.0\\,featureB2\\=1.0",- "featureB1\\=1.0"};- String[] expectedInterleavingPicks = new String[]{"modelA", "modelB", "modelB", "modelA", "modelB"};- int[] expectedInterleaved = new int[]{7, 1, 3, 8, 4};+ String[] expectedFeatureVectors =+ new String[] {+ "featureA1\\=1.0\\,featureA2\\=1.0\\,featureAB\\=1.0\\,featureB2\\=1.0",+ "featureB2\\=1.0",+ "featureB2\\=1.0",+ "featureA1\\=1.0\\,featureB2\\=1.0",+ "featureB1\\=1.0"+ };+ String[] expectedInterleavingPicks =+ new String[] {"modelA", "modelB", "modelB", "modelA", "modelB"};+ int[] expectedInterleaved = new int[] {7, 1, 3, 8, 4};String[] tests = new String[16];tests[0] = "/response/numFound/==5";for (int i = 1; i <= 5; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 5] = "/response/docs/[" + (i - 1) + "]/interleavingPick==" + expectedInterleavingPicks[(i - 1)];- tests[i + 10] = "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];+ tests[i + 5] =+ "/response/docs/["+ + (i - 1)+ + "]/interleavingPick=="+ + expectedInterleavingPicks[(i - 1)];+ tests[i + 10] =+ "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];}assertJQ("/query" + query.toQueryString(), tests);}@Test- public void interleavingTransformerWithOriginalRanking_shouldBeCompatibleWithFeatureTransformer() throws Exception {- TeamDraftInterleaving.setRANDOM(new Random(10101010));//Random Boolean Choices Generation from Seed: [0,1,1]+ public void interleavingTransformerWithOriginalRanking_shouldBeCompatibleWithFeatureTransformer()+ throws Exception {+ TeamDraftInterleaving.setRANDOM(+ new Random(10101010)); // Random Boolean Choices Generation from Seed: [0,1,1]loadFeaturesAndModelsForInterleaving();final SolrQuery query = new SolrQuery();@@ -222,8 +272,8 @@ public class TestInterleavingTransformer extends TestRerankBase {query.add("rows", "10");query.add("debugQuery", "true");query.add("fq", "{!terms f=title}w1"); // 1,3,4,7,8- query.add("rq",- "{!ltr model=modelA model=_OriginalRanking_ reRankDocs=10 efi.user_query='w5'}");+ query.add(+ "rq", "{!ltr model=modelA model=_OriginalRanking_ reRankDocs=10 efi.user_query='w5'}");/*Doc1 = "featureB2=1.0", ScoreA(0)@@ -231,38 +281,47 @@ public class TestInterleavingTransformer extends TestRerankBase {Doc4 = "featureB1=1.0", ScoreA(0)Doc7 ="featureA1=1.0,featureA2=1.0,featureAB=1.0,featureB2=1.0", ScoreA(39)Doc8 = "featureA1=1.0,featureB2=1.0", ScoreA(3)-+ModelARerankedList = [7,8,1,3,4]_OriginalRanking_ = [1,3,4,7,8]-+Random Boolean Choices Generation from Seed: [0,1,1]*/- String[] expectedFeatureVectors = new String[]{- "featureA1\\=1.0\\,featureA2\\=1.0\\,featureAB\\=1.0\\,featureB2\\=1.0",- null,- null,- "featureA1\\=1.0\\,featureB2\\=1.0",- null};- String[] expectedInterleavingPicks = new String[]{"modelA", "_OriginalRanking_", "_OriginalRanking_", "modelA", "_OriginalRanking_"};- int[] expectedInterleaved = new int[]{7, 1, 3, 8, 4};+ String[] expectedFeatureVectors =+ new String[] {+ "featureA1\\=1.0\\,featureA2\\=1.0\\,featureAB\\=1.0\\,featureB2\\=1.0",+ null,+ null,+ "featureA1\\=1.0\\,featureB2\\=1.0",+ null+ };+ String[] expectedInterleavingPicks =+ new String[] {+ "modelA", "_OriginalRanking_", "_OriginalRanking_", "modelA", "_OriginalRanking_"+ };+ int[] expectedInterleaved = new int[] {7, 1, 3, 8, 4};String[] tests = new String[16];tests[0] = "/response/numFound/==5";for (int i = 1; i <= 5; i++) {tests[i] = "/response/docs/[" + (i - 1) + "]/id==\"" + expectedInterleaved[(i - 1)] + "\"";- tests[i + 5] = "/response/docs/[" + (i - 1) + "]/interleavingPick==" + expectedInterleavingPicks[(i - 1)];+ tests[i + 5] =+ "/response/docs/["+ + (i - 1)+ + "]/interleavingPick=="+ + expectedInterleavingPicks[(i - 1)];if (expectedFeatureVectors[(i - 1)] != null) {- tests[i + 10] = "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];+ tests[i + 10] =+ "/response/docs/[" + (i - 1) + "]/features==" + expectedFeatureVectors[(i - 1)];}}assertJQ("/query" + query.toQueryString(), tests);- int[] nullFeatureVectorIndexes = new int[]{1, 2, 4};+ int[] nullFeatureVectorIndexes = new int[] {1, 2, 4};for (int index : nullFeatureVectorIndexes) {TeamDraftInterleaving.setRANDOM(new Random(10101010));assertJQ("/query" + query.toQueryString(), "!/response/docs/[" + index + "]/features==");}}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/store/rest/TestManagedFeatureStore.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/store/rest/TestManagedFeatureStore.javaindex 1cd4f613d6a..137500279ae 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/store/rest/TestManagedFeatureStore.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/store/rest/TestManagedFeatureStore.java@@ -18,7 +18,6 @@ package org.apache.solr.ltr.store.rest;import java.util.HashMap;import java.util.Map;-import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.ltr.feature.Feature;import org.apache.solr.ltr.feature.FeatureException;@@ -38,15 +37,16 @@ public class TestManagedFeatureStore extends SolrTestCaseJ4 {initCore("solrconfig-ltr.xml", "schema.xml");fstore = ManagedFeatureStore.getManagedFeatureStore(h.getCore());}+@Afterpublic void cleanup() throws Exception {fstore = null;deleteCore();}-- private static Map<String,Object> createMap(String name, String className, Map<String,Object> params) {- final Map<String,Object> map = new HashMap<String,Object>();+ private static Map<String, Object> createMap(+ String name, String className, Map<String, Object> params) {+ final Map<String, Object> map = new HashMap<String, Object>();map.put(ManagedFeatureStore.NAME_KEY, name);map.put(ManagedFeatureStore.CLASS_KEY, className);if (params != null) {@@ -56,53 +56,49 @@ public class TestManagedFeatureStore extends SolrTestCaseJ4 {}@Test- public void testDefaultFeatureStoreName()- {+ public void testDefaultFeatureStoreName() {assertEquals("_DEFAULT_", FeatureStore.DEFAULT_FEATURE_STORE_NAME);- final FeatureStore expectedFeatureStore = fstore.getFeatureStore(FeatureStore.DEFAULT_FEATURE_STORE_NAME);+ final FeatureStore expectedFeatureStore =+ fstore.getFeatureStore(FeatureStore.DEFAULT_FEATURE_STORE_NAME);final FeatureStore actualFeatureStore = fstore.getFeatureStore(null);- assertEquals("getFeatureStore(null) should return the default feature store", expectedFeatureStore, actualFeatureStore);+ assertEquals(+ "getFeatureStore(null) should return the default feature store",+ expectedFeatureStore,+ actualFeatureStore);}@Test- public void testFeatureStoreAdd() throws FeatureException- {+ public void testFeatureStoreAdd() throws FeatureException {final FeatureStore fs = fstore.getFeatureStore("fstore-testFeature");for (int i = 0; i < 5; i++) {final String name = "c" + i;- fstore.addFeature(createMap(name,- OriginalScoreFeature.class.getName(), null),- "fstore-testFeature");+ fstore.addFeature(+ createMap(name, OriginalScoreFeature.class.getName(), null), "fstore-testFeature");final Feature f = fs.get(name);assertNotNull(f);-}assertEquals(5, fs.getFeatures().size());-}@Test- public void testFeatureStoreGet() throws FeatureException- {+ public void testFeatureStoreGet() throws FeatureException {final FeatureStore fs = fstore.getFeatureStore("fstore-testFeature2");for (int i = 0; i < 5; i++) {- Map<String,Object> params = new HashMap<String,Object>();+ Map<String, Object> params = new HashMap<String, Object>();params.put("value", i);final String name = "c" + i;- fstore.addFeature(createMap(name,- ValueFeature.class.getName(), params),- "fstore-testFeature2");-+ fstore.addFeature(+ createMap(name, ValueFeature.class.getName(), params), "fstore-testFeature2");}for (int i = 0; i < 5; i++) {final Feature f = fs.get("c" + i);assertEquals("c" + i, f.getName());assertTrue(f instanceof ValueFeature);- final ValueFeature vf = (ValueFeature)f;+ final ValueFeature vf = (ValueFeature) f;assertEquals(i, vf.getValue());}}@@ -111,28 +107,22 @@ public class TestManagedFeatureStore extends SolrTestCaseJ4 {public void testMissingFeatureReturnsNull() {final FeatureStore fs = fstore.getFeatureStore("fstore-testFeature3");for (int i = 0; i < 5; i++) {- Map<String,Object> params = new HashMap<String,Object>();+ Map<String, Object> params = new HashMap<String, Object>();params.put("value", i);final String name = "testc" + (float) i;- fstore.addFeature(createMap(name,- ValueFeature.class.getName(), params),- "fstore-testFeature3");-+ fstore.addFeature(+ createMap(name, ValueFeature.class.getName(), params), "fstore-testFeature3");}assertNull(fs.get("missing_feature_name"));}@Test- public void getInstanceTest() throws FeatureException- {- fstore.addFeature(createMap("test",- OriginalScoreFeature.class.getName(), null),- "testFstore");+ public void getInstanceTest() throws FeatureException {+ fstore.addFeature(createMap("test", OriginalScoreFeature.class.getName(), null), "testFstore");final Feature feature = fstore.getFeatureStore("testFstore").get("test");assertNotNull(feature);assertEquals("test", feature.getName());- assertEquals(OriginalScoreFeature.class.getName(), feature- .getClass().getName());+ assertEquals(OriginalScoreFeature.class.getName(), feature.getClass().getName());}@Test@@ -140,11 +130,13 @@ public class TestManagedFeatureStore extends SolrTestCaseJ4 {final String nonExistingClassName = "org.apache.solr.ltr.feature.LOLFeature";final ClassNotFoundException expectedException =new ClassNotFoundException(nonExistingClassName);- Exception ex = expectThrows(Exception.class, () -> {- fstore.addFeature(createMap("test", nonExistingClassName, null), "testFstore2");- });+ Exception ex =+ expectThrows(+ Exception.class,+ () -> {+ fstore.addFeature(createMap("test", nonExistingClassName, null), "testFstore2");+ });Throwable rootError = getRootCause(ex);assertEquals(expectedException.toString(), rootError.toString());}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManager.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManager.javaindex 3c308bc5760..cda8dbd3642 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManager.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManager.java@@ -39,32 +39,26 @@ public class TestModelManager extends TestRerankBase {@Testpublic void test() throws Exception {- final SolrResourceLoader loader = new SolrResourceLoader(- tmpSolrHome.toPath());+ final SolrResourceLoader loader = new SolrResourceLoader(tmpSolrHome.toPath());final RestManager.Registry registry = loader.getManagedResourceRegistry();assertNotNull(- "Expected a non-null RestManager.Registry from the SolrResourceLoader!",- registry);+ "Expected a non-null RestManager.Registry from the SolrResourceLoader!", registry);final String resourceId = "/schema/fstore1";- registry.registerManagedResource(resourceId, ManagedFeatureStore.class,- new LTRQParserPlugin());+ registry.registerManagedResource(resourceId, ManagedFeatureStore.class, new LTRQParserPlugin());final String resourceId2 = "/schema/mstore1";- registry.registerManagedResource(resourceId2, ManagedModelStore.class,- new LTRQParserPlugin());+ registry.registerManagedResource(resourceId2, ManagedModelStore.class, new LTRQParserPlugin());final NamedList<String> initArgs = new NamedList<>();final RestManager restManager = new RestManager();- restManager.init(loader, initArgs,- new ManagedResourceStorage.InMemoryStorageIO());+ restManager.init(loader, initArgs, new ManagedResourceStorage.InMemoryStorageIO());final ManagedResource res = restManager.getManagedResource(resourceId);assertTrue(res instanceof ManagedFeatureStore);assertEquals(res.getResourceId(), resourceId);-}@Test@@ -77,59 +71,88 @@ public class TestModelManager extends TestRerankBase {final String valueFeatureClassName = ValueFeature.class.getName();// Add features- String feature = "{\"name\": \"test1\", \"class\": \""+valueFeatureClassName+"\", \"params\": {\"value\": 1} }";- assertJPut(ManagedFeatureStore.REST_END_POINT, feature,- "/responseHeader/status==0");-- feature = "{\"name\": \"test2\", \"class\": \""+valueFeatureClassName+"\", \"params\": {\"value\": 1} }";- assertJPut(ManagedFeatureStore.REST_END_POINT, feature,- "/responseHeader/status==0");-- feature = "{\"name\": \"test3\", \"class\": \""+valueFeatureClassName+"\", \"params\": {\"value\": 1} }";- assertJPut(ManagedFeatureStore.REST_END_POINT, feature,- "/responseHeader/status==0");-- feature = "{\"name\": \"test33\", \"store\": \""+TEST_FEATURE_STORE_NAME+"\", \"class\": \""+valueFeatureClassName+"\", \"params\": {\"value\": 1} }";- assertJPut(ManagedFeatureStore.REST_END_POINT, feature,- "/responseHeader/status==0");-- final String multipleFeatures = "[{\"name\": \"test4\", \"class\": \""+valueFeatureClassName+"\", \"params\": {\"value\": 1} }"- + ",{\"name\": \"test5\", \"class\": \""+valueFeatureClassName+"\", \"params\": {\"value\": 1} } ]";- assertJPut(ManagedFeatureStore.REST_END_POINT, multipleFeatures,- "/responseHeader/status==0");+ String feature =+ "{\"name\": \"test1\", \"class\": \""+ + valueFeatureClassName+ + "\", \"params\": {\"value\": 1} }";+ assertJPut(ManagedFeatureStore.REST_END_POINT, feature, "/responseHeader/status==0");++ feature =+ "{\"name\": \"test2\", \"class\": \""+ + valueFeatureClassName+ + "\", \"params\": {\"value\": 1} }";+ assertJPut(ManagedFeatureStore.REST_END_POINT, feature, "/responseHeader/status==0");++ feature =+ "{\"name\": \"test3\", \"class\": \""+ + valueFeatureClassName+ + "\", \"params\": {\"value\": 1} }";+ assertJPut(ManagedFeatureStore.REST_END_POINT, feature, "/responseHeader/status==0");++ feature =+ "{\"name\": \"test33\", \"store\": \""+ + TEST_FEATURE_STORE_NAME+ + "\", \"class\": \""+ + valueFeatureClassName+ + "\", \"params\": {\"value\": 1} }";+ assertJPut(ManagedFeatureStore.REST_END_POINT, feature, "/responseHeader/status==0");++ final String multipleFeatures =+ "[{\"name\": \"test4\", \"class\": \""+ + valueFeatureClassName+ + "\", \"params\": {\"value\": 1} }"+ + ",{\"name\": \"test5\", \"class\": \""+ + valueFeatureClassName+ + "\", \"params\": {\"value\": 1} } ]";+ assertJPut(ManagedFeatureStore.REST_END_POINT, multipleFeatures, "/responseHeader/status==0");final String fieldValueFeatureClassName = FieldValueFeature.class.getName();// Add bad feature (wrong params)_- final String badfeature = "{\"name\": \"fvalue\", \"class\": \""+fieldValueFeatureClassName+"\", \"params\": {\"value\": 1} }";- assertJPut(ManagedFeatureStore.REST_END_POINT, badfeature,- "/error/msg/=='No setter corrresponding to \\'value\\' in "+fieldValueFeatureClassName+"'");+ final String badfeature =+ "{\"name\": \"fvalue\", \"class\": \""+ + fieldValueFeatureClassName+ + "\", \"params\": {\"value\": 1} }";+ assertJPut(+ ManagedFeatureStore.REST_END_POINT,+ badfeature,+ "/error/msg/=='No setter corrresponding to \\'value\\' in "+ + fieldValueFeatureClassName+ + "'");final String linearModelClassName = LinearModel.class.getName();// Add models- String model = "{ \"name\":\"testmodel1\", \"class\":\""+linearModelClassName+"\", \"features\":[] }";+ String model =+ "{ \"name\":\"testmodel1\", \"class\":\"" + linearModelClassName + "\", \"features\":[] }";// fails since it does not have features- assertJPut(ManagedModelStore.REST_END_POINT, model,- "/responseHeader/status==400");+ assertJPut(ManagedModelStore.REST_END_POINT, model, "/responseHeader/status==400");// fails since it does not have weights- model = "{ \"name\":\"testmodel2\", \"class\":\""+linearModelClassName+"\", \"features\":[{\"name\":\"test1\"}, {\"name\":\"test2\"}] }";- assertJPut(ManagedModelStore.REST_END_POINT, model,- "/responseHeader/status==400");+ model =+ "{ \"name\":\"testmodel2\", \"class\":\""+ + linearModelClassName+ + "\", \"features\":[{\"name\":\"test1\"}, {\"name\":\"test2\"}] }";+ assertJPut(ManagedModelStore.REST_END_POINT, model, "/responseHeader/status==400");// success- model = "{ \"name\":\"testmodel3\", \"class\":\""+linearModelClassName+"\", \"features\":[{\"name\":\"test1\"}, {\"name\":\"test2\"}],\"params\":{\"weights\":{\"test1\":1.5,\"test2\":2.0}}}";- assertJPut(ManagedModelStore.REST_END_POINT, model,- "/responseHeader/status==0");+ model =+ "{ \"name\":\"testmodel3\", \"class\":\""+ + linearModelClassName+ + "\", \"features\":[{\"name\":\"test1\"}, {\"name\":\"test2\"}],\"params\":{\"weights\":{\"test1\":1.5,\"test2\":2.0}}}";+ assertJPut(ManagedModelStore.REST_END_POINT, model, "/responseHeader/status==0");// success- final String multipleModels = "[{ \"name\":\"testmodel4\", \"class\":\""+linearModelClassName+"\", \"features\":[{\"name\":\"test1\"}, {\"name\":\"test2\"}],\"params\":{\"weights\":{\"test1\":1.5,\"test2\":2.0}} }\n"- + ",{ \"name\":\"testmodel5\", \"class\":\""+linearModelClassName+"\", \"features\":[{\"name\":\"test1\"}, {\"name\":\"test2\"}],\"params\":{\"weights\":{\"test1\":1.5,\"test2\":2.0}} } ]";- assertJPut(ManagedModelStore.REST_END_POINT, multipleModels,- "/responseHeader/status==0");+ final String multipleModels =+ "[{ \"name\":\"testmodel4\", \"class\":\""+ + linearModelClassName+ + "\", \"features\":[{\"name\":\"test1\"}, {\"name\":\"test2\"}],\"params\":{\"weights\":{\"test1\":1.5,\"test2\":2.0}} }\n"+ + ",{ \"name\":\"testmodel5\", \"class\":\""+ + linearModelClassName+ + "\", \"features\":[{\"name\":\"test1\"}, {\"name\":\"test2\"}],\"params\":{\"weights\":{\"test1\":1.5,\"test2\":2.0}} } ]";+ assertJPut(ManagedModelStore.REST_END_POINT, multipleModels, "/responseHeader/status==0");final String qryResult = JQ(ManagedModelStore.REST_END_POINT);assert (qryResult.contains("\"name\":\"testmodel3\"")- && qryResult.contains("\"name\":\"testmodel4\"") && qryResult- .contains("\"name\":\"testmodel5\""));+ && qryResult.contains("\"name\":\"testmodel4\"")+ && qryResult.contains("\"name\":\"testmodel5\""));assertJQ(ManagedModelStore.REST_END_POINT, "/models/[0]/name=='testmodel3'");assertJQ(ManagedModelStore.REST_END_POINT, "/models/[1]/name=='testmodel4'");@@ -137,19 +160,27 @@ public class TestModelManager extends TestRerankBase {restTestHarness.delete(ManagedModelStore.REST_END_POINT + "/testmodel3");restTestHarness.delete(ManagedModelStore.REST_END_POINT + "/testmodel4");restTestHarness.delete(ManagedModelStore.REST_END_POINT + "/testmodel5");- assertJQ(ManagedModelStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ assertJQ(+ ManagedModelStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/models==[]'");- assertJQ(ManagedFeatureStore.REST_END_POINT,- "/featureStores==['"+TEST_FEATURE_STORE_NAME+"','"+FeatureStore.DEFAULT_FEATURE_STORE_NAME+"']");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ assertJQ(+ ManagedFeatureStore.REST_END_POINT,+ "/featureStores==['"+ + TEST_FEATURE_STORE_NAME+ + "','"+ + FeatureStore.DEFAULT_FEATURE_STORE_NAME+ + "']");+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/features/[0]/name=='test1'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/"+TEST_FEATURE_STORE_NAME,+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + TEST_FEATURE_STORE_NAME,"/features/[0]/name=='test33'");- restTestHarness.delete(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME);- restTestHarness.delete(ManagedFeatureStore.REST_END_POINT + "/"+TEST_FEATURE_STORE_NAME);- assertJQ(ManagedFeatureStore.REST_END_POINT,- "/featureStores==[]");+ restTestHarness.delete(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME);+ restTestHarness.delete(ManagedFeatureStore.REST_END_POINT + "/" + TEST_FEATURE_STORE_NAME);+ assertJQ(ManagedFeatureStore.REST_END_POINT, "/featureStores==[]");}@Test@@ -158,15 +189,16 @@ public class TestModelManager extends TestRerankBase {loadModels("linear-model.json");final String modelName = "6029760550880411648";- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/[0]/name=='"+modelName+"'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/[0]/name=='" + modelName + "'");+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/features/[0]/name=='title'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/features/[1]/name=='description'");- restTestHarness.delete(ManagedModelStore.REST_END_POINT + "/"+modelName);- restTestHarness.delete(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME);+ restTestHarness.delete(ManagedModelStore.REST_END_POINT + "/" + modelName);+ restTestHarness.delete(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME);}-}diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.javaindex f52acdcc045..7e42837bcf3 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java@@ -24,7 +24,6 @@ import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.List;import java.util.Map;-import org.apache.commons.io.FileUtils;import org.apache.solr.common.util.Utils;import org.apache.solr.ltr.TestRerankBase;@@ -45,6 +44,7 @@ public class TestModelManagerPersistence extends TestRerankBase {public void init() throws Exception {setupPersistenttest(true);}+@Afterpublic void cleanup() throws Exception {aftertest();@@ -54,99 +54,81 @@ public class TestModelManagerPersistence extends TestRerankBase {@Testpublic void testFeaturePersistence() throws Exception {- loadFeature("feature", ValueFeature.class.getName(), "test",- "{\"value\":2}");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test",- "/features/[0]/name=='feature'");+ loadFeature("feature", ValueFeature.class.getName(), "test", "{\"value\":2}");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test", "/features/[0]/name=='feature'");restTestHarness.reload();- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test",- "/features/[0]/name=='feature'");- loadFeature("feature1", ValueFeature.class.getName(), "test1",- "{\"value\":2}");- loadFeature("feature2", ValueFeature.class.getName(), "test",- "{\"value\":2}");- loadFeature("feature3", ValueFeature.class.getName(), "test2",- "{\"value\":2}");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test",- "/features/[0]/name=='feature'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test",- "/features/[1]/name=='feature2'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test1",- "/features/[0]/name=='feature1'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test2",- "/features/[0]/name=='feature3'");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test", "/features/[0]/name=='feature'");+ loadFeature("feature1", ValueFeature.class.getName(), "test1", "{\"value\":2}");+ loadFeature("feature2", ValueFeature.class.getName(), "test", "{\"value\":2}");+ loadFeature("feature3", ValueFeature.class.getName(), "test2", "{\"value\":2}");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test", "/features/[0]/name=='feature'");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test", "/features/[1]/name=='feature2'");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test1", "/features/[0]/name=='feature1'");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test2", "/features/[0]/name=='feature3'");restTestHarness.reload();- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test",- "/features/[0]/name=='feature'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test",- "/features/[1]/name=='feature2'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test1",- "/features/[0]/name=='feature1'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test2",- "/features/[0]/name=='feature3'");- loadModel("test-model", LinearModel.class.getName(),- new String[] {"feature"}, "test", "{\"weights\":{\"feature\":1.0}}");- loadModel("test-model2", LinearModel.class.getName(),- new String[] {"feature1"}, "test1", "{\"weights\":{\"feature1\":1.0}}");- final String fstorecontent = FileUtils- .readFileToString(fstorefile, "UTF-8");- final String mstorecontent = FileUtils- .readFileToString(mstorefile, "UTF-8");-- //check feature/model stores on deletion+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test", "/features/[0]/name=='feature'");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test", "/features/[1]/name=='feature2'");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test1", "/features/[0]/name=='feature1'");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test2", "/features/[0]/name=='feature3'");+ loadModel(+ "test-model",+ LinearModel.class.getName(),+ new String[] {"feature"},+ "test",+ "{\"weights\":{\"feature\":1.0}}");+ loadModel(+ "test-model2",+ LinearModel.class.getName(),+ new String[] {"feature1"},+ "test1",+ "{\"weights\":{\"feature1\":1.0}}");+ final String fstorecontent = FileUtils.readFileToString(fstorefile, "UTF-8");+ final String mstorecontent = FileUtils.readFileToString(mstorefile, "UTF-8");++ // check feature/model stores on deletion@SuppressWarnings({"unchecked"})- final ArrayList<Object> fStore = (ArrayList<Object>) ((Map<String,Object>)- Utils.fromJSONString(fstorecontent)).get("managedList");- for (int idx = 0;idx < fStore.size(); ++ idx) {+ final ArrayList<Object> fStore =+ (ArrayList<Object>)+ ((Map<String, Object>) Utils.fromJSONString(fstorecontent)).get("managedList");+ for (int idx = 0; idx < fStore.size(); ++idx) {@SuppressWarnings({"unchecked"})- String store = (String) ((Map<String,Object>)fStore.get(idx)).get("store");+ String store = (String) ((Map<String, Object>) fStore.get(idx)).get("store");assertTrue(store.equals("test") || store.equals("test2") || store.equals("test1"));}@SuppressWarnings({"unchecked"})- final ArrayList<Object> mStore = (ArrayList<Object>) ((Map<String,Object>)- Utils.fromJSONString(mstorecontent)).get("managedList");- for (int idx = 0;idx < mStore.size(); ++ idx) {+ final ArrayList<Object> mStore =+ (ArrayList<Object>)+ ((Map<String, Object>) Utils.fromJSONString(mstorecontent)).get("managedList");+ for (int idx = 0; idx < mStore.size(); ++idx) {@SuppressWarnings({"unchecked"})- String store = (String) ((Map<String,Object>)mStore.get(idx)).get("store");+ String store = (String) ((Map<String, Object>) mStore.get(idx)).get("store");assertTrue(store.equals("test") || store.equals("test1"));}- assertJDelete(ManagedFeatureStore.REST_END_POINT + "/test2",- "/responseHeader/status==0");- assertJDelete(ManagedModelStore.REST_END_POINT + "/test-model2",- "/responseHeader/status==0");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test2",- "/features/==[]");- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/[0]/name=='test-model'");+ assertJDelete(ManagedFeatureStore.REST_END_POINT + "/test2", "/responseHeader/status==0");+ assertJDelete(ManagedModelStore.REST_END_POINT + "/test-model2", "/responseHeader/status==0");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test2", "/features/==[]");+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/[0]/name=='test-model'");restTestHarness.reload();- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test2",- "/features/==[]");- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/[0]/name=='test-model'");-- assertJDelete(ManagedModelStore.REST_END_POINT + "/test-model",- "/responseHeader/status==0");- assertJDelete(ManagedFeatureStore.REST_END_POINT + "/test1",- "/responseHeader/status==0");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test1",- "/features/==[]");- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/==[]");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test2", "/features/==[]");+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/[0]/name=='test-model'");++ assertJDelete(ManagedModelStore.REST_END_POINT + "/test-model", "/responseHeader/status==0");+ assertJDelete(ManagedFeatureStore.REST_END_POINT + "/test1", "/responseHeader/status==0");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test1", "/features/==[]");+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/==[]");restTestHarness.reload();- assertJQ(ManagedFeatureStore.REST_END_POINT + "/test1",- "/features/==[]");- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/==[]");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/test1", "/features/==[]");+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/==[]");}@Testpublic void testFilePersistence() throws Exception {// check whether models and features are empty- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/==[]");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/==[]");+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/features/==[]");// load models and features from files@@ -155,70 +137,75 @@ public class TestModelManagerPersistence extends TestRerankBase {// check loaded models and featuresfinal String modelName = "6029760550880411648";- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/[0]/name=='"+modelName+"'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/[0]/name=='" + modelName + "'");+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/features/[0]/name=='title'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/features/[1]/name=='description'");// check persistence after reloadrestTestHarness.reload();- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/[0]/name=='"+modelName+"'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/[0]/name=='" + modelName + "'");+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/features/[0]/name=='title'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/features/[1]/name=='description'");// check persistence after restartjetty.stop();jetty.start();- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/[0]/name=='"+modelName+"'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/[0]/name=='" + modelName + "'");+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/features/[0]/name=='title'");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/features/[1]/name=='description'");// delete loaded models and features- restTestHarness.delete(ManagedModelStore.REST_END_POINT + "/"+modelName);- restTestHarness.delete(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME);- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/==[]");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ restTestHarness.delete(ManagedModelStore.REST_END_POINT + "/" + modelName);+ restTestHarness.delete(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME);+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/==[]");+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/features/==[]");// check persistence after reloadrestTestHarness.reload();- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/==[]");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/==[]");+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/features/==[]");// check persistence after restartjetty.stop();jetty.start();- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/==[]");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/==[]");+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + FeatureStore.DEFAULT_FEATURE_STORE_NAME,"/features/==[]");}- private static void doWrapperModelPersistenceChecks(String modelName,- String featureStoreName, String baseModelFileName) throws Exception {+ private static void doWrapperModelPersistenceChecks(+ String modelName, String featureStoreName, String baseModelFileName) throws Exception {// note that the wrapper and the wrapped model always have the same name- assertJQ(ManagedModelStore.REST_END_POINT,+ assertJQ(+ ManagedModelStore.REST_END_POINT,// the wrapped model shouldn't be registered- "!/models/[1]/name=='"+modelName+"'",+ "!/models/[1]/name=='" + modelName + "'",// but the wrapper model should be registered- "/models/[0]/name=='"+modelName+"'",+ "/models/[0]/name=='" + modelName + "'","/models/[0]/class=='" + DefaultWrapperModel.class.getName() + "'","/models/[0]/store=='" + featureStoreName + "'",// the wrapper model shouldn't contain the definitions of the wrapped model"/models/[0]/features/==[]",// but only its own parameters- "/models/[0]/params=={resource:'"+baseModelFileName+"'}");+ "/models/[0]/params=={resource:'" + baseModelFileName + "'}");}@Test@@ -227,30 +214,38 @@ public class TestModelManagerPersistence extends TestRerankBase {final String FS_NAME = "testWrapper";// check whether models and features are empty- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/==[]");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FS_NAME,- "/features/==[]");+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/==[]");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FS_NAME, "/features/==[]");// setup features- loadFeature("popularity", FieldValueFeature.class.getName(), FS_NAME, "{\"field\":\"popularity\"}");+ loadFeature(+ "popularity", FieldValueFeature.class.getName(), FS_NAME, "{\"field\":\"popularity\"}");loadFeature("const", ValueFeature.class.getName(), FS_NAME, "{\"value\":5}");// setup base model- String baseModelJson = getModelInJson(modelName, LinearModel.class.getName(),- new String[] {"popularity", "const"}, FS_NAME,- "{\"weights\":{\"popularity\":-1.0, \"const\":1.0}}");+ String baseModelJson =+ getModelInJson(+ modelName,+ LinearModel.class.getName(),+ new String[] {"popularity", "const"},+ FS_NAME,+ "{\"weights\":{\"popularity\":-1.0, \"const\":1.0}}");File baseModelFile = new File(tmpConfDir, "baseModelForPersistence.json");- try (BufferedWriter writer = new BufferedWriter(- new OutputStreamWriter(new FileOutputStream(baseModelFile), StandardCharsets.UTF_8))) {+ try (BufferedWriter writer =+ new BufferedWriter(+ new OutputStreamWriter(new FileOutputStream(baseModelFile), StandardCharsets.UTF_8))) {writer.write(baseModelJson);}baseModelFile.deleteOnExit();// setup wrapper model- String wrapperModelJson = getModelInJson(modelName, DefaultWrapperModel.class.getName(),- new String[0], FS_NAME,- "{\"resource\":\"" + baseModelFile.getName() + "\"}");+ String wrapperModelJson =+ getModelInJson(+ modelName,+ DefaultWrapperModel.class.getName(),+ new String[0],+ FS_NAME,+ "{\"resource\":\"" + baseModelFile.getName() + "\"}");assertJPut(ManagedModelStore.REST_END_POINT, wrapperModelJson, "/responseHeader/status==0");doWrapperModelPersistenceChecks(modelName, FS_NAME, baseModelFile.getName());@@ -266,23 +261,27 @@ public class TestModelManagerPersistence extends TestRerankBase {// delete test settingsrestTestHarness.delete(ManagedModelStore.REST_END_POINT + "/" + modelName);restTestHarness.delete(ManagedFeatureStore.REST_END_POINT + "/" + FS_NAME);- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/==[]");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FS_NAME,- "/features/==[]");+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/==[]");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + FS_NAME, "/features/==[]");- // NOTE: we don't test the persistence of the deletion here because it's tested in testFilePersistence+ // NOTE: we don't test the persistence of the deletion here because it's tested in+ // testFilePersistence}public static class DummyCustomFeature extends ValueFeature {- public DummyCustomFeature(String name, Map<String,Object> params) {+ public DummyCustomFeature(String name, Map<String, Object> params) {super(name, params);}}public static class DummyCustomModel extends LinearModel {- public DummyCustomModel(String name, List<Feature> features, List<Normalizer> norms, String featureStoreName,- List<Feature> allFeatures, Map<String,Object> params) {+ public DummyCustomModel(+ String name,+ List<Feature> features,+ List<Normalizer> norms,+ String featureStoreName,+ List<Feature> allFeatures,+ Map<String, Object> params) {super(name, features, norms, featureStoreName, allFeatures, params);}}@@ -300,10 +299,11 @@ public class TestModelManagerPersistence extends TestRerankBase {featureClassName = DummyCustomFeature.class.getName();}- loadFeature(featureName, featureClassName, "test42",- "{\"value\":"+random().nextInt(100)+"}");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/"+featureStoreName,- "/features/[0]/name=='"+featureName+"'");+ loadFeature(+ featureName, featureClassName, "test42", "{\"value\":" + random().nextInt(100) + "}");+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + featureStoreName,+ "/features/[0]/name=='" + featureName + "'");final String modelName = "model42";final String modelClassName;@@ -313,27 +313,25 @@ public class TestModelManagerPersistence extends TestRerankBase {modelClassName = DummyCustomModel.class.getName();}- loadModel(modelName, modelClassName,- new String[] { featureName }, featureStoreName,- "{\"weights\":{\""+featureName+"\":1.0}}");- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/[0]/name=='"+modelName+"'");+ loadModel(+ modelName,+ modelClassName,+ new String[] {featureName},+ featureStoreName,+ "{\"weights\":{\"" + featureName + "\":1.0}}");+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/[0]/name=='" + modelName + "'");restTestHarness.reload();- assertJQ(ManagedFeatureStore.REST_END_POINT + "/"+featureStoreName,- "/features/[0]/name=='"+featureName+"'");- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/[0]/name=='"+modelName+"'");-- assertJDelete(ManagedModelStore.REST_END_POINT + "/"+modelName,- "/responseHeader/status==0");- assertJQ(ManagedModelStore.REST_END_POINT,- "/models/==[]");-- assertJDelete(ManagedFeatureStore.REST_END_POINT + "/"+featureStoreName,- "/responseHeader/status==0");- assertJQ(ManagedFeatureStore.REST_END_POINT + "/"+featureStoreName,- "/features/==[]");- }+ assertJQ(+ ManagedFeatureStore.REST_END_POINT + "/" + featureStoreName,+ "/features/[0]/name=='" + featureName + "'");+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/[0]/name=='" + modelName + "'");++ assertJDelete(ManagedModelStore.REST_END_POINT + "/" + modelName, "/responseHeader/status==0");+ assertJQ(ManagedModelStore.REST_END_POINT, "/models/==[]");+ assertJDelete(+ ManagedFeatureStore.REST_END_POINT + "/" + featureStoreName, "/responseHeader/status==0");+ assertJQ(ManagedFeatureStore.REST_END_POINT + "/" + featureStoreName, "/features/==[]");+ }}