fix rewrite(), replace LocalDocId
diff --git a/src/main/java/de/ids_mannheim/korap/query/SimpleSpanQuery.java b/src/main/java/de/ids_mannheim/korap/query/SimpleSpanQuery.java
index f0d8589..d0ffdba 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SimpleSpanQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SimpleSpanQuery.java
@@ -9,7 +9,7 @@
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.util.ToStringUtils;
-/** An abstract class for Spanquery having two clauses.
+/** An abstract class for a Spanquery having two clauses.
*
* @author margaretha
* */
@@ -73,13 +73,15 @@
@Override
public Query rewrite(IndexReader reader) throws IOException {
- SimpleSpanQuery clone = clone();
+ SimpleSpanQuery clone = null;
SpanQuery query = (SpanQuery) firstClause.rewrite(reader);
if (!query.equals(firstClause)) {
+ if (clone == null) clone = clone();
clone.firstClause = query;
}
query = (SpanQuery) secondClause.rewrite(reader);
- if (!query.equals(secondClause)) {
+ if (!query.equals(secondClause)) {
+ if (clone == null) clone = clone();
clone.secondClause = query;
}
return (clone != null ? clone : this );
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanSegmentQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanSegmentQuery.java
index 3e52cbf..27e9a6e 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanSegmentQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanSegmentQuery.java
@@ -4,14 +4,19 @@
import java.util.Map;
import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
+import org.apache.lucene.search.Query;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.Spans;
import org.apache.lucene.util.Bits;
import de.ids_mannheim.korap.query.spans.SegmentSpans;
+/** Matching two spans having exactly the same start and end positions.
+ * @author margaretha
+ * */
public class SpanSegmentQuery extends SimpleSpanQuery{
private boolean collectPayloads;
@@ -34,10 +39,10 @@
Map<Term, TermContext> termContexts) throws IOException {
return (Spans) new SegmentSpans(this, context, acceptDocs,
termContexts, collectPayloads);
- }
-
+ }
+
@Override
- public SimpleSpanQuery clone() {
+ public SpanSegmentQuery clone() {
SpanSegmentQuery spanSegmentQuery = new SpanSegmentQuery(
(SpanQuery) firstClause.clone(),
(SpanQuery) secondClause.clone(),
@@ -47,31 +52,29 @@
return spanSegmentQuery;
}
- /* TODO: Where is the hashmap?
+ //TODO: Where is the hashmap?
@Override
public boolean equals(Object o) {
if (this == o) return true;
- if (!(o instanceof SpanNextQuery)) return false;
+ if (!(o instanceof SpanSegmentQuery)) return false;
- final SpanNextQuery spanNextQuery = (SpanNextQuery) o;
+ SpanSegmentQuery spanSegmentQuery = (SpanSegmentQuery) o;
- if (collectPayloads != spanNextQuery.collectPayloads) return false;
- if (!firstClause.equals(spanNextQuery.firstClause)) return false;
- if (!secondClause.equals(spanNextQuery.secondClause)) return false;
+ if (collectPayloads != spanSegmentQuery.collectPayloads) return false;
+ if (!firstClause.equals(spanSegmentQuery.firstClause)) return false;
+ if (!secondClause.equals(spanSegmentQuery.secondClause)) return false;
- return getBoost() == spanNextQuery.getBoost();
+ return getBoost() == spanSegmentQuery.getBoost();
};
-
- // I don't know what I am doing here
@Override
public int hashCode() {
int result;
result = firstClause.hashCode() + secondClause.hashCode();
- result ^= (result << 31) | (result >>> 2); // reversible
+ result ^= (31 << result) | (result >>> 2);
result += Float.floatToRawIntBits(getBoost());
return result;
};
- */
+
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/SegmentSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/SegmentSpans.java
index a401b0f..a4e9919 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/SegmentSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/SegmentSpans.java
@@ -10,8 +10,8 @@
import de.ids_mannheim.korap.query.SimpleSpanQuery;
-/** SegmentSpans is an enumeration of Span matches, which ensures that two spans:
- * a firstspan and a secondspan have exactly the same start and end positions.
+/** SegmentSpans is an enumeration of Span matches, which ensures that two spans
+ * have exactly the same start and end positions.
*
* @author margaretha
* */
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/SimpleSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/SimpleSpans.java
index 4169729..0db257d 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/SimpleSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/SimpleSpans.java
@@ -46,10 +46,10 @@
matchDocNumber= -1;
matchStartPosition= -1;
matchEndPosition= -1;
-
- this.collectPayloads = collectPayloads;
- if (collectPayloads)
- matchPayload = new LinkedList<byte[]>();
+
+ // TODO: what is this
+ this.collectPayloads = true;
+ matchPayload = new LinkedList<byte[]>();
// Get the enumeration of the two spans to match
firstSpans = simpleSpanQuery.getFirstClause().
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestSegmentIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestSegmentIndex.java
index 9ff2670..41df6d1 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestSegmentIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestSegmentIndex.java
@@ -68,11 +68,11 @@
assertEquals("totalResults", 3, kr.totalResults());
// Match #0
- assertEquals("doc-number", 1, kr.match(0).localDocID);
+ assertEquals("doc-number", 1, kr.match(0).getLocalDocID());
assertEquals("StartPos", 1, kr.match(0).startPos);
assertEquals("EndPos", 2, kr.match(0).endPos);
// Match #2
- assertEquals("doc-number", 2, kr.match(2).localDocID);
+ assertEquals("doc-number", 2, kr.match(2).getLocalDocID());
assertEquals("StartPos", 2, kr.match(2).startPos);
assertEquals("EndPos", 3, kr.match(2).endPos);
}
@@ -91,7 +91,7 @@
ki.close();
assertEquals("totalResults", 1, kr.totalResults());
- assertEquals("doc-number", 2, kr.match(0).localDocID);
+ assertEquals("doc-number", 2, kr.match(0).getLocalDocID());
assertEquals("StartPos (0)", 1, kr.match(0).startPos);
assertEquals("EndPos (0)", 2, kr.match(0).endPos);
}
@@ -113,11 +113,11 @@
assertEquals("totalResults", 2, kr.totalResults());
// Match #0
- assertEquals("doc-number", 0, kr.match(0).localDocID);
+ assertEquals("doc-number", 0, kr.match(0).getLocalDocID());
assertEquals("StartPos", 3, kr.match(0).startPos);
assertEquals("EndPos", 5, kr.match(0).endPos);
// Match #1
- assertEquals("doc-number", 1, kr.match(1).localDocID);
+ assertEquals("doc-number", 1, kr.match(1).getLocalDocID());
assertEquals("StartPos", 1, kr.match(1).startPos);
assertEquals("EndPos", 3, kr.match(1).endPos);
}
@@ -136,7 +136,7 @@
assertEquals("totalResults", 1, kr.totalResults());
// Match #0
- assertEquals("doc-number", 0, kr.match(0).localDocID);
+ assertEquals("doc-number", 0, kr.match(0).getLocalDocID());
assertEquals("StartPos", 3, kr.match(0).startPos);
assertEquals("EndPos", 5, kr.match(0).endPos);
}