You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2011/09/08 14:33:52 UTC
svn commit: r1166656 - in /lucene/dev/trunk/lucene: CHANGES.txt
src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java
src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java
Author: rmuir
Date: Thu Sep 8 12:33:51 2011
New Revision: 1166656
URL: http://svn.apache.org/viewvc?rev=1166656&view=rev
Log:
LUCENE-3421: PayloadTermQuery's explain was wrong when includeSpanScore=false
Added:
lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java (with props)
Modified:
lucene/dev/trunk/lucene/CHANGES.txt
lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java
Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1166656&r1=1166655&r2=1166656&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Thu Sep 8 12:33:51 2011
@@ -540,6 +540,9 @@ Bug fixes
* LUCENE-3412: SloppyPhraseScorer was returning non-deterministic results
for queries with many repeats (Doron Cohen)
+* LUCENE-3421: PayloadTermQuery's explain was wrong when includeSpanScore=false.
+ (Edward Drapkin via Robert Muir)
+
======================= Lucene 3.4.0 =======================
Bug fixes
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java?rev=1166656&r1=1166655&r2=1166656&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java Thu Sep 8 12:33:51 2011
@@ -194,11 +194,17 @@ public class PayloadTermQuery extends Sp
payloadExpl.setValue(scorer.getPayloadScore());
// combined
ComplexExplanation result = new ComplexExplanation();
- result.addDetail(expl);
- result.addDetail(payloadExpl);
- result.setValue(expl.getValue() * payloadExpl.getValue());
- result.setDescription("btq, product of:");
- result.setMatch(expl.getValue() == 0 ? Boolean.FALSE : Boolean.TRUE); // LUCENE-1303
+ if (includeSpanScore) {
+ result.addDetail(expl);
+ result.addDetail(payloadExpl);
+ result.setValue(expl.getValue() * payloadExpl.getValue());
+ result.setDescription("btq, product of:");
+ } else {
+ result.addDetail(payloadExpl);
+ result.setValue(payloadExpl.getValue());
+ result.setDescription("btq(includeSpanScore=false), result of:");
+ }
+ result.setMatch(true); // LUCENE-1303
return result;
}
}
Added: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java?rev=1166656&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java (added)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java Thu Sep 8 12:33:51 2011
@@ -0,0 +1,98 @@
+package org.apache.lucene.search.payloads;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.DefaultSimilarity;
+import org.apache.lucene.search.DefaultSimilarityProvider;
+import org.apache.lucene.search.Similarity;
+import org.apache.lucene.search.TestExplanations;
+import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.util.BytesRef;
+
+/**
+ * TestExplanations subclass focusing on payload queries
+ */
+public class TestPayloadExplanations extends TestExplanations {
+ private PayloadFunction functions[] = new PayloadFunction[] {
+ new AveragePayloadFunction(),
+ new MinPayloadFunction(),
+ new MaxPayloadFunction(),
+ };
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ searcher.setSimilarityProvider(new DefaultSimilarityProvider() {
+ @Override
+ public Similarity get(String field) {
+ return new DefaultSimilarity() {
+ @Override
+ public float scorePayload(int doc, int start, int end, BytesRef payload) {
+ return 1 + (payload.hashCode() % 10);
+ }
+ };
+ }
+ });
+ }
+
+ /** macro for payloadtermquery */
+ private SpanQuery pt(String s, PayloadFunction fn, boolean includeSpanScore) {
+ return new PayloadTermQuery(new Term(FIELD,s), fn, includeSpanScore);
+ }
+
+ /* simple PayloadTermQueries */
+
+ public void testPT1() throws Exception {
+ for (PayloadFunction fn : functions) {
+ qtest(pt("w1", fn, false), new int[] {0,1,2,3});
+ qtest(pt("w1", fn, true), new int[] {0,1,2,3});
+ }
+ }
+
+ public void testPT2() throws Exception {
+ for (PayloadFunction fn : functions) {
+ SpanQuery q = pt("w1", fn, false);
+ q.setBoost(1000);
+ qtest(q, new int[] {0,1,2,3});
+ q = pt("w1", fn, true);
+ q.setBoost(1000);
+ qtest(q, new int[] {0,1,2,3});
+ }
+ }
+
+ public void testPT4() throws Exception {
+ for (PayloadFunction fn : functions) {
+ qtest(pt("xx", fn, false), new int[] {2,3});
+ qtest(pt("xx", fn, true), new int[] {2,3});
+ }
+ }
+
+ public void testPT5() throws Exception {
+ for (PayloadFunction fn : functions) {
+ SpanQuery q = pt("xx", fn, false);
+ q.setBoost(1000);
+ qtest(q, new int[] {2,3});
+ q = pt("xx", fn, true);
+ q.setBoost(1000);
+ qtest(q, new int[] {2,3});
+ }
+ }
+
+ // TODO: test the payloadnear query too!
+}