This commit is contained in:
Uwe Schindler 2018-02-09 19:56:59 +01:00
commit 7d3fccefe6
29 changed files with 193 additions and 125 deletions

View File

@ -195,6 +195,8 @@ Bug Fixes
* SOLR-11459: In-place update of nonexistent doc following existing doc update fails to create the doc. * SOLR-11459: In-place update of nonexistent doc following existing doc update fails to create the doc.
(Andrey Kudryavtsev via Mikhail Khludnev) (Andrey Kudryavtsev via Mikhail Khludnev)
* SOLR-11931: Fix contrib/ltr custom inner class feature/normaliser/model persistence. (Christine Poerschke)
Optimizations Optimizations
---------------------- ----------------------

View File

@ -192,7 +192,7 @@ public class ManagedFeatureStore extends ManagedResource implements ManagedResou
private static LinkedHashMap<String,Object> toFeatureMap(Feature feat) { private static LinkedHashMap<String,Object> toFeatureMap(Feature feat) {
final LinkedHashMap<String,Object> o = new LinkedHashMap<>(4, 1.0f); // 1 extra for caller to add store final LinkedHashMap<String,Object> o = new LinkedHashMap<>(4, 1.0f); // 1 extra for caller to add store
o.put(NAME_KEY, feat.getName()); 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()); o.put(PARAMS_KEY, feat.paramsToMap());
return o; return o;
} }

View File

@ -268,7 +268,7 @@ public class ManagedModelStore extends ManagedResource implements ManagedResourc
final LinkedHashMap<String,Object> modelMap = new LinkedHashMap<>(5, 1.0f); final LinkedHashMap<String,Object> modelMap = new LinkedHashMap<>(5, 1.0f);
modelMap.put(NAME_KEY, model.getName()); 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()); modelMap.put(STORE_KEY, model.getFeatureStoreName());
final List<Map<String,Object>> features = new ArrayList<>(); final List<Map<String,Object>> features = new ArrayList<>();
@ -321,7 +321,7 @@ public class ManagedModelStore extends ManagedResource implements ManagedResourc
private static LinkedHashMap<String,Object> toNormalizerMap(Normalizer norm) { private static LinkedHashMap<String,Object> toNormalizerMap(Normalizer norm) {
final LinkedHashMap<String,Object> normalizer = new LinkedHashMap<>(2, 1.0f); final LinkedHashMap<String,Object> normalizer = new LinkedHashMap<>(2, 1.0f);
normalizer.put(CLASS_KEY, norm.getClass().getCanonicalName()); normalizer.put(CLASS_KEY, norm.getClass().getName());
final LinkedHashMap<String,Object> params = norm.paramsToMap(); final LinkedHashMap<String,Object> params = norm.paramsToMap();
if (params != null) { if (params != null) {

View File

@ -262,26 +262,26 @@ public class TestLTROnSolrCloud extends TestRerankBase {
loadFeature( loadFeature(
featureNames[0], featureNames[0],
SolrFeature.class.getCanonicalName(), SolrFeature.class.getName(),
featureStore, featureStore,
"{\"q\":\"{!func}pow(popularity,2)\"}" "{\"q\":\"{!func}pow(popularity,2)\"}"
); );
loadFeature( loadFeature(
featureNames[1], featureNames[1],
ValueFeature.class.getCanonicalName(), ValueFeature.class.getName(),
featureStore, featureStore,
"{\"value\":2}" "{\"value\":2}"
); );
loadFeature( loadFeature(
featureNames[2], featureNames[2],
OriginalScoreFeature.class.getCanonicalName(), OriginalScoreFeature.class.getName(),
featureStore, featureStore,
null null
); );
loadModel( loadModel(
"powpularityS-model", "powpularityS-model",
LinearModel.class.getCanonicalName(), LinearModel.class.getName(),
featureNames, featureNames,
featureStore, featureStore,
jsonModelParams jsonModelParams

View File

@ -38,7 +38,7 @@ public class TestLTRQParserExplain extends TestRerankBase {
@Test @Test
public void testRerankedExplain() throws Exception { public void testRerankedExplain() throws Exception {
loadModel("linear2", LinearModel.class.getCanonicalName(), new String[] { loadModel("linear2", LinearModel.class.getName(), new String[] {
"constant1", "constant2", "pop"}, "constant1", "constant2", "pop"},
"{\"weights\":{\"pop\":1.0,\"constant1\":1.5,\"constant2\":3.5}}"); "{\"weights\":{\"pop\":1.0,\"constant1\":1.5,\"constant2\":3.5}}");

View File

@ -77,7 +77,7 @@ public class TestLTRReRankingPipeline extends LuceneTestCase {
final Map<String,Object> params = new HashMap<String,Object>(); final Map<String,Object> params = new HashMap<String,Object>();
params.put("field", field); params.put("field", field);
final Feature f = Feature.getInstance(solrResourceLoader, final Feature f = Feature.getInstance(solrResourceLoader,
FieldValueFeature.class.getCanonicalName(), FieldValueFeature.class.getName(),
"f" + i, params); "f" + i, params);
f.setIndex(i); f.setIndex(i);
features.add(f); features.add(f);

View File

@ -68,7 +68,7 @@ public class TestLTRScoringQuery extends LuceneTestCase {
Map<String,Object> params = new HashMap<String,Object>(); Map<String,Object> params = new HashMap<String,Object>();
params.put("value", i); params.put("value", i);
final Feature f = Feature.getInstance(solrResourceLoader, final Feature f = Feature.getInstance(solrResourceLoader,
ValueFeature.class.getCanonicalName(), ValueFeature.class.getName(),
"f" + i, params); "f" + i, params);
f.setIndex(i); f.setIndex(i);
features.add(f); features.add(f);
@ -82,7 +82,7 @@ public class TestLTRScoringQuery extends LuceneTestCase {
Map<String,Object> params = new HashMap<String,Object>(); Map<String,Object> params = new HashMap<String,Object>();
params.put("value", i); params.put("value", i);
final Feature f = Feature.getInstance(solrResourceLoader, final Feature f = Feature.getInstance(solrResourceLoader,
ValueFeature.class.getCanonicalName(), ValueFeature.class.getName(),
"f" + i, params); "f" + i, params);
f.setIndex(i); f.setIndex(i);
features.add(f); features.add(f);

View File

@ -52,10 +52,10 @@ public class TestLTRWithFacet extends TestRerankBase {
@Test @Test
public void testRankingSolrFacet() throws Exception { public void testRankingSolrFacet() throws Exception {
// before(); // before();
loadFeature("powpularityS", SolrFeature.class.getCanonicalName(), loadFeature("powpularityS", SolrFeature.class.getName(),
"{\"q\":\"{!func}pow(popularity,2)\"}"); "{\"q\":\"{!func}pow(popularity,2)\"}");
loadModel("powpularityS-model", LinearModel.class.getCanonicalName(), loadModel("powpularityS-model", LinearModel.class.getName(),
new String[] {"powpularityS"}, "{\"weights\":{\"powpularityS\":1.0}}"); new String[] {"powpularityS"}, "{\"weights\":{\"powpularityS\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();

View File

@ -51,10 +51,10 @@ public class TestLTRWithSort extends TestRerankBase {
@Test @Test
public void testRankingSolrSort() throws Exception { public void testRankingSolrSort() throws Exception {
// before(); // before();
loadFeature("powpularityS", SolrFeature.class.getCanonicalName(), loadFeature("powpularityS", SolrFeature.class.getName(),
"{\"q\":\"{!func}pow(popularity,2)\"}"); "{\"q\":\"{!func}pow(popularity,2)\"}");
loadModel("powpularityS-model", LinearModel.class.getCanonicalName(), loadModel("powpularityS-model", LinearModel.class.getName(),
new String[] {"powpularityS"}, "{\"weights\":{\"powpularityS\":1.0}}"); new String[] {"powpularityS"}, "{\"weights\":{\"powpularityS\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();

View File

@ -63,7 +63,7 @@ public class TestSelectiveWeightCreation extends TestRerankBase {
Map<String,Object> params = new HashMap<String,Object>(); Map<String,Object> params = new HashMap<String,Object>();
params.put("value", i); params.put("value", i);
final Feature f = Feature.getInstance(solrResourceLoader, final Feature f = Feature.getInstance(solrResourceLoader,
ValueFeature.class.getCanonicalName(), ValueFeature.class.getName(),
"f" + i, params); "f" + i, params);
f.setIndex(i); f.setIndex(i);
features.add(f); features.add(f);

View File

@ -57,10 +57,10 @@ public class TestEdisMaxSolrFeature extends TestRerankBase {
public void testEdisMaxSolrFeature() throws Exception { public void testEdisMaxSolrFeature() throws Exception {
loadFeature( loadFeature(
"SomeEdisMax", "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}\"}"); "{\"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}}"); new String[] {"SomeEdisMax"}, "{\"weights\":{\"SomeEdisMax\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();

View File

@ -39,20 +39,20 @@ public class TestFeatureLogging extends TestRerankBase {
@Test @Test
public void testGeneratedFeatures() throws Exception { public void testGeneratedFeatures() throws Exception {
loadFeature("c1", ValueFeature.class.getCanonicalName(), "test1", loadFeature("c1", ValueFeature.class.getName(), "test1",
"{\"value\":1.0}"); "{\"value\":1.0}");
loadFeature("c2", ValueFeature.class.getCanonicalName(), "test1", loadFeature("c2", ValueFeature.class.getName(), "test1",
"{\"value\":2.0}"); "{\"value\":2.0}");
loadFeature("c3", ValueFeature.class.getCanonicalName(), "test1", loadFeature("c3", ValueFeature.class.getName(), "test1",
"{\"value\":3.0}"); "{\"value\":3.0}");
loadFeature("pop", FieldValueFeature.class.getCanonicalName(), "test1", loadFeature("pop", FieldValueFeature.class.getName(), "test1",
"{\"field\":\"popularity\"}"); "{\"field\":\"popularity\"}");
loadFeature("nomatch", SolrFeature.class.getCanonicalName(), "test1", loadFeature("nomatch", SolrFeature.class.getName(), "test1",
"{\"q\":\"{!terms f=title}foobarbat\"}"); "{\"q\":\"{!terms f=title}foobarbat\"}");
loadFeature("yesmatch", SolrFeature.class.getCanonicalName(), "test1", loadFeature("yesmatch", SolrFeature.class.getName(), "test1",
"{\"q\":\"{!terms f=popularity}2\"}"); "{\"q\":\"{!terms f=popularity}2\"}");
loadModel("sum1", LinearModel.class.getCanonicalName(), new String[] { loadModel("sum1", LinearModel.class.getName(), new String[] {
"c1", "c2", "c3"}, "test1", "c1", "c2", "c3"}, "test1",
"{\"weights\":{\"c1\":1.0,\"c2\":1.0,\"c3\":1.0}}"); "{\"weights\":{\"c1\":1.0,\"c2\":1.0,\"c3\":1.0}}");
@ -96,16 +96,16 @@ public class TestFeatureLogging extends TestRerankBase {
@Test @Test
public void testDefaultStoreFeatureExtraction() throws Exception { public void testDefaultStoreFeatureExtraction() throws Exception {
loadFeature("defaultf1", ValueFeature.class.getCanonicalName(), loadFeature("defaultf1", ValueFeature.class.getName(),
FeatureStore.DEFAULT_FEATURE_STORE_NAME, FeatureStore.DEFAULT_FEATURE_STORE_NAME,
"{\"value\":1.0}"); "{\"value\":1.0}");
loadFeature("store8f1", ValueFeature.class.getCanonicalName(), loadFeature("store8f1", ValueFeature.class.getName(),
"store8", "store8",
"{\"value\":2.0}"); "{\"value\":2.0}");
loadFeature("store9f1", ValueFeature.class.getCanonicalName(), loadFeature("store9f1", ValueFeature.class.getName(),
"store9", "store9",
"{\"value\":3.0}"); "{\"value\":3.0}");
loadModel("store9m1", LinearModel.class.getCanonicalName(), loadModel("store9m1", LinearModel.class.getName(),
new String[] {"store9f1"}, new String[] {"store9f1"},
"store9", "store9",
"{\"weights\":{\"store9f1\":1.0}}"); "{\"weights\":{\"store9f1\":1.0}}");
@ -140,16 +140,16 @@ public class TestFeatureLogging extends TestRerankBase {
@Test @Test
public void testGeneratedGroup() throws Exception { public void testGeneratedGroup() throws Exception {
loadFeature("c1", ValueFeature.class.getCanonicalName(), "testgroup", loadFeature("c1", ValueFeature.class.getName(), "testgroup",
"{\"value\":1.0}"); "{\"value\":1.0}");
loadFeature("c2", ValueFeature.class.getCanonicalName(), "testgroup", loadFeature("c2", ValueFeature.class.getName(), "testgroup",
"{\"value\":2.0}"); "{\"value\":2.0}");
loadFeature("c3", ValueFeature.class.getCanonicalName(), "testgroup", loadFeature("c3", ValueFeature.class.getName(), "testgroup",
"{\"value\":3.0}"); "{\"value\":3.0}");
loadFeature("pop", FieldValueFeature.class.getCanonicalName(), "testgroup", loadFeature("pop", FieldValueFeature.class.getName(), "testgroup",
"{\"field\":\"popularity\"}"); "{\"field\":\"popularity\"}");
loadModel("sumgroup", LinearModel.class.getCanonicalName(), new String[] { loadModel("sumgroup", LinearModel.class.getName(), new String[] {
"c1", "c2", "c3"}, "testgroup", "c1", "c2", "c3"}, "testgroup",
"{\"weights\":{\"c1\":1.0,\"c2\":1.0,\"c3\":1.0}}"); "{\"weights\":{\"c1\":1.0,\"c2\":1.0,\"c3\":1.0}}");
@ -180,12 +180,12 @@ public class TestFeatureLogging extends TestRerankBase {
@Test @Test
public void testSparseDenseFeatures() throws Exception { public void testSparseDenseFeatures() throws Exception {
loadFeature("match", SolrFeature.class.getCanonicalName(), "test4", loadFeature("match", SolrFeature.class.getName(), "test4",
"{\"q\":\"{!terms f=title}different\"}"); "{\"q\":\"{!terms f=title}different\"}");
loadFeature("c4", ValueFeature.class.getCanonicalName(), "test4", loadFeature("c4", ValueFeature.class.getName(), "test4",
"{\"value\":1.0}"); "{\"value\":1.0}");
loadModel("sum4", LinearModel.class.getCanonicalName(), new String[] { loadModel("sum4", LinearModel.class.getName(), new String[] {
"match"}, "test4", "match"}, "test4",
"{\"weights\":{\"match\":1.0}}"); "{\"weights\":{\"match\":1.0}}");

View File

@ -54,10 +54,10 @@ public class TestFieldLengthFeature extends TestRerankBase {
assertU(adoc("id", "42", "title", "w10")); assertU(adoc("id", "42", "title", "w10"));
assertU(commit()); assertU(commit());
loadFeature("description-length2", FieldLengthFeature.class.getCanonicalName(), loadFeature("description-length2", FieldLengthFeature.class.getName(),
"{\"field\":\"description\"}"); "{\"field\":\"description\"}");
loadModel("description-model2", LinearModel.class.getCanonicalName(), loadModel("description-model2", LinearModel.class.getName(),
new String[] {"description-length2"}, "{\"weights\":{\"description-length2\":1.0}}"); new String[] {"description-length2"}, "{\"weights\":{\"description-length2\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();
@ -75,10 +75,10 @@ public class TestFieldLengthFeature extends TestRerankBase {
assertU(adoc("id", "43", "title", "w11", "description", "")); assertU(adoc("id", "43", "title", "w11", "description", ""));
assertU(commit()); assertU(commit());
loadFeature("description-length3", FieldLengthFeature.class.getCanonicalName(), loadFeature("description-length3", FieldLengthFeature.class.getName(),
"{\"field\":\"description\"}"); "{\"field\":\"description\"}");
loadModel("description-model3", LinearModel.class.getCanonicalName(), loadModel("description-model3", LinearModel.class.getName(),
new String[] {"description-length3"}, "{\"weights\":{\"description-length3\":1.0}}"); new String[] {"description-length3"}, "{\"weights\":{\"description-length3\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();
@ -92,10 +92,10 @@ public class TestFieldLengthFeature extends TestRerankBase {
@Test @Test
public void testRanking() throws Exception { public void testRanking() throws Exception {
loadFeature("title-length", FieldLengthFeature.class.getCanonicalName(), loadFeature("title-length", FieldLengthFeature.class.getName(),
"{\"field\":\"title\"}"); "{\"field\":\"title\"}");
loadModel("title-model", LinearModel.class.getCanonicalName(), loadModel("title-model", LinearModel.class.getName(),
new String[] {"title-length"}, "{\"weights\":{\"title-length\":1.0}}"); new String[] {"title-length"}, "{\"weights\":{\"title-length\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();
@ -131,9 +131,9 @@ public class TestFieldLengthFeature extends TestRerankBase {
assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='6'"); assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='6'");
loadFeature("description-length", loadFeature("description-length",
FieldLengthFeature.class.getCanonicalName(), FieldLengthFeature.class.getName(),
"{\"field\":\"description\"}"); "{\"field\":\"description\"}");
loadModel("description-model", LinearModel.class.getCanonicalName(), loadModel("description-model", LinearModel.class.getName(),
new String[] {"description-length"}, new String[] {"description-length"},
"{\"weights\":{\"description-length\":1.0}}"); "{\"weights\":{\"description-length\":1.0}}");
query.setQuery("title:w1"); query.setQuery("title:w1");

View File

@ -54,10 +54,10 @@ public class TestFieldValueFeature extends TestRerankBase {
assertU(commit()); assertU(commit());
loadFeature("popularity", FieldValueFeature.class.getCanonicalName(), loadFeature("popularity", FieldValueFeature.class.getName(),
"{\"field\":\"popularity\"}"); "{\"field\":\"popularity\"}");
loadModel("popularity-model", LinearModel.class.getCanonicalName(), loadModel("popularity-model", LinearModel.class.getName(),
new String[] {"popularity"}, "{\"weights\":{\"popularity\":1.0}}"); new String[] {"popularity"}, "{\"weights\":{\"popularity\":1.0}}");
} }
@ -127,7 +127,7 @@ public class TestFieldValueFeature extends TestRerankBase {
final String fstore = "testIfADocumentDoesntHaveAFieldASetDefaultValueIsReturned"; final String fstore = "testIfADocumentDoesntHaveAFieldASetDefaultValueIsReturned";
loadFeature("popularity42", FieldValueFeature.class.getCanonicalName(), fstore, loadFeature("popularity42", FieldValueFeature.class.getName(), fstore,
"{\"field\":\"popularity\",\"defaultValue\":\"42.0\"}"); "{\"field\":\"popularity\",\"defaultValue\":\"42.0\"}");
SolrQuery query = new SolrQuery(); SolrQuery query = new SolrQuery();
@ -135,7 +135,7 @@ public class TestFieldValueFeature extends TestRerankBase {
query.add("fl", "*, score"); query.add("fl", "*, score");
query.add("rows", "4"); query.add("rows", "4");
loadModel("popularity-model42", LinearModel.class.getCanonicalName(), loadModel("popularity-model42", LinearModel.class.getName(),
new String[] {"popularity42"}, fstore, "{\"weights\":{\"popularity42\":1.0}}"); new String[] {"popularity42"}, fstore, "{\"weights\":{\"popularity42\":1.0}}");
assertJQ("/query" + query.toQueryString(), "/response/numFound/==1"); assertJQ("/query" + query.toQueryString(), "/response/numFound/==1");
@ -154,10 +154,10 @@ public class TestFieldValueFeature extends TestRerankBase {
public void testThatIfaFieldDoesNotExistDefaultValueIsReturned() throws Exception { public void testThatIfaFieldDoesNotExistDefaultValueIsReturned() throws Exception {
// using a different fstore to avoid a clash with the other tests // using a different fstore to avoid a clash with the other tests
final String fstore = "testThatIfaFieldDoesNotExistDefaultValueIsReturned"; final String fstore = "testThatIfaFieldDoesNotExistDefaultValueIsReturned";
loadFeature("not-existing-field", FieldValueFeature.class.getCanonicalName(), fstore, loadFeature("not-existing-field", FieldValueFeature.class.getName(), fstore,
"{\"field\":\"cowabunga\"}"); "{\"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}}"); new String[] {"not-existing-field"}, fstore, "{\"weights\":{\"not-existing-field\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();
@ -173,10 +173,10 @@ public class TestFieldValueFeature extends TestRerankBase {
@Test @Test
public void testBooleanValue() throws Exception { public void testBooleanValue() throws Exception {
final String fstore = "test_boolean_store"; final String fstore = "test_boolean_store";
loadFeature("trendy", FieldValueFeature.class.getCanonicalName(), fstore, loadFeature("trendy", FieldValueFeature.class.getName(), fstore,
"{\"field\":\"isTrendy\"}"); "{\"field\":\"isTrendy\"}");
loadModel("trendy-model", LinearModel.class.getCanonicalName(), loadModel("trendy-model", LinearModel.class.getName(),
new String[] {"trendy"}, fstore, "{\"weights\":{\"trendy\":1.0}}"); new String[] {"trendy"}, fstore, "{\"weights\":{\"trendy\":1.0}}");
SolrQuery query = new SolrQuery(); SolrQuery query = new SolrQuery();

View File

@ -56,11 +56,11 @@ public class TestFilterSolrFeature extends TestRerankBase {
@Test @Test
public void testUserTermScoreWithFQ() throws Exception { public void testUserTermScoreWithFQ() throws Exception {
loadFeature("SomeTermFQ", SolrFeature.class.getCanonicalName(), loadFeature("SomeTermFQ", SolrFeature.class.getName(),
"{\"fq\":[\"{!terms f=popularity}88888\"]}"); "{\"fq\":[\"{!terms f=popularity}88888\"]}");
loadFeature("SomeEfiFQ", SolrFeature.class.getCanonicalName(), loadFeature("SomeEfiFQ", SolrFeature.class.getName(),
"{\"fq\":[\"{!terms f=title}${user_query}\"]}"); "{\"fq\":[\"{!terms f=title}${user_query}\"]}");
loadModel("Term-modelFQ", LinearModel.class.getCanonicalName(), loadModel("Term-modelFQ", LinearModel.class.getName(),
new String[] {"SomeTermFQ", "SomeEfiFQ"}, new String[] {"SomeTermFQ", "SomeEfiFQ"},
"{\"weights\":{\"SomeTermFQ\":1.6, \"SomeEfiFQ\":2.0}}"); "{\"weights\":{\"SomeTermFQ\":1.6, \"SomeEfiFQ\":2.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();
@ -80,7 +80,7 @@ public class TestFilterSolrFeature extends TestRerankBase {
public void testBadFeature() throws Exception { public void testBadFeature() throws Exception {
// Missing q/fq // Missing q/fq
final String feature = getFeatureInJson("badFeature", "test", final String feature = getFeatureInJson("badFeature", "test",
SolrFeature.class.getCanonicalName(), "{\"df\":\"foo\"]}"); SolrFeature.class.getName(), "{\"df\":\"foo\"]}");
assertJPut(ManagedFeatureStore.REST_END_POINT, feature, assertJPut(ManagedFeatureStore.REST_END_POINT, feature,
"/responseHeader/status==500"); "/responseHeader/status==500");
} }

View File

@ -53,27 +53,27 @@ public class TestNoMatchSolrFeature extends TestRerankBase {
"w1 w1 w1 w2 w2", "popularity", "8")); "w1 w1 w1 w2 w2", "popularity", "8"));
assertU(commit()); assertU(commit());
loadFeature("nomatchfeature", SolrFeature.class.getCanonicalName(), loadFeature("nomatchfeature", SolrFeature.class.getName(),
"{\"q\":\"foobarbat12345\",\"df\":\"title\"}"); "{\"q\":\"foobarbat12345\",\"df\":\"title\"}");
loadFeature("yesmatchfeature", SolrFeature.class.getCanonicalName(), loadFeature("yesmatchfeature", SolrFeature.class.getName(),
"{\"q\":\"w1\",\"df\":\"title\"}"); "{\"q\":\"w1\",\"df\":\"title\"}");
loadFeature("nomatchfeature2", SolrFeature.class.getCanonicalName(), loadFeature("nomatchfeature2", SolrFeature.class.getName(),
"{\"q\":\"foobarbat12345\",\"df\":\"title\"}"); "{\"q\":\"foobarbat12345\",\"df\":\"title\"}");
loadModel( loadModel(
"nomatchmodel", "nomatchmodel",
LinearModel.class.getCanonicalName(), LinearModel.class.getName(),
new String[] {"nomatchfeature", "yesmatchfeature", "nomatchfeature2"}, new String[] {"nomatchfeature", "yesmatchfeature", "nomatchfeature2"},
"{\"weights\":{\"nomatchfeature\":1.0,\"yesmatchfeature\":1.1,\"nomatchfeature2\":1.1}}"); "{\"weights\":{\"nomatchfeature\":1.0,\"yesmatchfeature\":1.1,\"nomatchfeature2\":1.1}}");
loadFeature("nomatchfeature3", SolrFeature.class.getCanonicalName(), loadFeature("nomatchfeature3", SolrFeature.class.getName(),
"{\"q\":\"foobarbat12345\",\"df\":\"title\"}"); "{\"q\":\"foobarbat12345\",\"df\":\"title\"}");
loadModel("nomatchmodel2", LinearModel.class.getCanonicalName(), loadModel("nomatchmodel2", LinearModel.class.getName(),
new String[] {"nomatchfeature3"}, new String[] {"nomatchfeature3"},
"{\"weights\":{\"nomatchfeature3\":1.0}}"); "{\"weights\":{\"nomatchfeature3\":1.0}}");
loadFeature("nomatchfeature4", SolrFeature.class.getCanonicalName(), loadFeature("nomatchfeature4", SolrFeature.class.getName(),
"noMatchFeaturesStore", "{\"q\":\"foobarbat12345\",\"df\":\"title\"}"); "noMatchFeaturesStore", "{\"q\":\"foobarbat12345\",\"df\":\"title\"}");
loadModel("nomatchmodel3", LinearModel.class.getCanonicalName(), loadModel("nomatchmodel3", LinearModel.class.getName(),
new String[] {"nomatchfeature4"}, "noMatchFeaturesStore", new String[] {"nomatchfeature4"}, "noMatchFeaturesStore",
"{\"weights\":{\"nomatchfeature4\":1.0}}"); "{\"weights\":{\"nomatchfeature4\":1.0}}");
} }
@ -239,7 +239,7 @@ public class TestNoMatchSolrFeature extends TestRerankBase {
// MultipleAdditiveTrees will return scores even for docs without any feature matches // MultipleAdditiveTrees will return scores even for docs without any feature matches
loadModel( loadModel(
"nomatchmodel4", "nomatchmodel4",
MultipleAdditiveTreesModel.class.getCanonicalName(), MultipleAdditiveTreesModel.class.getName(),
new String[] {"nomatchfeature4"}, new String[] {"nomatchfeature4"},
"noMatchFeaturesStore", "noMatchFeaturesStore",
"{\"trees\":[{\"weight\":\"1f\", \"root\":{\"feature\": \"matchedTitle\",\"threshold\": \"0.5f\",\"left\":{\"value\" : \"-10\"},\"right\":{\"value\" : \"9\"}}}]}"); "{\"trees\":[{\"weight\":\"1f\", \"root\":{\"feature\": \"matchedTitle\",\"threshold\": \"0.5f\",\"left\":{\"value\" : \"-10\"},\"right\":{\"value\" : \"9\"}}}]}");

View File

@ -53,8 +53,8 @@ public class TestOriginalScoreFeature extends TestRerankBase {
@Test @Test
public void testOriginalScore() throws Exception { public void testOriginalScore() throws Exception {
loadFeature("score", OriginalScoreFeature.class.getCanonicalName(), "{}"); loadFeature("score", OriginalScoreFeature.class.getName(), "{}");
loadModel("originalScore", LinearModel.class.getCanonicalName(), loadModel("originalScore", LinearModel.class.getName(),
new String[] {"score"}, "{\"weights\":{\"score\":1.0}}"); new String[] {"score"}, "{\"weights\":{\"score\":1.0}}");
implTestOriginalScoreResponseDocsCheck("originalScore", "score", null, null); implTestOriginalScoreResponseDocsCheck("originalScore", "score", null, null);
@ -62,12 +62,12 @@ public class TestOriginalScoreFeature extends TestRerankBase {
@Test @Test
public void testOriginalScoreWithNonScoringFeatures() throws Exception { public void testOriginalScoreWithNonScoringFeatures() throws Exception {
loadFeature("origScore", OriginalScoreFeature.class.getCanonicalName(), loadFeature("origScore", OriginalScoreFeature.class.getName(),
"store2", "{}"); "store2", "{}");
loadFeature("c2", ValueFeature.class.getCanonicalName(), "store2", loadFeature("c2", ValueFeature.class.getName(), "store2",
"{\"value\":2.0}"); "{\"value\":2.0}");
loadModel("origScore", LinearModel.class.getCanonicalName(), loadModel("origScore", LinearModel.class.getName(),
new String[] {"origScore"}, "store2", new String[] {"origScore"}, "store2",
"{\"weights\":{\"origScore\":1.0}}"); "{\"weights\":{\"origScore\":1.0}}");

View File

@ -57,14 +57,14 @@ public class TestRankingFeature extends TestRerankBase {
@Test @Test
public void testRankingSolrFeature() throws Exception { public void testRankingSolrFeature() throws Exception {
// before(); // before();
loadFeature("powpularityS", SolrFeature.class.getCanonicalName(), loadFeature("powpularityS", SolrFeature.class.getName(),
"{\"q\":\"{!func}pow(popularity,2)\"}"); "{\"q\":\"{!func}pow(popularity,2)\"}");
loadFeature("unpopularityS", SolrFeature.class.getCanonicalName(), loadFeature("unpopularityS", SolrFeature.class.getName(),
"{\"q\":\"{!func}div(1,popularity)\"}"); "{\"q\":\"{!func}div(1,popularity)\"}");
loadModel("powpularityS-model", LinearModel.class.getCanonicalName(), loadModel("powpularityS-model", LinearModel.class.getName(),
new String[] {"powpularityS"}, "{\"weights\":{\"powpularityS\":1.0}}"); 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}}"); new String[] {"unpopularityS"}, "{\"weights\":{\"unpopularityS\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();
@ -104,16 +104,16 @@ public class TestRankingFeature extends TestRerankBase {
assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='8'"); assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='8'");
//bad solr ranking feature //bad solr ranking feature
loadFeature("powdesS", SolrFeature.class.getCanonicalName(), loadFeature("powdesS", SolrFeature.class.getName(),
"{\"q\":\"{!func}pow(description,2)\"}"); "{\"q\":\"{!func}pow(description,2)\"}");
loadModel("powdesS-model", LinearModel.class.getCanonicalName(), loadModel("powdesS-model", LinearModel.class.getName(),
new String[] {"powdesS"}, "{\"weights\":{\"powdesS\":1.0}}"); new String[] {"powdesS"}, "{\"weights\":{\"powdesS\":1.0}}");
query.remove("rq"); query.remove("rq");
query.add("rq", "{!ltr model=powdesS-model reRankDocs=4}"); query.add("rq", "{!ltr model=powdesS-model reRankDocs=4}");
assertJQ("/query" + query.toQueryString(), assertJQ("/query" + query.toQueryString(),
"/error/msg/=='"+FeatureException.class.getCanonicalName()+": " + "/error/msg/=='"+FeatureException.class.getName()+": " +
"java.lang.UnsupportedOperationException: " + "java.lang.UnsupportedOperationException: " +
"Unable to extract feature for powdesS'"); "Unable to extract feature for powdesS'");
// aftertest(); // aftertest();

View File

@ -56,9 +56,9 @@ public class TestUserTermScoreWithQ extends TestRerankBase {
@Test @Test
public void testUserTermScoreWithQ() throws Exception { public void testUserTermScoreWithQ() throws Exception {
// before(); // before();
loadFeature("SomeTermQ", SolrFeature.class.getCanonicalName(), loadFeature("SomeTermQ", SolrFeature.class.getName(),
"{\"q\":\"{!terms f=popularity}88888\"}"); "{\"q\":\"{!terms f=popularity}88888\"}");
loadModel("Term-modelQ", LinearModel.class.getCanonicalName(), loadModel("Term-modelQ", LinearModel.class.getName(),
new String[] {"SomeTermQ"}, "{\"weights\":{\"SomeTermQ\":1.0}}"); new String[] {"SomeTermQ"}, "{\"weights\":{\"SomeTermQ\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();
query.setQuery("title:w1"); query.setQuery("title:w1");

View File

@ -56,9 +56,9 @@ public class TestUserTermScorerQuery extends TestRerankBase {
@Test @Test
public void testUserTermScorerQuery() throws Exception { public void testUserTermScorerQuery() throws Exception {
// before(); // before();
loadFeature("matchedTitleDFExt", SolrFeature.class.getCanonicalName(), loadFeature("matchedTitleDFExt", SolrFeature.class.getName(),
"{\"q\":\"${user_query}\",\"df\":\"title\"}"); "{\"q\":\"${user_query}\",\"df\":\"title\"}");
loadModel("Term-matchedTitleDFExt", LinearModel.class.getCanonicalName(), loadModel("Term-matchedTitleDFExt", LinearModel.class.getName(),
new String[] {"matchedTitleDFExt"}, new String[] {"matchedTitleDFExt"},
"{\"weights\":{\"matchedTitleDFExt\":1.1}}"); "{\"weights\":{\"matchedTitleDFExt\":1.1}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();

View File

@ -56,9 +56,9 @@ public class TestUserTermScorereQDF extends TestRerankBase {
@Test @Test
public void testUserTermScorerQWithDF() throws Exception { public void testUserTermScorerQWithDF() throws Exception {
// before(); // before();
loadFeature("matchedTitleDF", SolrFeature.class.getCanonicalName(), loadFeature("matchedTitleDF", SolrFeature.class.getName(),
"{\"q\":\"w5\",\"df\":\"title\"}"); "{\"q\":\"w5\",\"df\":\"title\"}");
loadModel("Term-matchedTitleDF", LinearModel.class.getCanonicalName(), loadModel("Term-matchedTitleDF", LinearModel.class.getName(),
new String[] {"matchedTitleDF"}, new String[] {"matchedTitleDF"},
"{\"weights\":{\"matchedTitleDF\":1.0}}"); "{\"weights\":{\"matchedTitleDF\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();

View File

@ -50,7 +50,7 @@ public class TestValueFeature extends TestRerankBase {
final RuntimeException expectedException = final RuntimeException expectedException =
new RuntimeException("mismatch: '0'!='500' @ responseHeader/status"); new RuntimeException("mismatch: '0'!='500' @ responseHeader/status");
try { try {
loadFeature("c2", ValueFeature.class.getCanonicalName(), "{\"value\":\"\"}"); loadFeature("c2", ValueFeature.class.getName(), "{\"value\":\"\"}");
fail("testValueFeatureWithEmptyValue failed to throw exception: "+expectedException); fail("testValueFeatureWithEmptyValue failed to throw exception: "+expectedException);
} catch (RuntimeException actualException) { } catch (RuntimeException actualException) {
assertEquals(expectedException.toString(), actualException.toString()); assertEquals(expectedException.toString(), actualException.toString());
@ -62,7 +62,7 @@ public class TestValueFeature extends TestRerankBase {
final RuntimeException expectedException = final RuntimeException expectedException =
new RuntimeException("mismatch: '0'!='500' @ responseHeader/status"); new RuntimeException("mismatch: '0'!='500' @ responseHeader/status");
try { try {
loadFeature("c2", ValueFeature.class.getCanonicalName(), loadFeature("c2", ValueFeature.class.getName(),
"{\"value\":\" \"}"); "{\"value\":\" \"}");
fail("testValueFeatureWithWhitespaceValue failed to throw exception: "+expectedException); fail("testValueFeatureWithWhitespaceValue failed to throw exception: "+expectedException);
} catch (RuntimeException actualException) { } catch (RuntimeException actualException) {
@ -72,9 +72,9 @@ public class TestValueFeature extends TestRerankBase {
@Test @Test
public void testRerankingWithConstantValueFeatureReplacesDocScore() throws Exception { public void testRerankingWithConstantValueFeatureReplacesDocScore() throws Exception {
loadFeature("c3", ValueFeature.class.getCanonicalName(), "c3", loadFeature("c3", ValueFeature.class.getName(), "c3",
"{\"value\":2}"); "{\"value\":2}");
loadModel("m3", LinearModel.class.getCanonicalName(), new String[] {"c3"}, loadModel("m3", LinearModel.class.getName(), new String[] {"c3"},
"c3", "{\"weights\":{\"c3\":1.0}}"); "c3", "{\"weights\":{\"c3\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();
@ -92,9 +92,9 @@ public class TestValueFeature extends TestRerankBase {
@Test @Test
public void testRerankingWithEfiValueFeatureReplacesDocScore() throws Exception { public void testRerankingWithEfiValueFeatureReplacesDocScore() throws Exception {
loadFeature("c6", ValueFeature.class.getCanonicalName(), "c6", loadFeature("c6", ValueFeature.class.getName(), "c6",
"{\"value\":\"${val6}\"}"); "{\"value\":\"${val6}\"}");
loadModel("m6", LinearModel.class.getCanonicalName(), new String[] {"c6"}, loadModel("m6", LinearModel.class.getName(), new String[] {"c6"},
"c6", "{\"weights\":{\"c6\":1.0}}"); "c6", "{\"weights\":{\"c6\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();
@ -113,9 +113,9 @@ public class TestValueFeature extends TestRerankBase {
@Test @Test
public void testValueFeatureImplicitlyNotRequiredShouldReturnOkStatusCode() throws Exception { public void testValueFeatureImplicitlyNotRequiredShouldReturnOkStatusCode() throws Exception {
loadFeature("c5", ValueFeature.class.getCanonicalName(), "c5", loadFeature("c5", ValueFeature.class.getName(), "c5",
"{\"value\":\"${val6}\"}"); "{\"value\":\"${val6}\"}");
loadModel("m5", LinearModel.class.getCanonicalName(), new String[] {"c5"}, loadModel("m5", LinearModel.class.getName(), new String[] {"c5"},
"c5", "{\"weights\":{\"c5\":1.0}}"); "c5", "{\"weights\":{\"c5\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();
@ -130,9 +130,9 @@ public class TestValueFeature extends TestRerankBase {
@Test @Test
public void testValueFeatureExplictlyNotRequiredShouldReturnOkStatusCode() throws Exception { public void testValueFeatureExplictlyNotRequiredShouldReturnOkStatusCode() throws Exception {
loadFeature("c7", ValueFeature.class.getCanonicalName(), "c7", loadFeature("c7", ValueFeature.class.getName(), "c7",
"{\"value\":\"${val7}\",\"required\":false}"); "{\"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}}"); "c7", "{\"weights\":{\"c7\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();
@ -147,9 +147,9 @@ public class TestValueFeature extends TestRerankBase {
@Test @Test
public void testValueFeatureRequiredShouldReturn400StatusCode() throws Exception { public void testValueFeatureRequiredShouldReturn400StatusCode() throws Exception {
loadFeature("c8", ValueFeature.class.getCanonicalName(), "c8", loadFeature("c8", ValueFeature.class.getName(), "c8",
"{\"value\":\"${val8}\",\"required\":true}"); "{\"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}}"); "c8", "{\"weights\":{\"c8\":1.0}}");
final SolrQuery query = new SolrQuery(); final SolrQuery query = new SolrQuery();

View File

@ -52,13 +52,13 @@ public class TestDefaultWrapperModel extends TestRerankBase {
assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5")); assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));
assertU(commit()); assertU(commit());
loadFeature("popularity", FieldValueFeature.class.getCanonicalName(), "test", "{\"field\":\"popularity\"}"); loadFeature("popularity", FieldValueFeature.class.getName(), "test", "{\"field\":\"popularity\"}");
loadFeature("const", ValueFeature.class.getCanonicalName(), "test", "{\"value\":5}"); loadFeature("const", ValueFeature.class.getName(), "test", "{\"value\":5}");
features = new ArrayList<>(); features = new ArrayList<>();
features.add(getManagedFeatureStore().getFeatureStore("test").get("popularity")); features.add(getManagedFeatureStore().getFeatureStore("test").get("popularity"));
features.add(getManagedFeatureStore().getFeatureStore("test").get("const")); features.add(getManagedFeatureStore().getFeatureStore("test").get("const"));
baseModelJson = getModelInJson("linear", LinearModel.class.getCanonicalName(), baseModelJson = getModelInJson("linear", LinearModel.class.getName(),
new String[] {"popularity", "const"}, new String[] {"popularity", "const"},
featureStoreName, featureStoreName,
"{\"weights\":{\"popularity\":-1.0, \"const\":1.0}}"); "{\"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) { 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); features, featureStoreName, params);
} }

View File

@ -39,7 +39,7 @@ public class TestLinearModel extends TestRerankBase {
String featureStoreName, List<Feature> allFeatures, String featureStoreName, List<Feature> allFeatures,
Map<String,Object> params) throws ModelException { Map<String,Object> params) throws ModelException {
final LTRScoringModel model = LTRScoringModel.getInstance(solrResourceLoader, final LTRScoringModel model = LTRScoringModel.getInstance(solrResourceLoader,
LinearModel.class.getCanonicalName(), LinearModel.class.getName(),
name, name,
features, norms, featureStoreName, allFeatures, params); features, norms, featureStoreName, allFeatures, params);
return model; return model;
@ -111,7 +111,7 @@ public class TestLinearModel extends TestRerankBase {
public void existingNameTest() { public void existingNameTest() {
final SolrException expectedException = final SolrException expectedException =
new SolrException(SolrException.ErrorCode.BAD_REQUEST, 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 { try {
final List<Feature> features = getFeatures(new String[] final List<Feature> features = getFeatures(new String[]
{"constant1", "constant5"}); {"constant1", "constant5"});

View File

@ -34,7 +34,7 @@ public class TestMinMaxNormalizer {
float expectedMin, float expectedMax) { float expectedMin, float expectedMax) {
final Normalizer n = Normalizer.getInstance( final Normalizer n = Normalizer.getInstance(
solrResourceLoader, solrResourceLoader,
MinMaxNormalizer.class.getCanonicalName(), MinMaxNormalizer.class.getName(),
params); params);
assertTrue(n instanceof MinMaxNormalizer); assertTrue(n instanceof MinMaxNormalizer);
final MinMaxNormalizer mmn = (MinMaxNormalizer)n; final MinMaxNormalizer mmn = (MinMaxNormalizer)n;

View File

@ -34,7 +34,7 @@ public class TestStandardNormalizer {
float expectedAvg, float expectedStd) { float expectedAvg, float expectedStd) {
final Normalizer n = Normalizer.getInstance( final Normalizer n = Normalizer.getInstance(
solrResourceLoader, solrResourceLoader,
StandardNormalizer.class.getCanonicalName(), StandardNormalizer.class.getName(),
params); params);
assertTrue(n instanceof StandardNormalizer); assertTrue(n instanceof StandardNormalizer);
final StandardNormalizer sn = (StandardNormalizer)n; final StandardNormalizer sn = (StandardNormalizer)n;
@ -122,7 +122,7 @@ public class TestStandardNormalizer {
params.put("std", "1.5f"); params.put("std", "1.5f");
final Normalizer norm = Normalizer.getInstance( final Normalizer norm = Normalizer.getInstance(
solrResourceLoader, solrResourceLoader,
StandardNormalizer.class.getCanonicalName(), StandardNormalizer.class.getName(),
params); params);
for (final float v : new float[] {10f, 20f, 25f, 30f, 31f, 40f, 42f, 100f, for (final float v : new float[] {10f, 20f, 25f, 30f, 31f, 40f, 42f, 100f,

View File

@ -66,7 +66,7 @@ public class TestManagedFeatureStore extends SolrTestCaseJ4 {
final String name = "c" + i; final String name = "c" + i;
fstore.addFeature(createMap(name, fstore.addFeature(createMap(name,
OriginalScoreFeature.class.getCanonicalName(), null), OriginalScoreFeature.class.getName(), null),
"fstore-testFeature"); "fstore-testFeature");
final Feature f = fs.get(name); final Feature f = fs.get(name);
@ -87,7 +87,7 @@ public class TestManagedFeatureStore extends SolrTestCaseJ4 {
final String name = "c" + i; final String name = "c" + i;
fstore.addFeature(createMap(name, fstore.addFeature(createMap(name,
ValueFeature.class.getCanonicalName(), params), ValueFeature.class.getName(), params),
"fstore-testFeature2"); "fstore-testFeature2");
} }
@ -109,7 +109,7 @@ public class TestManagedFeatureStore extends SolrTestCaseJ4 {
params.put("value", i); params.put("value", i);
final String name = "testc" + (float) i; final String name = "testc" + (float) i;
fstore.addFeature(createMap(name, fstore.addFeature(createMap(name,
ValueFeature.class.getCanonicalName(), params), ValueFeature.class.getName(), params),
"fstore-testFeature3"); "fstore-testFeature3");
} }
@ -120,13 +120,13 @@ public class TestManagedFeatureStore extends SolrTestCaseJ4 {
public void getInstanceTest() throws FeatureException public void getInstanceTest() throws FeatureException
{ {
fstore.addFeature(createMap("test", fstore.addFeature(createMap("test",
OriginalScoreFeature.class.getCanonicalName(), null), OriginalScoreFeature.class.getName(), null),
"testFstore"); "testFstore");
final Feature feature = fstore.getFeatureStore("testFstore").get("test"); final Feature feature = fstore.getFeatureStore("testFstore").get("test");
assertNotNull(feature); assertNotNull(feature);
assertEquals("test", feature.getName()); assertEquals("test", feature.getName());
assertEquals(OriginalScoreFeature.class.getCanonicalName(), feature assertEquals(OriginalScoreFeature.class.getName(), feature
.getClass().getCanonicalName()); .getClass().getName());
} }
@Test @Test

View File

@ -74,7 +74,7 @@ public class TestModelManager extends TestRerankBase {
// schema-rest.xml used by this test // schema-rest.xml used by this test
assertJQ("/schema/managed", "/responseHeader/status==0"); assertJQ("/schema/managed", "/responseHeader/status==0");
final String valueFeatureClassName = ValueFeature.class.getCanonicalName(); final String valueFeatureClassName = ValueFeature.class.getName();
// Add features // Add features
String feature = "{\"name\": \"test1\", \"class\": \""+valueFeatureClassName+"\", \"params\": {\"value\": 1} }"; String feature = "{\"name\": \"test1\", \"class\": \""+valueFeatureClassName+"\", \"params\": {\"value\": 1} }";
@ -98,14 +98,14 @@ public class TestModelManager extends TestRerankBase {
assertJPut(ManagedFeatureStore.REST_END_POINT, multipleFeatures, assertJPut(ManagedFeatureStore.REST_END_POINT, multipleFeatures,
"/responseHeader/status==0"); "/responseHeader/status==0");
final String fieldValueFeatureClassName = FieldValueFeature.class.getCanonicalName(); final String fieldValueFeatureClassName = FieldValueFeature.class.getName();
// Add bad feature (wrong params)_ // Add bad feature (wrong params)_
final String badfeature = "{\"name\": \"fvalue\", \"class\": \""+fieldValueFeatureClassName+"\", \"params\": {\"value\": 1} }"; final String badfeature = "{\"name\": \"fvalue\", \"class\": \""+fieldValueFeatureClassName+"\", \"params\": {\"value\": 1} }";
assertJPut(ManagedFeatureStore.REST_END_POINT, badfeature, assertJPut(ManagedFeatureStore.REST_END_POINT, badfeature,
"/error/msg/=='No setter corrresponding to \\'value\\' in "+fieldValueFeatureClassName+"'"); "/error/msg/=='No setter corrresponding to \\'value\\' in "+fieldValueFeatureClassName+"'");
final String linearModelClassName = LinearModel.class.getCanonicalName(); final String linearModelClassName = LinearModel.class.getName();
// Add models // Add models
String model = "{ \"name\":\"testmodel1\", \"class\":\""+linearModelClassName+"\", \"features\":[] }"; String model = "{ \"name\":\"testmodel1\", \"class\":\""+linearModelClassName+"\", \"features\":[] }";

View File

@ -22,14 +22,17 @@ import java.io.FileOutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.solr.ltr.TestRerankBase; 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.FieldValueFeature;
import org.apache.solr.ltr.feature.ValueFeature; import org.apache.solr.ltr.feature.ValueFeature;
import org.apache.solr.ltr.model.DefaultWrapperModel; import org.apache.solr.ltr.model.DefaultWrapperModel;
import org.apache.solr.ltr.model.LinearModel; import org.apache.solr.ltr.model.LinearModel;
import org.apache.solr.ltr.norm.Normalizer;
import org.apache.solr.ltr.store.FeatureStore; import org.apache.solr.ltr.store.FeatureStore;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -46,18 +49,18 @@ public class TestModelManagerPersistence extends TestRerankBase {
@Test @Test
public void testFeaturePersistence() throws Exception { public void testFeaturePersistence() throws Exception {
loadFeature("feature", ValueFeature.class.getCanonicalName(), "test", loadFeature("feature", ValueFeature.class.getName(), "test",
"{\"value\":2}"); "{\"value\":2}");
assertJQ(ManagedFeatureStore.REST_END_POINT + "/test", assertJQ(ManagedFeatureStore.REST_END_POINT + "/test",
"/features/[0]/name=='feature'"); "/features/[0]/name=='feature'");
restTestHarness.reload(); restTestHarness.reload();
assertJQ(ManagedFeatureStore.REST_END_POINT + "/test", assertJQ(ManagedFeatureStore.REST_END_POINT + "/test",
"/features/[0]/name=='feature'"); "/features/[0]/name=='feature'");
loadFeature("feature1", ValueFeature.class.getCanonicalName(), "test1", loadFeature("feature1", ValueFeature.class.getName(), "test1",
"{\"value\":2}"); "{\"value\":2}");
loadFeature("feature2", ValueFeature.class.getCanonicalName(), "test", loadFeature("feature2", ValueFeature.class.getName(), "test",
"{\"value\":2}"); "{\"value\":2}");
loadFeature("feature3", ValueFeature.class.getCanonicalName(), "test2", loadFeature("feature3", ValueFeature.class.getName(), "test2",
"{\"value\":2}"); "{\"value\":2}");
assertJQ(ManagedFeatureStore.REST_END_POINT + "/test", assertJQ(ManagedFeatureStore.REST_END_POINT + "/test",
"/features/[0]/name=='feature'"); "/features/[0]/name=='feature'");
@ -76,9 +79,9 @@ public class TestModelManagerPersistence extends TestRerankBase {
"/features/[0]/name=='feature1'"); "/features/[0]/name=='feature1'");
assertJQ(ManagedFeatureStore.REST_END_POINT + "/test2", assertJQ(ManagedFeatureStore.REST_END_POINT + "/test2",
"/features/[0]/name=='feature3'"); "/features/[0]/name=='feature3'");
loadModel("test-model", LinearModel.class.getCanonicalName(), loadModel("test-model", LinearModel.class.getName(),
new String[] {"feature"}, "test", "{\"weights\":{\"feature\":1.0}}"); 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}}"); new String[] {"feature1"}, "test1", "{\"weights\":{\"feature1\":1.0}}");
final String fstorecontent = FileUtils final String fstorecontent = FileUtils
.readFileToString(fstorefile, "UTF-8"); .readFileToString(fstorefile, "UTF-8");
@ -201,7 +204,7 @@ public class TestModelManagerPersistence extends TestRerankBase {
"!/models/[1]/name=='"+modelName+"'", "!/models/[1]/name=='"+modelName+"'",
// but the wrapper model should be registered // but the wrapper model should be registered
"/models/[0]/name=='"+modelName+"'", "/models/[0]/name=='"+modelName+"'",
"/models/[0]/class=='" + DefaultWrapperModel.class.getCanonicalName() + "'", "/models/[0]/class=='" + DefaultWrapperModel.class.getName() + "'",
"/models/[0]/store=='" + featureStoreName + "'", "/models/[0]/store=='" + featureStoreName + "'",
// the wrapper model shouldn't contain the definitions of the wrapped model // the wrapper model shouldn't contain the definitions of the wrapped model
"/models/[0]/features/==[]", "/models/[0]/features/==[]",
@ -221,11 +224,11 @@ public class TestModelManagerPersistence extends TestRerankBase {
"/features/==[]"); "/features/==[]");
// setup features // setup features
loadFeature("popularity", FieldValueFeature.class.getCanonicalName(), FS_NAME, "{\"field\":\"popularity\"}"); loadFeature("popularity", FieldValueFeature.class.getName(), FS_NAME, "{\"field\":\"popularity\"}");
loadFeature("const", ValueFeature.class.getCanonicalName(), FS_NAME, "{\"value\":5}"); loadFeature("const", ValueFeature.class.getName(), FS_NAME, "{\"value\":5}");
// setup base model // setup base model
String baseModelJson = getModelInJson(modelName, LinearModel.class.getCanonicalName(), String baseModelJson = getModelInJson(modelName, LinearModel.class.getName(),
new String[] {"popularity", "const"}, FS_NAME, new String[] {"popularity", "const"}, FS_NAME,
"{\"weights\":{\"popularity\":-1.0, \"const\":1.0}}"); "{\"weights\":{\"popularity\":-1.0, \"const\":1.0}}");
File baseModelFile = new File(tmpConfDir, "baseModelForPersistence.json"); File baseModelFile = new File(tmpConfDir, "baseModelForPersistence.json");
@ -236,7 +239,7 @@ public class TestModelManagerPersistence extends TestRerankBase {
baseModelFile.deleteOnExit(); baseModelFile.deleteOnExit();
// setup wrapper model // setup wrapper model
String wrapperModelJson = getModelInJson(modelName, DefaultWrapperModel.class.getCanonicalName(), String wrapperModelJson = getModelInJson(modelName, DefaultWrapperModel.class.getName(),
new String[0], FS_NAME, new String[0], FS_NAME,
"{\"resource\":\"" + baseModelFile.getName() + "\"}"); "{\"resource\":\"" + baseModelFile.getName() + "\"}");
assertJPut(ManagedModelStore.REST_END_POINT, wrapperModelJson, "/responseHeader/status==0"); assertJPut(ManagedModelStore.REST_END_POINT, wrapperModelJson, "/responseHeader/status==0");
@ -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 // 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) {
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) {
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/==[]");
}
} }