From e07c4328a419b392cdc60daa9396419c470acf3b Mon Sep 17 00:00:00 2001 From: tomglk <> Date: Wed, 19 May 2021 20:57:20 +0200 Subject: [PATCH] [SOLR-12697] add tests for parsing different sortedDocValues, add entry to CHANGES.txt --- solr/CHANGES.txt | 2 ++ .../ltr/feature/TestFieldValueFeature.java | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 0054194c483..9384f314b78 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -322,6 +322,8 @@ New Features * SOLR-15397: Expose zookeeper status in the Prometheus exporter (janhoy) +* SOLR-12697: Add pure DocValues support to FieldValueFeature (Tom Gilke, Christine Poerschke) + Improvements --------------------- * SOLR-15081: Metrics for a core: add SolrCloud "isLeader" and "replicaState". (David Smiley) 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 82c8bf5bacb..c485dc9fe46 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 @@ -347,6 +347,40 @@ public void testParamsToMap() throws Exception { doTestParamsToMap(FieldValueFeature.class.getName(), params); } + @Test + public void testThatStringValuesAreCorrectlyParsed() throws Exception { + final String[][] inputsAndTests = { + new String[]{"T", "/response/docs/[0]/=={'[fv]':'" + + FeatureLoggerTestUtils.toFeatureVector("dvStrNumField", "1.0")+"'}"}, + new String[]{"F", "/response/docs/[0]/=={'[fv]':'" + + FeatureLoggerTestUtils.toFeatureVector("dvStrNumField", "0.0")+"'}"}, + new String[]{"-7324.427", "/response/docs/[0]/=={'[fv]':'" + + FeatureLoggerTestUtils.toFeatureVector("dvStrNumField", "-7324.427")+"'}"}, + new String[]{"532", "/response/docs/[0]/=={'[fv]':'" + + FeatureLoggerTestUtils.toFeatureVector("dvStrNumField", "532.0")+"'}"}, + new String[]{"notanumber", "/error/msg/=='org.apache.solr.ltr.feature.FeatureException: " + + "Cannot parse value notanumber of field dvStrNumField to float.'"} + }; + + final String fstore = "testThatStringValuesAreCorrectlyParsed"; + loadFeature("dvStrNumField", FieldValueFeature.class.getName(), fstore, + "{\"field\":\"" + "dvStrNumField" + "\"}"); + loadModel("dvStrNumField-model", LinearModel.class.getName(), + new String[]{"dvStrNumField"}, fstore, "{\"weights\":{\"" + "dvStrNumField" + "\":1.0}}"); + + for (String[] inputAndTest : inputsAndTests) { + assertU(adoc("id", "21", "dvStrNumField", inputAndTest[0])); + assertU(commit()); + + SolrQuery query = new SolrQuery(); + query.setQuery("id:21"); + query.add("rq", "{!ltr model=" + "dvStrNumField" + "-model reRankDocs=4}"); + query.add("fl", "[fv]"); + + assertJQ("/query" + query.toQueryString(), inputAndTest[1]); + } + } + /** * This class is used to track which specific FieldValueFeature is used so that we can test, whether the * fallback mechanism works correctly.