From 0c1fde664fb1c9456b3fdc2abd08e80dc8f86eb8 Mon Sep 17 00:00:00 2001 From: Joel Bernstein Date: Mon, 27 Feb 2017 12:03:03 -0500 Subject: [PATCH] SOLR-10208: Adjust scoring formula for the scoreNodes function --- .../solr/client/solrj/io/stream/ScoreNodesStream.java | 2 +- .../solrj/io/stream/SignificantTermsStream.java | 2 +- .../client/solrj/io/graph/GraphExpressionTest.java | 11 +++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/ScoreNodesStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/ScoreNodesStream.java index 41e719779c0..f394424e7e1 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/ScoreNodesStream.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/ScoreNodesStream.java @@ -237,7 +237,7 @@ public class ScoreNodesStream extends TupleStream implements Expressible throw new Exception("termFreq field not present in the Tuple"); } Number termFreqValue = (Number)tuple.get(termFreq); - float score = termFreqValue.floatValue() * (float) (Math.log((numDocs + 1) / (docFreq.doubleValue() + 1)) + 1.0); + float score = (float)(Math.log(termFreqValue.floatValue())+1.0) * (float) (Math.log((numDocs + 1) / (docFreq.doubleValue() + 1)) + 1.0); tuple.put("nodeScore", score); tuple.put("docFreq", docFreq); tuple.put("numDocs", numDocs); diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/SignificantTermsStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/SignificantTermsStream.java index f5f8a067c2b..87b5a9f9837 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/SignificantTermsStream.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/SignificantTermsStream.java @@ -358,7 +358,7 @@ public class SignificantTermsStream extends TupleStream implements Expressible{ map.put("background", freqs[0]); map.put("foreground", freqs[1]); - float score = (float)Math.log(freqs[1]) * (float) (Math.log(((float)(numDocs + 1)) / (freqs[0] + 1)) + 1.0); + float score = (float)(Math.log(freqs[1])+1.0) * (float) (Math.log(((float)(numDocs + 1)) / (freqs[0] + 1)) + 1.0); map.put("score", score); maps.add(map); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java index cf0705818eb..33781efedf0 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java @@ -521,10 +521,10 @@ public class GraphExpressionTest extends SolrCloudTestCase { .add(id, "3", "basket_s", "basket2", "product_ss", "product1", "product_ss", "product6", "product_ss", "product7", "price_f", "1") .add(id, "6", "basket_s", "basket3", "product_ss", "product4", "product_ss","product3", "product_ss","product1", "price_f", "1") .add(id, "9", "basket_s", "basket4", "product_ss", "product4", "product_ss", "product3", "product_ss", "product1","price_f", "1") - .add(id, "12", "basket_s", "basket5", "product_ss", "product1", "price_f", "1") - .add(id, "13", "basket_s", "basket6", "product_ss", "product1", "price_f", "1") - .add(id, "14", "basket_s", "basket7", "product_ss", "product1", "price_f", "1") - .add(id, "15", "basket_s", "basket4", "product_ss", "product1", "price_f", "1") + //.add(id, "12", "basket_s", "basket5", "product_ss", "product1", "price_f", "1") + //.add(id, "13", "basket_s", "basket6", "product_ss", "product1", "price_f", "1") + //.add(id, "14", "basket_s", "basket7", "product_ss", "product1", "price_f", "1") + //.add(id, "15", "basket_s", "basket4", "product_ss", "product1", "price_f", "1") .commit(cluster.getSolrClient(), COLLECTION); List tuples = null; @@ -557,7 +557,6 @@ public class GraphExpressionTest extends SolrCloudTestCase { stream.setStreamContext(context); tuples = getTuples(stream); - //The highest scoring tuple will be the product searched for. Tuple tuple = tuples.get(0); assert(tuple.getString("node").equals("product3")); assert(tuple.getLong("docFreq") == 3); @@ -570,7 +569,7 @@ public class GraphExpressionTest extends SolrCloudTestCase { Tuple tuple1 = tuples.get(2); assert(tuple1.getString("node").equals("product1")); - assert(tuple1.getLong("docFreq") == 8); + assert(tuple1.getLong("docFreq") == 4); assert(tuple1.getLong("count(*)") == 3); Tuple tuple2 = tuples.get(3);