You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2017/05/23 00:03:26 UTC
[04/27] lucene-solr:jira/solr-10233: LUCENE-7833: Fix score
computation with ToParentBlockJoinQuery and ScoreMode.MAX.
LUCENE-7833: Fix score computation with ToParentBlockJoinQuery and ScoreMode.MAX.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/3bb4662e
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/3bb4662e
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/3bb4662e
Branch: refs/heads/jira/solr-10233
Commit: 3bb4662e63484eb032e6c1e1a175999869ddff88
Parents: eb475db
Author: Adrien Grand <jp...@gmail.com>
Authored: Fri May 19 08:28:37 2017 +0200
Committer: Adrien Grand <jp...@gmail.com>
Committed: Fri May 19 08:28:37 2017 +0200
----------------------------------------------------------------------
lucene/CHANGES.txt | 3 +
.../search/join/ToParentBlockJoinQuery.java | 2 +-
.../lucene/search/join/TestBlockJoin.java | 62 +++++++++++++++++++-
3 files changed, 64 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3bb4662e/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index f309334..43b13b1 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -147,6 +147,9 @@ Bug Fixes
* LUCENE-7831: CodecUtil should not seek to negative offsets. (Adrien Grand)
+* LUCENE-7833: ToParentBlockJoinQuery computed the min score instead of the max
+ score with ScoreMode.MAX. (Adrien Grand)
+
Improvements
* LUCENE-7782: OfflineSorter now passes the total number of items it
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3bb4662e/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
index 0f1f727..1b6f386 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
@@ -312,7 +312,7 @@ public class ToParentBlockJoinQuery extends Query {
score = Math.min(score, childScore);
break;
case Max:
- score = Math.min(score, childScore);
+ score = Math.max(score, childScore);
break;
case None:
break;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3bb4662e/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
index da3c20e..c87fdbb 100644
--- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
@@ -52,6 +52,9 @@ import org.apache.lucene.index.ReaderUtil;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.*;
import org.apache.lucene.search.BooleanClause.Occur;
+import org.apache.lucene.search.similarities.BasicStats;
+import org.apache.lucene.search.similarities.Similarity;
+import org.apache.lucene.search.similarities.SimilarityBase;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BitSet;
import org.apache.lucene.util.Bits;
@@ -230,11 +233,11 @@ public class TestBlockJoin extends LuceneTestCase {
matchingChildren = s.search(childrenQuery, 1);
assertEquals(1, matchingChildren.totalHits);
assertEquals("java", s.doc(matchingChildren.scoreDocs[0].doc).get("skill"));
-
+
r.close();
dir.close();
}
-
+
public void testSimple() throws Exception {
final Directory dir = newDirectory();
@@ -1472,5 +1475,60 @@ public class TestBlockJoin extends LuceneTestCase {
dir.close();
}
+ public void testScoreMode() throws IOException {
+ Similarity sim = new SimilarityBase() {
+
+ @Override
+ public String toString() {
+ return "TestSim";
+ }
+
+ @Override
+ protected float score(BasicStats stats, float freq, float docLen) {
+ return freq;
+ }
+ };
+ Directory dir = newDirectory();
+ RandomIndexWriter w = new RandomIndexWriter(random(), dir, newIndexWriterConfig().setSimilarity(sim));
+ w.addDocuments(Arrays.asList(
+ Collections.singleton(newTextField("foo", "bar bar", Store.NO)),
+ Collections.singleton(newTextField("foo", "bar", Store.NO)),
+ Collections.emptyList(),
+ Collections.singleton(newStringField("type", new BytesRef("parent"), Store.NO))));
+ DirectoryReader reader = w.getReader();
+ w.close();
+ IndexSearcher searcher = newSearcher(reader);
+ searcher.setSimilarity(sim);
+ BitSetProducer parents = new QueryBitSetProducer(new TermQuery(new Term("type", "parent")));
+ for (ScoreMode scoreMode : ScoreMode.values()) {
+ Query query = new ToParentBlockJoinQuery(new TermQuery(new Term("foo", "bar")), parents, scoreMode);
+ TopDocs topDocs = searcher.search(query, 10);
+ assertEquals(1, topDocs.totalHits);
+ assertEquals(3, topDocs.scoreDocs[0].doc);
+ float expectedScore;
+ switch (scoreMode) {
+ case Avg:
+ expectedScore = 1.5f;
+ break;
+ case Max:
+ expectedScore = 2f;
+ break;
+ case Min:
+ expectedScore = 1f;
+ break;
+ case None:
+ expectedScore = 0f;
+ break;
+ case Total:
+ expectedScore = 3f;
+ break;
+ default:
+ throw new AssertionError();
+ }
+ assertEquals(expectedScore, topDocs.scoreDocs[0].score, 0f);
+ }
+ reader.close();
+ dir.close();
+ }
}