Index: lucene/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java	(revision 0)
+++ lucene/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java	(revision 0)
@@ -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!
+}

Property changes on: lucene/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java
___________________________________________________________________
Added: svn:eol-style
   + native

Index: lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java
===================================================================
--- lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java	(revision 1166189)
+++ lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java	(working copy)
@@ -194,11 +194,17 @@
           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;
         }
       }
