You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2015/06/16 11:06:57 UTC
svn commit: r1685740 - in /lucene/dev/branches/branch_5x: ./ lucene/
lucene/core/ lucene/core/src/java/org/apache/lucene/search/payloads/
lucene/core/src/test/org/apache/lucene/search/payloads/
Author: romseygeek
Date: Tue Jun 16 09:06:56 2015
New Revision: 1685740
URL: http://svn.apache.org/r1685740
Log:
LUCENE-6567: Simplify payload checks in SpanPayloadCheckQuery
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/lucene/ (props changed)
lucene/dev/branches/branch_5x/lucene/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_5x/lucene/core/ (props changed)
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/SpanPayloadCheckQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/payloads/TestPayloadBasics.java
Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1685740&r1=1685739&r2=1685740&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Tue Jun 16 09:06:56 2015
@@ -141,6 +141,9 @@ Build
* LUCENE-6518: Don't report false thread leaks from IBM J9
ClassCache Reaper in test framework. (Dawid Weiss)
+* LUCENE-6567: Simplify payload checking in SpanPayloadCheckQuery (Alan
+ Woodward)
+
======================= Lucene 5.2.1 =======================
Bug Fixes
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/SpanPayloadCheckQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/SpanPayloadCheckQuery.java?rev=1685740&r1=1685739&r2=1685740&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/SpanPayloadCheckQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/SpanPayloadCheckQuery.java Tue Jun 16 09:06:56 2015
@@ -32,7 +32,6 @@ import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.search.spans.FilterSpans;
import org.apache.lucene.search.spans.FilterSpans.AcceptStatus;
-import org.apache.lucene.search.spans.SpanNearQuery;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.SpanScorer;
import org.apache.lucene.search.spans.SpanWeight;
@@ -40,7 +39,6 @@ import org.apache.lucene.search.spans.Sp
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.ToStringUtils;
-
/**
* Only return those matches that have a specific payload at the given position.
*/
@@ -98,17 +96,9 @@ public class SpanPayloadCheckQuery exten
return (matchSpans == null) ? null : new FilterSpans(matchSpans) {
@Override
protected AcceptStatus accept(Spans candidate) throws IOException {
-
collector.reset();
candidate.collect(collector);
- Collection<byte[]> collected = collector.getPayloads();
-
- if (match instanceof SpanNearQuery) {
- return checkCompositePayloads(collected);
- }
- else {
- return checkOrderedPayloads(collected);
- }
+ return checkPayloads(collector.getPayloads());
}
};
}
@@ -132,19 +122,14 @@ public class SpanPayloadCheckQuery exten
/**
* Check to see if the collected payloads match the required set.
*
- * This is called for Near span queries which collect their sub spans
- * out-of-order, meaning that we can't rely on the order of payloads
- * in the collection
- *
* @param candidate a collection of payloads from the current Spans
* @return whether or not the payloads match
*/
- protected AcceptStatus checkOrderedPayloads(Collection<byte[]> candidate) {
+ protected AcceptStatus checkPayloads(Collection<byte[]> candidate) {
if (candidate.size() == payloadToMatch.size()){
//TODO: check the byte arrays are the same
Iterator<byte[]> toMatchIter = payloadToMatch.iterator();
//check each of the byte arrays, in order
- //hmm, can't rely on order here
for (byte[] candBytes : candidate) {
//if one is a mismatch, then return false
if (Arrays.equals(candBytes, toMatchIter.next()) == false){
@@ -158,36 +143,6 @@ public class SpanPayloadCheckQuery exten
}
}
- /**
- * Check to see if the collected payloads match the required set.
- * @param candidate a collection of payloads from the current Spans
- * @return whether or not the payloads match
- */
- protected AcceptStatus checkCompositePayloads(Collection<byte[]> candidate) {
- if (candidate.size() == payloadToMatch.size()) {
- //TODO: check the byte arrays are the same
- //hmm, can't rely on order here
- int matches = 0;
- for (byte[] candBytes : candidate) {
- //Unfortunately, we can't rely on order, so we need to compare all
- for (byte[] payBytes : payloadToMatch) {
- if (Arrays.equals(candBytes, payBytes) == true) {
- matches++;
- break;
- }
- }
- }
- if (matches == payloadToMatch.size()){
- //we've verified all the bytes
- return AcceptStatus.YES;
- } else {
- return AcceptStatus.NO;
- }
- } else {
- return AcceptStatus.NO;
- }
- }
-
@Override
public String toString(String field) {
StringBuilder buffer = new StringBuilder();
@@ -225,4 +180,4 @@ public class SpanPayloadCheckQuery exten
h = (h * 63) ^ payloadToMatch.hashCode();
return h;
}
-}
\ No newline at end of file
+}
Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/payloads/TestPayloadBasics.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/payloads/TestPayloadBasics.java?rev=1685740&r1=1685739&r2=1685740&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/payloads/TestPayloadBasics.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/payloads/TestPayloadBasics.java Tue Jun 16 09:06:56 2015
@@ -134,6 +134,23 @@ public class TestPayloadBasics extends L
{505});
}
+ public void testUnorderedPayloadChecks() throws Exception {
+
+ SpanTermQuery term5 = new SpanTermQuery(new Term("field", "five"));
+ SpanTermQuery term100 = new SpanTermQuery(new Term("field", "hundred"));
+ SpanTermQuery term4 = new SpanTermQuery(new Term("field", "four"));
+ SpanNearQuery nearQuery = new SpanNearQuery(new SpanQuery[]{term5, term100, term4}, 0, false);
+
+ List<byte[]> payloads = new ArrayList<>();
+ payloads.add(("pos: " + 2).getBytes(StandardCharsets.UTF_8));
+ payloads.add(("pos: " + 1).getBytes(StandardCharsets.UTF_8));
+ payloads.add(("pos: " + 0).getBytes(StandardCharsets.UTF_8));
+
+ SpanPayloadCheckQuery payloadQuery = new SpanPayloadCheckQuery(nearQuery, payloads);
+ checkHits(payloadQuery, new int[]{ 405 });
+
+ }
+
public void testComplexSpanChecks() throws Exception {
SpanTermQuery one = new SpanTermQuery(new Term("field", "one"));
SpanTermQuery thous = new SpanTermQuery(new Term("field", "thousand"));