diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java index 861ff8a670e..4bee7359657 100644 --- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java +++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java @@ -526,34 +526,45 @@ public void testThatCorrectFieldValueFeatureIsUsedForDocValueTypes() throws Exce final String field = fieldAndScorerClass[0]; final String fieldValue = fieldAndScorerClass[1]; final String fstore = "testThatCorrectFieldValueFeatureIsUsedForDocValueTypes" + field; + final String modelName = field + "-model"; assertU(adoc("id", "21", field, fieldValue)); assertU(commit()); - loadFeature( - field, getObservingFieldValueFeatureClassName(), fstore, "{\"field\":\"" + field + "\"}"); - loadModel( - field + "-model", - LinearModel.class.getName(), - new String[] {field}, - fstore, - "{\"weights\":{\"" + field + "\":1.0}}"); + loadFeatureAndModel(getObservingFieldValueFeatureClassName(), field, fstore, modelName); - final SolrQuery query = new SolrQuery("id:21"); - query.add("rq", "{!ltr model=" + field + "-model reRankDocs=4}"); - query.add("fl", "[fv]"); + query(field, modelName); - ObservingFieldValueFeature.usedScorerClass = null; // to clear away any previous test's use - assertJQ("/query" + query.toQueryString(), "/response/numFound/==1"); - assertJQ( - "/query" + query.toQueryString(), - "/response/docs/[0]/=={'[fv]':'" - + FeatureLoggerTestUtils.toFeatureVector(field, "1.0") - + "'}"); assertEquals(fieldAndScorerClass[2], ObservingFieldValueFeature.usedScorerClass); } } + void loadFeatureAndModel(String featureClassName, String field, String fstore, String modelName) throws Exception { + loadFeature( + field, featureClassName, fstore, "{\"field\":\"" + field + "\"}"); + + loadModel( + modelName, + LinearModel.class.getName(), + new String[]{field}, + fstore, + "{\"weights\":{\"" + field + "\":1.0}}"); + } + + void query(String field, String modelName) throws Exception { + final SolrQuery query = new SolrQuery("id:21"); + query.add("rq", "{!ltr model=" + modelName + " reRankDocs=4}"); + query.add("fl", "[fv]"); + + ObservingFieldValueFeature.usedScorerClass = null; // to clear away any previous test's use + assertJQ("/query" + query.toQueryString(), "/response/numFound/==1"); + assertJQ( + "/query" + query.toQueryString(), + "/response/docs/[0]/=={'[fv]':'" + + FeatureLoggerTestUtils.toFeatureVector(field, "1.0") + + "'}"); + } + @Test public void testParamsToMap() throws Exception { final LinkedHashMap params = new LinkedHashMap<>(); diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestLegacyFieldValueFeature.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestLegacyFieldValueFeature.java index ba3839146f4..f40ed89d230 100644 --- a/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestLegacyFieldValueFeature.java +++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/feature/TestLegacyFieldValueFeature.java @@ -47,11 +47,39 @@ protected String storedDvIsTrendy_FieldValueFeatureScorer_className() { } @Test - public void test_storedDvIsTrendy_FieldValueFeatureScorer_className_differs() throws Exception { - final String className = super.storedDvIsTrendy_FieldValueFeatureScorer_className(); - final String legacyClassName = storedDvIsTrendy_FieldValueFeatureScorer_className(); + public void test_LegacyFieldValueFeature_behavesDifferentlyThan_FieldValueFeature() throws Exception { + // the field storedDvIsTrendy has stored=true and docValues=true + final String field = "storedDvIsTrendy"; + final String fieldValue = "1"; + String fstore = "test_LegacyFieldValueFeature_behavesDifferentlyThan_FieldValueFeature" + field; + + assertU(adoc("id", "21", field, fieldValue)); + assertU(commit()); // demonstrate that & how the FieldValueFeature & LegacyFieldValueFeature implementations differ - assertNotEquals(className, legacyClassName); - assertEquals(className.replace("SortedDocValues", ""), legacyClassName); + + // the LegacyFieldValueFeature does not use docValues + loadAndQuery(getObservingFieldValueFeatureClassName(), field, fstore); + + String legacyScorerClass = ObservingFieldValueFeature.usedScorerClass; + assertEquals( + FieldValueFeature.FieldValueFeatureWeight.FieldValueFeatureScorer.class.getName(), + legacyScorerClass); + + // the FieldValueFeature does use docValues + loadAndQuery(super.getObservingFieldValueFeatureClassName(), field, fstore); + + String scorerClass = ObservingFieldValueFeature.usedScorerClass; + assertEquals( + FieldValueFeature.FieldValueFeatureWeight.SortedDocValuesFieldValueFeatureScorer.class.getName(), + scorerClass); + } + + void loadAndQuery(String featureClassName, String field, String fstore) throws Exception { + final String modelName = field + "-model-" + featureClassName; + final String featureStoreName = fstore + featureClassName; + + loadFeatureAndModel(featureClassName, field, featureStoreName, modelName); + + query(field, modelName); } }