Made matchinfo a bit more robust
diff --git a/CHANGES b/CHANGES
index e9f4a58..60987bf 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,6 @@
0.31.4 2014-06-16
- [feature] MatchModifyClassQuery now can extend (diewald)
+ - [bugfix] Make matchinfo a bit more robust (diewald)
0.31.3 2014-06-11
- [bugfix] Minor bugfix regarding treatment of
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndex.java b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
index 8265541..5a04288 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
@@ -557,6 +557,11 @@
if (this.getVersion() != null)
match.setVersion(this.getVersion());
+
+ if (match.getStartPos() == -1)
+ return match;
+
+
// Create a filter based on the corpusID and the docID
BooleanQuery bool = new BooleanQuery();
bool.add(new TermQuery(new Term("ID", match.getDocID())), BooleanClause.Occur.MUST);
diff --git a/src/main/java/de/ids_mannheim/korap/KorapMatch.java b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
index bd19155..0e81695 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapMatch.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
@@ -62,7 +62,7 @@
// Should be deprecated, but used wildly in tests!
@JsonIgnore
- public int startPos, endPos;
+ public int startPos, endPos = -1;
@JsonIgnore
public int potentialStartPosChar = -1,
@@ -138,18 +138,20 @@
*/
public KorapMatch (String idString, boolean includeHighlights) {
MatchIdentifier id = new MatchIdentifier(idString);
- this.setCorpusID(id.getCorpusID());
- this.setDocID(id.getDocID());
- this.setStartPos(id.getStartPos());
- this.setEndPos(id.getEndPos());
+ if (id.getStartPos() > -1) {
+ this.setCorpusID(id.getCorpusID());
+ this.setDocID(id.getDocID());
+ this.setStartPos(id.getStartPos());
+ this.setEndPos(id.getEndPos());
- if (includeHighlights)
- for (int[] pos : id.getPos()) {
- if (pos[0] < id.getStartPos() || pos[1] > id.getEndPos())
- continue;
-
- this.addHighlight(pos[0], pos[1], pos[2]);
- };
+ if (includeHighlights)
+ for (int[] pos : id.getPos()) {
+ if (pos[0] < id.getStartPos() || pos[1] > id.getEndPos())
+ continue;
+
+ this.addHighlight(pos[0], pos[1], pos[2]);
+ };
+ };
};
diff --git a/src/main/java/de/ids_mannheim/korap/index/MatchIdentifier.java b/src/main/java/de/ids_mannheim/korap/index/MatchIdentifier.java
index f89fd07..fcf0dc4 100644
--- a/src/main/java/de/ids_mannheim/korap/index/MatchIdentifier.java
+++ b/src/main/java/de/ids_mannheim/korap/index/MatchIdentifier.java
@@ -5,7 +5,7 @@
public class MatchIdentifier extends DocIdentifier {
- private int startPos, endPos = 0;
+ private int startPos, endPos = -1;
private ArrayList<int[]> pos = new ArrayList<>(8);