From a1a9341a9c0aeb2c3ec819b7f74153a3b31a04be Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Fri, 9 Feb 2018 17:28:17 +0000 Subject: [PATCH 1/2] SOLR-11931: Fix contrib/ltr custom inner class feature/normaliser/model persistence. --- solr/CHANGES.txt | 2 + .../ltr/store/rest/ManagedFeatureStore.java | 2 +- .../ltr/store/rest/ManagedModelStore.java | 4 +- .../rest/TestModelManagerPersistence.java | 66 +++++++++++++++++++ 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 3212a6f387e..3f6911b42cb 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -195,6 +195,8 @@ Bug Fixes * SOLR-11459: In-place update of nonexistent doc following existing doc update fails to create the doc. (Andrey Kudryavtsev via Mikhail Khludnev) +* SOLR-11931: Fix contrib/ltr custom inner class feature/normaliser/model persistence. (Christine Poerschke) + Optimizations ---------------------- diff --git a/solr/contrib/ltr/src/java/org/apache/solr/ltr/store/rest/ManagedFeatureStore.java b/solr/contrib/ltr/src/java/org/apache/solr/ltr/store/rest/ManagedFeatureStore.java index 6b415a66393..9ef36b876de 100644 --- a/solr/contrib/ltr/src/java/org/apache/solr/ltr/store/rest/ManagedFeatureStore.java +++ b/solr/contrib/ltr/src/java/org/apache/solr/ltr/store/rest/ManagedFeatureStore.java @@ -192,7 +192,7 @@ public class ManagedFeatureStore extends ManagedResource implements ManagedResou private static LinkedHashMap toFeatureMap(Feature feat) { final LinkedHashMap o = new LinkedHashMap<>(4, 1.0f); // 1 extra for caller to add store o.put(NAME_KEY, feat.getName()); - o.put(CLASS_KEY, feat.getClass().getCanonicalName()); + o.put(CLASS_KEY, feat.getClass().getName()); o.put(PARAMS_KEY, feat.paramsToMap()); return o; } diff --git a/solr/contrib/ltr/src/java/org/apache/solr/ltr/store/rest/ManagedModelStore.java b/solr/contrib/ltr/src/java/org/apache/solr/ltr/store/rest/ManagedModelStore.java index 342a14067c6..bdc4cfd9df2 100644 --- a/solr/contrib/ltr/src/java/org/apache/solr/ltr/store/rest/ManagedModelStore.java +++ b/solr/contrib/ltr/src/java/org/apache/solr/ltr/store/rest/ManagedModelStore.java @@ -268,7 +268,7 @@ public class ManagedModelStore extends ManagedResource implements ManagedResourc final LinkedHashMap modelMap = new LinkedHashMap<>(5, 1.0f); modelMap.put(NAME_KEY, model.getName()); - modelMap.put(CLASS_KEY, model.getClass().getCanonicalName()); + modelMap.put(CLASS_KEY, model.getClass().getName()); modelMap.put(STORE_KEY, model.getFeatureStoreName()); final List> features = new ArrayList<>(); @@ -321,7 +321,7 @@ public class ManagedModelStore extends ManagedResource implements ManagedResourc private static LinkedHashMap toNormalizerMap(Normalizer norm) { final LinkedHashMap normalizer = new LinkedHashMap<>(2, 1.0f); - normalizer.put(CLASS_KEY, norm.getClass().getCanonicalName()); + normalizer.put(CLASS_KEY, norm.getClass().getName()); final LinkedHashMap params = norm.paramsToMap(); if (params != null) { diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java index a056cf7e340..16a202f99d7 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java @@ -22,14 +22,17 @@ import java.io.FileOutputStream; import java.io.OutputStreamWriter; 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.ltr.TestRerankBase; +import org.apache.solr.ltr.feature.Feature; import org.apache.solr.ltr.feature.FieldValueFeature; import org.apache.solr.ltr.feature.ValueFeature; import org.apache.solr.ltr.model.DefaultWrapperModel; import org.apache.solr.ltr.model.LinearModel; +import org.apache.solr.ltr.norm.Normalizer; import org.apache.solr.ltr.store.FeatureStore; import org.junit.BeforeClass; import org.junit.Test; @@ -261,4 +264,67 @@ public class TestModelManagerPersistence extends TestRerankBase { // 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 params) { + super(name, params); + } + } + + public static class DummyCustomModel extends LinearModel { + public DummyCustomModel(String name, List features, List norms, String featureStoreName, + List allFeatures, Map params) { + super(name, features, norms, featureStoreName, allFeatures, params); + } + } + + @Test + public void testInnerCustomClassesPersistence() throws Exception { + + final String featureStoreName = "test42"; + + final String featureName = "feature42"; + final String featureClassName; + if (random().nextBoolean()) { + featureClassName = ValueFeature.class.getName(); + } else { + featureClassName = DummyCustomFeature.class.getName(); + } + + 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; + if (random().nextBoolean()) { + modelClassName = LinearModel.class.getName(); + } else { + modelClassName = DummyCustomModel.class.getName(); + } + + 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/==[]"); + } + } From 1a6d0f585f35ff6c4e0b188bfd14c0c8e092b688 Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Fri, 9 Feb 2018 18:09:26 +0000 Subject: [PATCH 2/2] SOLR-11931: contrib/ltr tests: s/getCanonicalName/getName --- .../apache/solr/ltr/TestLTROnSolrCloud.java | 8 ++-- .../solr/ltr/TestLTRQParserExplain.java | 2 +- .../solr/ltr/TestLTRReRankingPipeline.java | 2 +- .../apache/solr/ltr/TestLTRScoringQuery.java | 4 +- .../org/apache/solr/ltr/TestLTRWithFacet.java | 4 +- .../org/apache/solr/ltr/TestLTRWithSort.java | 4 +- .../solr/ltr/TestSelectiveWeightCreation.java | 2 +- .../ltr/feature/TestEdisMaxSolrFeature.java | 4 +- .../solr/ltr/feature/TestFeatureLogging.java | 38 +++++++++---------- .../ltr/feature/TestFieldLengthFeature.java | 16 ++++---- .../ltr/feature/TestFieldValueFeature.java | 16 ++++---- .../ltr/feature/TestFilterSolrFeature.java | 8 ++-- .../ltr/feature/TestNoMatchSolrFeature.java | 18 ++++----- .../ltr/feature/TestOriginalScoreFeature.java | 10 ++--- .../solr/ltr/feature/TestRankingFeature.java | 14 +++---- .../ltr/feature/TestUserTermScoreWithQ.java | 4 +- .../ltr/feature/TestUserTermScorerQuery.java | 4 +- .../ltr/feature/TestUserTermScorereQDF.java | 4 +- .../solr/ltr/feature/TestValueFeature.java | 24 ++++++------ .../ltr/model/TestDefaultWrapperModel.java | 8 ++-- .../solr/ltr/model/TestLinearModel.java | 4 +- .../solr/ltr/norm/TestMinMaxNormalizer.java | 2 +- .../solr/ltr/norm/TestStandardNormalizer.java | 4 +- .../store/rest/TestManagedFeatureStore.java | 12 +++--- .../solr/ltr/store/rest/TestModelManager.java | 6 +-- .../rest/TestModelManagerPersistence.java | 22 +++++------ 26 files changed, 122 insertions(+), 122 deletions(-) diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTROnSolrCloud.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTROnSolrCloud.java index d0042c801b2..d4c30e6a703 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTROnSolrCloud.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTROnSolrCloud.java @@ -262,26 +262,26 @@ public class TestLTROnSolrCloud extends TestRerankBase { loadFeature( featureNames[0], - SolrFeature.class.getCanonicalName(), + SolrFeature.class.getName(), featureStore, "{\"q\":\"{!func}pow(popularity,2)\"}" ); loadFeature( featureNames[1], - ValueFeature.class.getCanonicalName(), + ValueFeature.class.getName(), featureStore, "{\"value\":2}" ); loadFeature( featureNames[2], - OriginalScoreFeature.class.getCanonicalName(), + OriginalScoreFeature.class.getName(), featureStore, null ); loadModel( "powpularityS-model", - LinearModel.class.getCanonicalName(), + LinearModel.class.getName(), featureNames, featureStore, jsonModelParams diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRQParserExplain.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRQParserExplain.java index 3d7d3e599cb..b4a821391f8 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRQParserExplain.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRQParserExplain.java @@ -38,7 +38,7 @@ public class TestLTRQParserExplain extends TestRerankBase { @Test public void testRerankedExplain() throws Exception { - loadModel("linear2", LinearModel.class.getCanonicalName(), new String[] { + loadModel("linear2", LinearModel.class.getName(), new String[] { "constant1", "constant2", "pop"}, "{\"weights\":{\"pop\":1.0,\"constant1\":1.5,\"constant2\":3.5}}"); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRReRankingPipeline.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRReRankingPipeline.java index d17dd8d05ce..de978949b06 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRReRankingPipeline.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRReRankingPipeline.java @@ -77,7 +77,7 @@ public class TestLTRReRankingPipeline extends LuceneTestCase { final Map params = new HashMap(); params.put("field", field); final Feature f = Feature.getInstance(solrResourceLoader, - FieldValueFeature.class.getCanonicalName(), + FieldValueFeature.class.getName(), "f" + i, params); f.setIndex(i); features.add(f); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java index 9b9713fa520..b38dacce21f 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java @@ -68,7 +68,7 @@ public class TestLTRScoringQuery extends LuceneTestCase { Map params = new HashMap(); params.put("value", i); final Feature f = Feature.getInstance(solrResourceLoader, - ValueFeature.class.getCanonicalName(), + ValueFeature.class.getName(), "f" + i, params); f.setIndex(i); features.add(f); @@ -82,7 +82,7 @@ public class TestLTRScoringQuery extends LuceneTestCase { Map params = new HashMap(); params.put("value", i); final Feature f = Feature.getInstance(solrResourceLoader, - ValueFeature.class.getCanonicalName(), + ValueFeature.class.getName(), "f" + i, params); f.setIndex(i); features.add(f); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithFacet.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithFacet.java index 4026bbbfd7e..db8fb38b3fc 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithFacet.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithFacet.java @@ -52,10 +52,10 @@ public class TestLTRWithFacet extends TestRerankBase { @Test public void testRankingSolrFacet() throws Exception { // before(); - loadFeature("powpularityS", SolrFeature.class.getCanonicalName(), + loadFeature("powpularityS", SolrFeature.class.getName(), "{\"q\":\"{!func}pow(popularity,2)\"}"); - loadModel("powpularityS-model", LinearModel.class.getCanonicalName(), + loadModel("powpularityS-model", LinearModel.class.getName(), new String[] {"powpularityS"}, "{\"weights\":{\"powpularityS\":1.0}}"); final SolrQuery query = new SolrQuery(); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithSort.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithSort.java index d120af1c283..c3c9857b19c 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithSort.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithSort.java @@ -51,10 +51,10 @@ public class TestLTRWithSort extends TestRerankBase { @Test public void testRankingSolrSort() throws Exception { // before(); - loadFeature("powpularityS", SolrFeature.class.getCanonicalName(), + loadFeature("powpularityS", SolrFeature.class.getName(), "{\"q\":\"{!func}pow(popularity,2)\"}"); - loadModel("powpularityS-model", LinearModel.class.getCanonicalName(), + loadModel("powpularityS-model", LinearModel.class.getName(), new String[] {"powpularityS"}, "{\"weights\":{\"powpularityS\":1.0}}"); final SolrQuery query = new SolrQuery(); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java index 71934360968..4e9e949ab3b 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java @@ -63,7 +63,7 @@ public class TestSelectiveWeightCreation extends TestRerankBase { Map params = new HashMap(); params.put("value", i); final Feature f = Feature.getInstance(solrResourceLoader, - ValueFeature.class.getCanonicalName(), + ValueFeature.class.getName(), "f" + i, params); f.setIndex(i); features.add(f); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestEdisMaxSolrFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestEdisMaxSolrFeature.java index 96a1d28cce3..4fd77e317cd 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestEdisMaxSolrFeature.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestEdisMaxSolrFeature.java @@ -57,10 +57,10 @@ public class TestEdisMaxSolrFeature extends TestRerankBase { public void testEdisMaxSolrFeature() throws Exception { loadFeature( "SomeEdisMax", - SolrFeature.class.getCanonicalName(), + 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.getCanonicalName(), + loadModel("EdisMax-model", LinearModel.class.getName(), new String[] {"SomeEdisMax"}, "{\"weights\":{\"SomeEdisMax\":1.0}}"); final SolrQuery query = new SolrQuery(); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureLogging.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureLogging.java index 6f811d92021..52fe70ef088 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureLogging.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureLogging.java @@ -39,20 +39,20 @@ public class TestFeatureLogging extends TestRerankBase { @Test public void testGeneratedFeatures() throws Exception { - loadFeature("c1", ValueFeature.class.getCanonicalName(), "test1", + loadFeature("c1", ValueFeature.class.getName(), "test1", "{\"value\":1.0}"); - loadFeature("c2", ValueFeature.class.getCanonicalName(), "test1", + loadFeature("c2", ValueFeature.class.getName(), "test1", "{\"value\":2.0}"); - loadFeature("c3", ValueFeature.class.getCanonicalName(), "test1", + loadFeature("c3", ValueFeature.class.getName(), "test1", "{\"value\":3.0}"); - loadFeature("pop", FieldValueFeature.class.getCanonicalName(), "test1", + loadFeature("pop", FieldValueFeature.class.getName(), "test1", "{\"field\":\"popularity\"}"); - loadFeature("nomatch", SolrFeature.class.getCanonicalName(), "test1", + loadFeature("nomatch", SolrFeature.class.getName(), "test1", "{\"q\":\"{!terms f=title}foobarbat\"}"); - loadFeature("yesmatch", SolrFeature.class.getCanonicalName(), "test1", + loadFeature("yesmatch", SolrFeature.class.getName(), "test1", "{\"q\":\"{!terms f=popularity}2\"}"); - loadModel("sum1", LinearModel.class.getCanonicalName(), new String[] { + loadModel("sum1", LinearModel.class.getName(), new String[] { "c1", "c2", "c3"}, "test1", "{\"weights\":{\"c1\":1.0,\"c2\":1.0,\"c3\":1.0}}"); @@ -96,16 +96,16 @@ public class TestFeatureLogging extends TestRerankBase { @Test public void testDefaultStoreFeatureExtraction() throws Exception { - loadFeature("defaultf1", ValueFeature.class.getCanonicalName(), + loadFeature("defaultf1", ValueFeature.class.getName(), FeatureStore.DEFAULT_FEATURE_STORE_NAME, "{\"value\":1.0}"); - loadFeature("store8f1", ValueFeature.class.getCanonicalName(), + loadFeature("store8f1", ValueFeature.class.getName(), "store8", "{\"value\":2.0}"); - loadFeature("store9f1", ValueFeature.class.getCanonicalName(), + loadFeature("store9f1", ValueFeature.class.getName(), "store9", "{\"value\":3.0}"); - loadModel("store9m1", LinearModel.class.getCanonicalName(), + loadModel("store9m1", LinearModel.class.getName(), new String[] {"store9f1"}, "store9", "{\"weights\":{\"store9f1\":1.0}}"); @@ -140,16 +140,16 @@ public class TestFeatureLogging extends TestRerankBase { @Test public void testGeneratedGroup() throws Exception { - loadFeature("c1", ValueFeature.class.getCanonicalName(), "testgroup", + loadFeature("c1", ValueFeature.class.getName(), "testgroup", "{\"value\":1.0}"); - loadFeature("c2", ValueFeature.class.getCanonicalName(), "testgroup", + loadFeature("c2", ValueFeature.class.getName(), "testgroup", "{\"value\":2.0}"); - loadFeature("c3", ValueFeature.class.getCanonicalName(), "testgroup", + loadFeature("c3", ValueFeature.class.getName(), "testgroup", "{\"value\":3.0}"); - loadFeature("pop", FieldValueFeature.class.getCanonicalName(), "testgroup", + loadFeature("pop", FieldValueFeature.class.getName(), "testgroup", "{\"field\":\"popularity\"}"); - loadModel("sumgroup", LinearModel.class.getCanonicalName(), new String[] { + loadModel("sumgroup", LinearModel.class.getName(), new String[] { "c1", "c2", "c3"}, "testgroup", "{\"weights\":{\"c1\":1.0,\"c2\":1.0,\"c3\":1.0}}"); @@ -180,12 +180,12 @@ public class TestFeatureLogging extends TestRerankBase { @Test public void testSparseDenseFeatures() throws Exception { - loadFeature("match", SolrFeature.class.getCanonicalName(), "test4", + loadFeature("match", SolrFeature.class.getName(), "test4", "{\"q\":\"{!terms f=title}different\"}"); - loadFeature("c4", ValueFeature.class.getCanonicalName(), "test4", + loadFeature("c4", ValueFeature.class.getName(), "test4", "{\"value\":1.0}"); - loadModel("sum4", LinearModel.class.getCanonicalName(), new String[] { + loadModel("sum4", LinearModel.class.getName(), new String[] { "match"}, "test4", "{\"weights\":{\"match\":1.0}}"); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldLengthFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldLengthFeature.java index 2e1a14d607b..18729088a31 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldLengthFeature.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldLengthFeature.java @@ -54,10 +54,10 @@ public class TestFieldLengthFeature extends TestRerankBase { assertU(adoc("id", "42", "title", "w10")); assertU(commit()); - loadFeature("description-length2", FieldLengthFeature.class.getCanonicalName(), + loadFeature("description-length2", FieldLengthFeature.class.getName(), "{\"field\":\"description\"}"); - loadModel("description-model2", LinearModel.class.getCanonicalName(), + loadModel("description-model2", LinearModel.class.getName(), new String[] {"description-length2"}, "{\"weights\":{\"description-length2\":1.0}}"); final SolrQuery query = new SolrQuery(); @@ -75,10 +75,10 @@ public class TestFieldLengthFeature extends TestRerankBase { assertU(adoc("id", "43", "title", "w11", "description", "")); assertU(commit()); - loadFeature("description-length3", FieldLengthFeature.class.getCanonicalName(), + loadFeature("description-length3", FieldLengthFeature.class.getName(), "{\"field\":\"description\"}"); - loadModel("description-model3", LinearModel.class.getCanonicalName(), + loadModel("description-model3", LinearModel.class.getName(), new String[] {"description-length3"}, "{\"weights\":{\"description-length3\":1.0}}"); final SolrQuery query = new SolrQuery(); @@ -92,10 +92,10 @@ public class TestFieldLengthFeature extends TestRerankBase { @Test public void testRanking() throws Exception { - loadFeature("title-length", FieldLengthFeature.class.getCanonicalName(), + loadFeature("title-length", FieldLengthFeature.class.getName(), "{\"field\":\"title\"}"); - loadModel("title-model", LinearModel.class.getCanonicalName(), + loadModel("title-model", LinearModel.class.getName(), new String[] {"title-length"}, "{\"weights\":{\"title-length\":1.0}}"); final SolrQuery query = new SolrQuery(); @@ -131,9 +131,9 @@ public class TestFieldLengthFeature extends TestRerankBase { assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='6'"); loadFeature("description-length", - FieldLengthFeature.class.getCanonicalName(), + FieldLengthFeature.class.getName(), "{\"field\":\"description\"}"); - loadModel("description-model", LinearModel.class.getCanonicalName(), + loadModel("description-model", LinearModel.class.getName(), new String[] {"description-length"}, "{\"weights\":{\"description-length\":1.0}}"); query.setQuery("title:w1"); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java index e4a132ad8f5..4fceddaf43a 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java @@ -54,10 +54,10 @@ public class TestFieldValueFeature extends TestRerankBase { assertU(commit()); - loadFeature("popularity", FieldValueFeature.class.getCanonicalName(), + loadFeature("popularity", FieldValueFeature.class.getName(), "{\"field\":\"popularity\"}"); - loadModel("popularity-model", LinearModel.class.getCanonicalName(), + loadModel("popularity-model", LinearModel.class.getName(), new String[] {"popularity"}, "{\"weights\":{\"popularity\":1.0}}"); } @@ -127,7 +127,7 @@ public class TestFieldValueFeature extends TestRerankBase { final String fstore = "testIfADocumentDoesntHaveAFieldASetDefaultValueIsReturned"; - loadFeature("popularity42", FieldValueFeature.class.getCanonicalName(), fstore, + loadFeature("popularity42", FieldValueFeature.class.getName(), fstore, "{\"field\":\"popularity\",\"defaultValue\":\"42.0\"}"); SolrQuery query = new SolrQuery(); @@ -135,7 +135,7 @@ public class TestFieldValueFeature extends TestRerankBase { query.add("fl", "*, score"); query.add("rows", "4"); - loadModel("popularity-model42", LinearModel.class.getCanonicalName(), + loadModel("popularity-model42", LinearModel.class.getName(), new String[] {"popularity42"}, fstore, "{\"weights\":{\"popularity42\":1.0}}"); assertJQ("/query" + query.toQueryString(), "/response/numFound/==1"); @@ -154,10 +154,10 @@ public class TestFieldValueFeature extends TestRerankBase { public void testThatIfaFieldDoesNotExistDefaultValueIsReturned() throws Exception { // using a different fstore to avoid a clash with the other tests final String fstore = "testThatIfaFieldDoesNotExistDefaultValueIsReturned"; - loadFeature("not-existing-field", FieldValueFeature.class.getCanonicalName(), fstore, + loadFeature("not-existing-field", FieldValueFeature.class.getName(), fstore, "{\"field\":\"cowabunga\"}"); - loadModel("not-existing-field-model", LinearModel.class.getCanonicalName(), + 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(); @@ -173,10 +173,10 @@ public class TestFieldValueFeature extends TestRerankBase { @Test public void testBooleanValue() throws Exception { final String fstore = "test_boolean_store"; - loadFeature("trendy", FieldValueFeature.class.getCanonicalName(), fstore, + loadFeature("trendy", FieldValueFeature.class.getName(), fstore, "{\"field\":\"isTrendy\"}"); - loadModel("trendy-model", LinearModel.class.getCanonicalName(), + loadModel("trendy-model", LinearModel.class.getName(), new String[] {"trendy"}, fstore, "{\"weights\":{\"trendy\":1.0}}"); SolrQuery query = new SolrQuery(); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFilterSolrFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFilterSolrFeature.java index bb52f39c161..d3c72109fa5 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFilterSolrFeature.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFilterSolrFeature.java @@ -56,11 +56,11 @@ public class TestFilterSolrFeature extends TestRerankBase { @Test public void testUserTermScoreWithFQ() throws Exception { - loadFeature("SomeTermFQ", SolrFeature.class.getCanonicalName(), + loadFeature("SomeTermFQ", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=popularity}88888\"]}"); - loadFeature("SomeEfiFQ", SolrFeature.class.getCanonicalName(), + loadFeature("SomeEfiFQ", SolrFeature.class.getName(), "{\"fq\":[\"{!terms f=title}${user_query}\"]}"); - loadModel("Term-modelFQ", LinearModel.class.getCanonicalName(), + loadModel("Term-modelFQ", LinearModel.class.getName(), new String[] {"SomeTermFQ", "SomeEfiFQ"}, "{\"weights\":{\"SomeTermFQ\":1.6, \"SomeEfiFQ\":2.0}}"); final SolrQuery query = new SolrQuery(); @@ -80,7 +80,7 @@ public class TestFilterSolrFeature extends TestRerankBase { public void testBadFeature() throws Exception { // Missing q/fq final String feature = getFeatureInJson("badFeature", "test", - SolrFeature.class.getCanonicalName(), "{\"df\":\"foo\"]}"); + SolrFeature.class.getName(), "{\"df\":\"foo\"]}"); assertJPut(ManagedFeatureStore.REST_END_POINT, feature, "/responseHeader/status==500"); } diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestNoMatchSolrFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestNoMatchSolrFeature.java index c068be95cc5..aaafc75722f 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestNoMatchSolrFeature.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestNoMatchSolrFeature.java @@ -53,27 +53,27 @@ public class TestNoMatchSolrFeature extends TestRerankBase { "w1 w1 w1 w2 w2", "popularity", "8")); assertU(commit()); - loadFeature("nomatchfeature", SolrFeature.class.getCanonicalName(), + loadFeature("nomatchfeature", SolrFeature.class.getName(), "{\"q\":\"foobarbat12345\",\"df\":\"title\"}"); - loadFeature("yesmatchfeature", SolrFeature.class.getCanonicalName(), + loadFeature("yesmatchfeature", SolrFeature.class.getName(), "{\"q\":\"w1\",\"df\":\"title\"}"); - loadFeature("nomatchfeature2", SolrFeature.class.getCanonicalName(), + loadFeature("nomatchfeature2", SolrFeature.class.getName(), "{\"q\":\"foobarbat12345\",\"df\":\"title\"}"); loadModel( "nomatchmodel", - LinearModel.class.getCanonicalName(), + LinearModel.class.getName(), new String[] {"nomatchfeature", "yesmatchfeature", "nomatchfeature2"}, "{\"weights\":{\"nomatchfeature\":1.0,\"yesmatchfeature\":1.1,\"nomatchfeature2\":1.1}}"); - loadFeature("nomatchfeature3", SolrFeature.class.getCanonicalName(), + loadFeature("nomatchfeature3", SolrFeature.class.getName(), "{\"q\":\"foobarbat12345\",\"df\":\"title\"}"); - loadModel("nomatchmodel2", LinearModel.class.getCanonicalName(), + loadModel("nomatchmodel2", LinearModel.class.getName(), new String[] {"nomatchfeature3"}, "{\"weights\":{\"nomatchfeature3\":1.0}}"); - loadFeature("nomatchfeature4", SolrFeature.class.getCanonicalName(), + loadFeature("nomatchfeature4", SolrFeature.class.getName(), "noMatchFeaturesStore", "{\"q\":\"foobarbat12345\",\"df\":\"title\"}"); - loadModel("nomatchmodel3", LinearModel.class.getCanonicalName(), + loadModel("nomatchmodel3", LinearModel.class.getName(), new String[] {"nomatchfeature4"}, "noMatchFeaturesStore", "{\"weights\":{\"nomatchfeature4\":1.0}}"); } @@ -239,7 +239,7 @@ public class TestNoMatchSolrFeature extends TestRerankBase { // MultipleAdditiveTrees will return scores even for docs without any feature matches loadModel( "nomatchmodel4", - MultipleAdditiveTreesModel.class.getCanonicalName(), + MultipleAdditiveTreesModel.class.getName(), new String[] {"nomatchfeature4"}, "noMatchFeaturesStore", "{\"trees\":[{\"weight\":\"1f\", \"root\":{\"feature\": \"matchedTitle\",\"threshold\": \"0.5f\",\"left\":{\"value\" : \"-10\"},\"right\":{\"value\" : \"9\"}}}]}"); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestOriginalScoreFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestOriginalScoreFeature.java index f4c0df1fbf5..b8481bdeee4 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestOriginalScoreFeature.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestOriginalScoreFeature.java @@ -53,8 +53,8 @@ public class TestOriginalScoreFeature extends TestRerankBase { @Test public void testOriginalScore() throws Exception { - loadFeature("score", OriginalScoreFeature.class.getCanonicalName(), "{}"); - loadModel("originalScore", LinearModel.class.getCanonicalName(), + loadFeature("score", OriginalScoreFeature.class.getName(), "{}"); + loadModel("originalScore", LinearModel.class.getName(), new String[] {"score"}, "{\"weights\":{\"score\":1.0}}"); implTestOriginalScoreResponseDocsCheck("originalScore", "score", null, null); @@ -62,12 +62,12 @@ public class TestOriginalScoreFeature extends TestRerankBase { @Test public void testOriginalScoreWithNonScoringFeatures() throws Exception { - loadFeature("origScore", OriginalScoreFeature.class.getCanonicalName(), + loadFeature("origScore", OriginalScoreFeature.class.getName(), "store2", "{}"); - loadFeature("c2", ValueFeature.class.getCanonicalName(), "store2", + loadFeature("c2", ValueFeature.class.getName(), "store2", "{\"value\":2.0}"); - loadModel("origScore", LinearModel.class.getCanonicalName(), + loadModel("origScore", LinearModel.class.getName(), new String[] {"origScore"}, "store2", "{\"weights\":{\"origScore\":1.0}}"); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestRankingFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestRankingFeature.java index 31add41fb43..1d28dd88c68 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestRankingFeature.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestRankingFeature.java @@ -57,14 +57,14 @@ public class TestRankingFeature extends TestRerankBase { @Test public void testRankingSolrFeature() throws Exception { // before(); - loadFeature("powpularityS", SolrFeature.class.getCanonicalName(), + loadFeature("powpularityS", SolrFeature.class.getName(), "{\"q\":\"{!func}pow(popularity,2)\"}"); - loadFeature("unpopularityS", SolrFeature.class.getCanonicalName(), + loadFeature("unpopularityS", SolrFeature.class.getName(), "{\"q\":\"{!func}div(1,popularity)\"}"); - loadModel("powpularityS-model", LinearModel.class.getCanonicalName(), + loadModel("powpularityS-model", LinearModel.class.getName(), new String[] {"powpularityS"}, "{\"weights\":{\"powpularityS\":1.0}}"); - loadModel("unpopularityS-model", LinearModel.class.getCanonicalName(), + loadModel("unpopularityS-model", LinearModel.class.getName(), new String[] {"unpopularityS"}, "{\"weights\":{\"unpopularityS\":1.0}}"); final SolrQuery query = new SolrQuery(); @@ -104,16 +104,16 @@ public class TestRankingFeature extends TestRerankBase { assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='8'"); //bad solr ranking feature - loadFeature("powdesS", SolrFeature.class.getCanonicalName(), + loadFeature("powdesS", SolrFeature.class.getName(), "{\"q\":\"{!func}pow(description,2)\"}"); - loadModel("powdesS-model", LinearModel.class.getCanonicalName(), + 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.getCanonicalName()+": " + + "/error/msg/=='"+FeatureException.class.getName()+": " + "java.lang.UnsupportedOperationException: " + "Unable to extract feature for powdesS'"); // aftertest(); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScoreWithQ.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScoreWithQ.java index b5c8e32ea84..8ca63124d72 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScoreWithQ.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScoreWithQ.java @@ -56,9 +56,9 @@ public class TestUserTermScoreWithQ extends TestRerankBase { @Test public void testUserTermScoreWithQ() throws Exception { // before(); - loadFeature("SomeTermQ", SolrFeature.class.getCanonicalName(), + loadFeature("SomeTermQ", SolrFeature.class.getName(), "{\"q\":\"{!terms f=popularity}88888\"}"); - loadModel("Term-modelQ", LinearModel.class.getCanonicalName(), + loadModel("Term-modelQ", LinearModel.class.getName(), new String[] {"SomeTermQ"}, "{\"weights\":{\"SomeTermQ\":1.0}}"); final SolrQuery query = new SolrQuery(); query.setQuery("title:w1"); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorerQuery.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorerQuery.java index c0f92d220d3..29a537223ae 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorerQuery.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorerQuery.java @@ -56,9 +56,9 @@ public class TestUserTermScorerQuery extends TestRerankBase { @Test public void testUserTermScorerQuery() throws Exception { // before(); - loadFeature("matchedTitleDFExt", SolrFeature.class.getCanonicalName(), + loadFeature("matchedTitleDFExt", SolrFeature.class.getName(), "{\"q\":\"${user_query}\",\"df\":\"title\"}"); - loadModel("Term-matchedTitleDFExt", LinearModel.class.getCanonicalName(), + loadModel("Term-matchedTitleDFExt", LinearModel.class.getName(), new String[] {"matchedTitleDFExt"}, "{\"weights\":{\"matchedTitleDFExt\":1.1}}"); final SolrQuery query = new SolrQuery(); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorereQDF.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorereQDF.java index 6b22cdfde23..62061ca3694 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorereQDF.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorereQDF.java @@ -56,9 +56,9 @@ public class TestUserTermScorereQDF extends TestRerankBase { @Test public void testUserTermScorerQWithDF() throws Exception { // before(); - loadFeature("matchedTitleDF", SolrFeature.class.getCanonicalName(), + loadFeature("matchedTitleDF", SolrFeature.class.getName(), "{\"q\":\"w5\",\"df\":\"title\"}"); - loadModel("Term-matchedTitleDF", LinearModel.class.getCanonicalName(), + loadModel("Term-matchedTitleDF", LinearModel.class.getName(), new String[] {"matchedTitleDF"}, "{\"weights\":{\"matchedTitleDF\":1.0}}"); final SolrQuery query = new SolrQuery(); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestValueFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestValueFeature.java index de0c9239640..af23fdc9cfe 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestValueFeature.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestValueFeature.java @@ -50,7 +50,7 @@ public class TestValueFeature extends TestRerankBase { final RuntimeException expectedException = new RuntimeException("mismatch: '0'!='500' @ responseHeader/status"); try { - loadFeature("c2", ValueFeature.class.getCanonicalName(), "{\"value\":\"\"}"); + loadFeature("c2", ValueFeature.class.getName(), "{\"value\":\"\"}"); fail("testValueFeatureWithEmptyValue failed to throw exception: "+expectedException); } catch (RuntimeException actualException) { assertEquals(expectedException.toString(), actualException.toString()); @@ -62,7 +62,7 @@ public class TestValueFeature extends TestRerankBase { final RuntimeException expectedException = new RuntimeException("mismatch: '0'!='500' @ responseHeader/status"); try { - loadFeature("c2", ValueFeature.class.getCanonicalName(), + loadFeature("c2", ValueFeature.class.getName(), "{\"value\":\" \"}"); fail("testValueFeatureWithWhitespaceValue failed to throw exception: "+expectedException); } catch (RuntimeException actualException) { @@ -72,9 +72,9 @@ public class TestValueFeature extends TestRerankBase { @Test public void testRerankingWithConstantValueFeatureReplacesDocScore() throws Exception { - loadFeature("c3", ValueFeature.class.getCanonicalName(), "c3", + loadFeature("c3", ValueFeature.class.getName(), "c3", "{\"value\":2}"); - loadModel("m3", LinearModel.class.getCanonicalName(), new String[] {"c3"}, + loadModel("m3", LinearModel.class.getName(), new String[] {"c3"}, "c3", "{\"weights\":{\"c3\":1.0}}"); final SolrQuery query = new SolrQuery(); @@ -92,9 +92,9 @@ public class TestValueFeature extends TestRerankBase { @Test public void testRerankingWithEfiValueFeatureReplacesDocScore() throws Exception { - loadFeature("c6", ValueFeature.class.getCanonicalName(), "c6", + loadFeature("c6", ValueFeature.class.getName(), "c6", "{\"value\":\"${val6}\"}"); - loadModel("m6", LinearModel.class.getCanonicalName(), new String[] {"c6"}, + loadModel("m6", LinearModel.class.getName(), new String[] {"c6"}, "c6", "{\"weights\":{\"c6\":1.0}}"); final SolrQuery query = new SolrQuery(); @@ -113,9 +113,9 @@ public class TestValueFeature extends TestRerankBase { @Test public void testValueFeatureImplicitlyNotRequiredShouldReturnOkStatusCode() throws Exception { - loadFeature("c5", ValueFeature.class.getCanonicalName(), "c5", + loadFeature("c5", ValueFeature.class.getName(), "c5", "{\"value\":\"${val6}\"}"); - loadModel("m5", LinearModel.class.getCanonicalName(), new String[] {"c5"}, + loadModel("m5", LinearModel.class.getName(), new String[] {"c5"}, "c5", "{\"weights\":{\"c5\":1.0}}"); final SolrQuery query = new SolrQuery(); @@ -130,9 +130,9 @@ public class TestValueFeature extends TestRerankBase { @Test public void testValueFeatureExplictlyNotRequiredShouldReturnOkStatusCode() throws Exception { - loadFeature("c7", ValueFeature.class.getCanonicalName(), "c7", + loadFeature("c7", ValueFeature.class.getName(), "c7", "{\"value\":\"${val7}\",\"required\":false}"); - loadModel("m7", LinearModel.class.getCanonicalName(), new String[] {"c7"}, + loadModel("m7", LinearModel.class.getName(), new String[] {"c7"}, "c7", "{\"weights\":{\"c7\":1.0}}"); final SolrQuery query = new SolrQuery(); @@ -147,9 +147,9 @@ public class TestValueFeature extends TestRerankBase { @Test public void testValueFeatureRequiredShouldReturn400StatusCode() throws Exception { - loadFeature("c8", ValueFeature.class.getCanonicalName(), "c8", + loadFeature("c8", ValueFeature.class.getName(), "c8", "{\"value\":\"${val8}\",\"required\":true}"); - loadModel("m8", LinearModel.class.getCanonicalName(), new String[] {"c8"}, + loadModel("m8", LinearModel.class.getName(), new String[] {"c8"}, "c8", "{\"weights\":{\"c8\":1.0}}"); final SolrQuery query = new SolrQuery(); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestDefaultWrapperModel.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestDefaultWrapperModel.java index a930c23f2b1..25e716a8251 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestDefaultWrapperModel.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestDefaultWrapperModel.java @@ -52,13 +52,13 @@ public class TestDefaultWrapperModel extends TestRerankBase { assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5")); assertU(commit()); - loadFeature("popularity", FieldValueFeature.class.getCanonicalName(), "test", "{\"field\":\"popularity\"}"); - loadFeature("const", ValueFeature.class.getCanonicalName(), "test", "{\"value\":5}"); + 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")); - baseModelJson = getModelInJson("linear", LinearModel.class.getCanonicalName(), + baseModelJson = getModelInJson("linear", LinearModel.class.getName(), new String[] {"popularity", "const"}, featureStoreName, "{\"weights\":{\"popularity\":-1.0, \"const\":1.0}}"); @@ -72,7 +72,7 @@ public class TestDefaultWrapperModel extends TestRerankBase { } private static String getDefaultWrapperModelInJson(String wrapperModelName, String[] features, String params) { - return getModelInJson(wrapperModelName, DefaultWrapperModel.class.getCanonicalName(), + return getModelInJson(wrapperModelName, DefaultWrapperModel.class.getName(), features, featureStoreName, params); } diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java index 46496244db8..6620441cd5f 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java @@ -39,7 +39,7 @@ public class TestLinearModel extends TestRerankBase { String featureStoreName, List allFeatures, Map params) throws ModelException { final LTRScoringModel model = LTRScoringModel.getInstance(solrResourceLoader, - LinearModel.class.getCanonicalName(), + LinearModel.class.getName(), name, features, norms, featureStoreName, allFeatures, params); return model; @@ -111,7 +111,7 @@ public class TestLinearModel extends TestRerankBase { public void existingNameTest() { final SolrException expectedException = new SolrException(SolrException.ErrorCode.BAD_REQUEST, - ModelException.class.getCanonicalName()+": model 'test3' already exists. Please use a different name"); + ModelException.class.getName()+": model 'test3' already exists. Please use a different name"); try { final List features = getFeatures(new String[] {"constant1", "constant5"}); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/norm/TestMinMaxNormalizer.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/norm/TestMinMaxNormalizer.java index f5e00264d50..5c261078334 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/norm/TestMinMaxNormalizer.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/norm/TestMinMaxNormalizer.java @@ -34,7 +34,7 @@ public class TestMinMaxNormalizer { float expectedMin, float expectedMax) { final Normalizer n = Normalizer.getInstance( solrResourceLoader, - MinMaxNormalizer.class.getCanonicalName(), + MinMaxNormalizer.class.getName(), params); assertTrue(n instanceof MinMaxNormalizer); final MinMaxNormalizer mmn = (MinMaxNormalizer)n; diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/norm/TestStandardNormalizer.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/norm/TestStandardNormalizer.java index c27dcadd865..6ef5c306d1e 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/norm/TestStandardNormalizer.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/norm/TestStandardNormalizer.java @@ -34,7 +34,7 @@ public class TestStandardNormalizer { float expectedAvg, float expectedStd) { final Normalizer n = Normalizer.getInstance( solrResourceLoader, - StandardNormalizer.class.getCanonicalName(), + StandardNormalizer.class.getName(), params); assertTrue(n instanceof StandardNormalizer); final StandardNormalizer sn = (StandardNormalizer)n; @@ -122,7 +122,7 @@ public class TestStandardNormalizer { params.put("std", "1.5f"); final Normalizer norm = Normalizer.getInstance( solrResourceLoader, - StandardNormalizer.class.getCanonicalName(), + StandardNormalizer.class.getName(), params); for (final float v : new float[] {10f, 20f, 25f, 30f, 31f, 40f, 42f, 100f, diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestManagedFeatureStore.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestManagedFeatureStore.java index c229dddd886..e849d3f0b12 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestManagedFeatureStore.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestManagedFeatureStore.java @@ -66,7 +66,7 @@ public class TestManagedFeatureStore extends SolrTestCaseJ4 { final String name = "c" + i; fstore.addFeature(createMap(name, - OriginalScoreFeature.class.getCanonicalName(), null), + OriginalScoreFeature.class.getName(), null), "fstore-testFeature"); final Feature f = fs.get(name); @@ -87,7 +87,7 @@ public class TestManagedFeatureStore extends SolrTestCaseJ4 { final String name = "c" + i; fstore.addFeature(createMap(name, - ValueFeature.class.getCanonicalName(), params), + ValueFeature.class.getName(), params), "fstore-testFeature2"); } @@ -109,7 +109,7 @@ public class TestManagedFeatureStore extends SolrTestCaseJ4 { params.put("value", i); final String name = "testc" + (float) i; fstore.addFeature(createMap(name, - ValueFeature.class.getCanonicalName(), params), + ValueFeature.class.getName(), params), "fstore-testFeature3"); } @@ -120,13 +120,13 @@ public class TestManagedFeatureStore extends SolrTestCaseJ4 { public void getInstanceTest() throws FeatureException { fstore.addFeature(createMap("test", - OriginalScoreFeature.class.getCanonicalName(), null), + OriginalScoreFeature.class.getName(), null), "testFstore"); final Feature feature = fstore.getFeatureStore("testFstore").get("test"); assertNotNull(feature); assertEquals("test", feature.getName()); - assertEquals(OriginalScoreFeature.class.getCanonicalName(), feature - .getClass().getCanonicalName()); + assertEquals(OriginalScoreFeature.class.getName(), feature + .getClass().getName()); } @Test diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManager.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManager.java index 125f452479f..3c308bc5760 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManager.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManager.java @@ -74,7 +74,7 @@ public class TestModelManager extends TestRerankBase { // schema-rest.xml used by this test assertJQ("/schema/managed", "/responseHeader/status==0"); - final String valueFeatureClassName = ValueFeature.class.getCanonicalName(); + final String valueFeatureClassName = ValueFeature.class.getName(); // Add features String feature = "{\"name\": \"test1\", \"class\": \""+valueFeatureClassName+"\", \"params\": {\"value\": 1} }"; @@ -98,14 +98,14 @@ public class TestModelManager extends TestRerankBase { assertJPut(ManagedFeatureStore.REST_END_POINT, multipleFeatures, "/responseHeader/status==0"); - final String fieldValueFeatureClassName = FieldValueFeature.class.getCanonicalName(); + 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 linearModelClassName = LinearModel.class.getCanonicalName(); + final String linearModelClassName = LinearModel.class.getName(); // Add models String model = "{ \"name\":\"testmodel1\", \"class\":\""+linearModelClassName+"\", \"features\":[] }"; diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java index 16a202f99d7..c47a92c6f3c 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java @@ -49,18 +49,18 @@ public class TestModelManagerPersistence extends TestRerankBase { @Test public void testFeaturePersistence() throws Exception { - loadFeature("feature", ValueFeature.class.getCanonicalName(), "test", + 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.getCanonicalName(), "test1", + loadFeature("feature1", ValueFeature.class.getName(), "test1", "{\"value\":2}"); - loadFeature("feature2", ValueFeature.class.getCanonicalName(), "test", + loadFeature("feature2", ValueFeature.class.getName(), "test", "{\"value\":2}"); - loadFeature("feature3", ValueFeature.class.getCanonicalName(), "test2", + loadFeature("feature3", ValueFeature.class.getName(), "test2", "{\"value\":2}"); assertJQ(ManagedFeatureStore.REST_END_POINT + "/test", "/features/[0]/name=='feature'"); @@ -79,9 +79,9 @@ public class TestModelManagerPersistence extends TestRerankBase { "/features/[0]/name=='feature1'"); assertJQ(ManagedFeatureStore.REST_END_POINT + "/test2", "/features/[0]/name=='feature3'"); - loadModel("test-model", LinearModel.class.getCanonicalName(), + loadModel("test-model", LinearModel.class.getName(), new String[] {"feature"}, "test", "{\"weights\":{\"feature\":1.0}}"); - loadModel("test-model2", LinearModel.class.getCanonicalName(), + loadModel("test-model2", LinearModel.class.getName(), new String[] {"feature1"}, "test1", "{\"weights\":{\"feature1\":1.0}}"); final String fstorecontent = FileUtils .readFileToString(fstorefile, "UTF-8"); @@ -204,7 +204,7 @@ public class TestModelManagerPersistence extends TestRerankBase { "!/models/[1]/name=='"+modelName+"'", // but the wrapper model should be registered "/models/[0]/name=='"+modelName+"'", - "/models/[0]/class=='" + DefaultWrapperModel.class.getCanonicalName() + "'", + "/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/==[]", @@ -224,11 +224,11 @@ public class TestModelManagerPersistence extends TestRerankBase { "/features/==[]"); // setup features - loadFeature("popularity", FieldValueFeature.class.getCanonicalName(), FS_NAME, "{\"field\":\"popularity\"}"); - loadFeature("const", ValueFeature.class.getCanonicalName(), FS_NAME, "{\"value\":5}"); + 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.getCanonicalName(), + 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"); @@ -239,7 +239,7 @@ public class TestModelManagerPersistence extends TestRerankBase { baseModelFile.deleteOnExit(); // setup wrapper model - String wrapperModelJson = getModelInJson(modelName, DefaultWrapperModel.class.getCanonicalName(), + String wrapperModelJson = getModelInJson(modelName, DefaultWrapperModel.class.getName(), new String[0], FS_NAME, "{\"resource\":\"" + baseModelFile.getName() + "\"}"); assertJPut(ManagedModelStore.REST_END_POINT, wrapperModelJson, "/responseHeader/status==0");