Dependency Updates, JSON output bugfix, nested highlight bugfix
diff --git a/CHANGES b/CHANGES
index b013ba1..febbab7 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,7 +1,12 @@
-0.43 2014-09-25
+0.44 2014-09-27
- [feature] Match collector using database for distributed search (diewald)
- [bugfix] Unified boundary handling and prevent nullpointer
exceptions on parsing (diewald)
+ - [bugfix] Ordering of payloads reversed to make nesting highlights
+ nest correctly (diewald)
+ - [performance] Updated Lucene dependency from 4.3.1 to 4.5.1 (diewald)
+ - [performance] Updated Jackson dependency from 2.2.2 to 2.4.0 (diewald)
+ - [bugfix] Return matches correctly with JSON (diewald)
0.43 2014-09-23
- [cleanup] Made a lot of stuff rely on KorapResponse (diewald)
diff --git a/pom.xml b/pom.xml
index 879d385..5398b8f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -101,30 +101,13 @@
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
-
- <!-- solr dependency -->
- <!--
- <dependency>
- <artifactId>solr-core</artifactId>
- <groupId>org.apache.solr</groupId>
- <version>4.3.1</version>
- <type>jar</type>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <artifactId>solr-test-framework</artifactId>
- <groupId>org.apache.solr</groupId>
- <version>4.3.1</version>
- </dependency>
- -->
<!-- Lucene core dependency -->
<dependency>
<artifactId>lucene-core</artifactId>
<groupId>org.apache.lucene</groupId>
<type>jar</type>
- <version>4.3.1</version>
+ <version>4.5.1</version>
</dependency>
<!-- Lucene queryparser dependency -->
@@ -132,7 +115,7 @@
<artifactId>lucene-queryparser</artifactId>
<groupId>org.apache.lucene</groupId>
<type>jar</type>
- <version>4.3.1</version>
+ <version>4.5.1</version>
</dependency>
<!-- Lucene analyzers dependency -->
@@ -156,15 +139,6 @@
<version>1.0</version>
</dependency>
- <!-- servlet dependency -->
- <!--
- <dependency>
- <artifactId>servlet-api</artifactId>
- <groupId>javax.servlet</groupId>
- <version>2.5</version>
- </dependency>
- -->
-
<!-- Jersey -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
@@ -177,17 +151,6 @@
<version>1.13-b01</version>
</dependency>
- <!-- Multipart support for Jersey -->
- <!--
- See
- http://www.mkyong.com/webservices/jax-rs/file-upload-example-in-jersey/
- <dependency>
- <groupId>com.sun.jersey.contribs</groupId>
- <artifactId>jersey-multipart</artifactId>
- <version>1.13</version>
- </dependency>
- -->
-
<!-- JSON support -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
@@ -200,17 +163,17 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
- <version>2.2.2</version>
+ <version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
- <version>2.2.2</version>
+ <version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
- <version>2.2.2</version>
+ <version>2.4.0</version>
</dependency>
</dependencies>
@@ -232,25 +195,19 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
- <configuration>
- <!--
- <finalName>KorapTools</finalName>
- -->
-
+ <configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>de.ids_mannheim.korap.KorapIndexer</mainClass>
</manifest>
</archive>
-
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
-
<execution>
<id>KorapIndexer</id>
<phase>package</phase>
@@ -268,7 +225,7 @@
</execution>
</executions>
</plugin>
-
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@@ -298,7 +255,6 @@
<mainClass>de.ids_mannheim.korap.KorapNode</mainClass>
</configuration>
</plugin>
-
</plugins>
<resources>
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndex.java b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
index bfd6c94..c98b06d 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
@@ -423,8 +423,8 @@
// Todo: Maybe reuse a termsEnum!
final TermsEnum termsEnum = terms.iterator(null);
- // Set the positioon in the iterator to the term that is seeked
- if (termsEnum.seekExact(term.bytes(), true)) {
+ // Set the position in the iterator to the term that is seeked
+ if (termsEnum.seekExact(term.bytes())) {
// Start an iterator to fetch all payloads of the term
DocsAndPositionsEnum docs = termsEnum.docsAndPositions(
@@ -1213,7 +1213,7 @@
); // new KorapMatch();
if (spans.isPayloadAvailable())
- match.addPayload(spans.getPayload());
+ match.addPayload((List<byte[]>) spans.getPayload());
match.internalDocID = docID;
match.populateDocument(doc, field, fieldsToLoadLocal);
diff --git a/src/main/java/de/ids_mannheim/korap/KorapMatch.java b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
index 16e69d9..d3a42ad 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapMatch.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
@@ -195,9 +195,14 @@
// TODO: Here are offsets and highlight offsets!
// <> payloads have 12 bytes (iii) or 8!?
// highlightoffsets have 11 bytes (iis)!
- public void addPayload (Collection<byte[]> payload) {
+ public void addPayload (List<byte[]> payload) {
+
+ // Reverse to make embedding of highlights correct
+ Collections.reverse(payload);
try {
ByteBuffer bb = ByteBuffer.allocate(10);
+
+ // TODO: REVERSE ITERATOR!
for (byte[] b : payload) {
if (DEBUG)
diff --git a/src/main/java/de/ids_mannheim/korap/KorapResult.java b/src/main/java/de/ids_mannheim/korap/KorapResult.java
index 7300d24..b546c9c 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapResult.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapResult.java
@@ -188,15 +188,17 @@
return this.benchmarkHitCounter;
}
+ @JsonIgnore
public void setItemsPerResource (short value) {
this.itemsPerResource = value;
};
+ @JsonIgnore
public void setItemsPerResource (int value) {
this.itemsPerResource = (short) value;
};
- // @JsonIgnore
+ @JsonIgnore
public short getItemsPerResource () {
return this.itemsPerResource;
};
@@ -210,7 +212,7 @@
return this.matches.get(index);
}
- @JsonIgnore
+ // @JsonIgnore
public List<KorapMatch> getMatches() {
return this.matches;
}
diff --git a/src/main/java/de/ids_mannheim/korap/analysis/MultiTermTokenStream.java b/src/main/java/de/ids_mannheim/korap/analysis/MultiTermTokenStream.java
index dd6ab1c..c869c0a 100644
--- a/src/main/java/de/ids_mannheim/korap/analysis/MultiTermTokenStream.java
+++ b/src/main/java/de/ids_mannheim/korap/analysis/MultiTermTokenStream.java
@@ -38,6 +38,12 @@
private PositionIncrementAttribute posIncrAttr;
private PayloadAttribute payloadAttr;
+
+ /*
+ TODO: Update to new Tokeanstream API
+ http://www.hankcs.com/program/java/lucene-4-6-1-java-lang-illegalstateexception-tokenstream-contract-violation.html
+ */
+
private static final Pattern pattern = Pattern.compile("\\[(?:\\([0-9]+-[0-9]+\\))?([^\\]]+?)\\]");
// This advices the java compiler to ignore all loggings
diff --git a/src/main/java/de/ids_mannheim/korap/index/PositionsToOffset.java b/src/main/java/de/ids_mannheim/korap/index/PositionsToOffset.java
index 57375d0..3bd0d74 100644
--- a/src/main/java/de/ids_mannheim/korap/index/PositionsToOffset.java
+++ b/src/main/java/de/ids_mannheim/korap/index/PositionsToOffset.java
@@ -189,8 +189,9 @@
Term term = new Term(field, sb.toString());
sb.setLength(1);
-
- if (termsEnum.seekExact(term.bytes(), true)) {
+
+ // Set the position in the iterator to the term that is seeked
+ if (termsEnum.seekExact(term.bytes())) {
if (DEBUG)
log.trace("Search for {} in doc {} with pos {}",
diff --git a/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java b/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java
index 7541af6..111d2c0 100644
--- a/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java
+++ b/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java
@@ -6,6 +6,7 @@
import de.ids_mannheim.korap.KorapIndex;
import de.ids_mannheim.korap.KorapQuery;
import de.ids_mannheim.korap.KorapResult;
+import de.ids_mannheim.korap.KorapSearch;
import de.ids_mannheim.korap.KorapMatch;
import de.ids_mannheim.korap.index.FieldDocument;
@@ -128,4 +129,133 @@
assertEquals("<span class=\"context-left\"></span><span class=\"match\"><em class=\"class-7 level-0\"><em class=\"class-5 level-1\">a<em class=\"class-6 level-2\">b</em></em></em><em class=\"class-6 level-2\">c</em></span><span class=\"context-right\"></span>", km.getSnippetHTML());
};
+
+
+ @Test
+ public void highlightMissingBug () throws IOException {
+ KorapIndex ki = new KorapIndex();
+ FieldDocument fd = new FieldDocument();
+ fd.addString("ID", "doc-1");
+ fd.addString("UID", "1");
+ fd.addTV("base",
+ "abab",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>4]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]" +
+ "[(3-4)s:b|i:a|_3#3-4]");
+ ki.addDoc(fd);
+ fd = new FieldDocument();
+ fd.addString("ID", "doc-2");
+ fd.addString("UID", "2");
+ fd.addTV("base",
+ "aba",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>3]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]");
+ ki.addDoc(fd);
+
+ // Commit!
+ ki.commit();
+ fd = new FieldDocument();
+ fd.addString("ID", "doc-3");
+ fd.addString("UID", "3");
+ fd.addTV("base",
+ "abab",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>4]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]" +
+ "[(3-4)s:b|i:a|_3#3-4]");
+ ki.addDoc(fd);
+
+ // Commit!
+ ki.commit();
+ fd = new FieldDocument();
+ fd.addString("ID", "doc-4");
+ fd.addString("UID", "4");
+ fd.addTV("base",
+ "aba",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>3]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]");
+ ki.addDoc(fd);
+
+ // Commit!
+ ki.commit();
+
+ KorapQuery kq = new KorapQuery("base");
+ SpanQuery q = (SpanQuery) kq.or(kq._(1, kq.seg("s:a"))).or(kq._(2, kq.seg("s:b"))).toQuery();
+ KorapResult kr = ki.search(q);
+ assertEquals(14, kr.getTotalResults());
+ assertEquals("[{1:a}]bab", kr.getMatch(0).getSnippetBrackets());
+ assertEquals("a[{2:b}]ab", kr.getMatch(1).getSnippetBrackets());
+ assertEquals("ab[{1:a}]b", kr.getMatch(2).getSnippetBrackets());
+ assertEquals("aba[{2:b}]", kr.getMatch(3).getSnippetBrackets());
+
+ assertEquals("[{1:a}]ba", kr.getMatch(4).getSnippetBrackets());
+ assertEquals("a[{2:b}]a", kr.getMatch(5).getSnippetBrackets());
+ assertEquals("ab[{1:a}]", kr.getMatch(6).getSnippetBrackets());
+
+ assertEquals("[{1:a}]bab", kr.getMatch(7).getSnippetBrackets());
+ assertEquals("a[{2:b}]ab", kr.getMatch(8).getSnippetBrackets());
+ assertEquals("ab[{1:a}]b", kr.getMatch(9).getSnippetBrackets());
+ assertEquals("aba[{2:b}]", kr.getMatch(10).getSnippetBrackets());
+
+ assertEquals("[{1:a}]ba", kr.getMatch(11).getSnippetBrackets());
+ assertEquals("a[{2:b}]a", kr.getMatch(12).getSnippetBrackets());
+ assertEquals("ab[{1:a}]", kr.getMatch(13).getSnippetBrackets());
+
+
+ kq = new KorapQuery("base");
+ q = (SpanQuery) kq.or(kq._(1, kq.seg("i:a"))).or(kq._(2, kq.seg("i:c"))).toQuery();
+ KorapSearch qs = new KorapSearch(q);
+ qs.getContext().left.setToken(true).setLength((short) 1);
+ qs.getContext().right.setToken(true).setLength((short) 1);
+ kr = ki.search(qs);
+ assertEquals(10, kr.getTotalResults());
+
+ assertEquals("[{1:a}]b ...", kr.getMatch(0).getSnippetBrackets());
+ assertEquals("... b[{2:a}]b", kr.getMatch(1).getSnippetBrackets());
+ assertEquals("... a[{1:b}]", kr.getMatch(2).getSnippetBrackets());
+ assertEquals("[{1:a}]b ...", kr.getMatch(3).getSnippetBrackets());
+ assertEquals("... b[{2:a}]", kr.getMatch(4).getSnippetBrackets());
+ assertEquals("[{1:a}]b ...", kr.getMatch(5).getSnippetBrackets());
+ assertEquals("... b[{2:a}]b", kr.getMatch(6).getSnippetBrackets());
+ assertEquals("... a[{1:b}]", kr.getMatch(7).getSnippetBrackets());
+ assertEquals("[{1:a}]b ...", kr.getMatch(8).getSnippetBrackets());
+ assertEquals("... b[{2:a}]", kr.getMatch(9).getSnippetBrackets());
+
+ qs.getContext().left.setToken(true).setLength((short) 0);
+ qs.getContext().right.setToken(true).setLength((short) 0);
+ kr = ki.search(qs);
+ assertEquals(10, kr.getTotalResults());
+
+ assertEquals("[{1:a}] ...", kr.getMatch(0).getSnippetBrackets());
+ assertEquals("... [{2:a}] ...", kr.getMatch(1).getSnippetBrackets());
+ assertEquals("... [{1:b}]", kr.getMatch(2).getSnippetBrackets());
+ assertEquals("[{1:a}] ...", kr.getMatch(3).getSnippetBrackets());
+ assertEquals("... [{2:a}]", kr.getMatch(4).getSnippetBrackets());
+ assertEquals("[{1:a}] ...", kr.getMatch(5).getSnippetBrackets());
+ assertEquals("... [{2:a}] ...", kr.getMatch(6).getSnippetBrackets());
+ assertEquals("... [{1:b}]", kr.getMatch(7).getSnippetBrackets());
+ assertEquals("[{1:a}] ...", kr.getMatch(8).getSnippetBrackets());
+ assertEquals("... [{2:a}]", kr.getMatch(9).getSnippetBrackets());
+
+ q = (SpanQuery) kq._(3, kq.or(kq._(1, kq.seg("i:a"))).or(kq._(2, kq.seg("i:c")))).toQuery();
+ qs = new KorapSearch(q);
+ qs.getContext().left.setToken(true).setLength((short) 0);
+ qs.getContext().right.setToken(true).setLength((short) 0);
+ kr = ki.search(qs);
+ assertEquals(10, kr.getTotalResults());
+
+ assertEquals("[{3:{1:a}}] ...", kr.getMatch(0).getSnippetBrackets());
+ assertEquals("... [{3:{2:a}}] ...", kr.getMatch(1).getSnippetBrackets());
+ assertEquals("... [{3:{1:b}}]", kr.getMatch(2).getSnippetBrackets());
+ assertEquals("[{3:{1:a}}] ...", kr.getMatch(3).getSnippetBrackets());
+ assertEquals("... [{3:{2:a}}]", kr.getMatch(4).getSnippetBrackets());
+ assertEquals("[{3:{1:a}}] ...", kr.getMatch(5).getSnippetBrackets());
+ assertEquals("... [{3:{2:a}}] ...", kr.getMatch(6).getSnippetBrackets());
+ assertEquals("... [{3:{1:b}}]", kr.getMatch(7).getSnippetBrackets());
+ assertEquals("[{3:{1:a}}] ...", kr.getMatch(8).getSnippetBrackets());
+ assertEquals("... [{3:{2:a}}]", kr.getMatch(9).getSnippetBrackets());
+ };
};
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
index c0e6b05..347f4ee 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
@@ -102,7 +102,7 @@
KorapMatch km = kr.match(0);
assertEquals("SnippetBrackets (0)", "... bcabca[{2:b{a}}]c", km.snippetBrackets());
- assertEquals("ID (0)", "match-c1!d1-p7-9(0)8-8(2)7-8", km.getID());
+ assertEquals("ID (0)", "match-c1!d1-p7-9(2)7-8(0)8-8", km.getID());
};
@Test
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestKorapQuery.java b/src/test/java/de/ids_mannheim/korap/query/TestKorapQuery.java
index 0f4afdd..ffe98e5 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKorapQuery.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKorapQuery.java
@@ -145,7 +145,7 @@
public void KorapShrinkQuery3 () {
KorapQuery kq = new KorapQuery("field");
SpanQuery sq = kq.shrink(1, kq._(1, kq.seq(kq.tag("np"), kq._(kq.seg("test").without("no"))))).toQuery();
- assertEquals("shrink(1: {1: spanNext(<field:np />, {0: spanNot(field:test, field:no)})})", sq.toString());
+ assertEquals("shrink(1: {1: spanNext(<field:np />, {0: spanNot(field:test, field:no, 0, 0)})})", sq.toString());
};
@Test
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestSpanSegmentQuery.java b/src/test/java/de/ids_mannheim/korap/query/TestSpanSegmentQuery.java
index 57a9288..7717f84 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestSpanSegmentQuery.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestSpanSegmentQuery.java
@@ -34,10 +34,10 @@
assertEquals("spanSegment(field:a, field:b)", ssquery.toQuery().toString());
ssquery.without("c");
- assertEquals("spanNot(spanSegment(field:a, field:b), field:c)", ssquery.toQuery().toString());
+ assertEquals("spanNot(spanSegment(field:a, field:b), field:c, 0, 0)", ssquery.toQuery().toString());
ssquery.without("d");
- assertEquals("spanNot(spanSegment(field:a, field:b), spanOr([field:c, field:d]))", ssquery.toQuery().toString());
+ assertEquals("spanNot(spanSegment(field:a, field:b), spanOr([field:c, field:d]), 0, 0)", ssquery.toQuery().toString());
};
@@ -62,11 +62,11 @@
ssquery.without(new SpanRegexQueryWrapper("field", "x.?y"));
- assertEquals("spanNot(spanSegment(spanSegment(spanSegment(spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/)), field:c), field:d), field:e), SpanMultiTermQueryWrapper(field:/x.?y/))", ssquery.toQuery().toString());
+ assertEquals("spanNot(spanSegment(spanSegment(spanSegment(spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/)), field:c), field:d), field:e), SpanMultiTermQueryWrapper(field:/x.?y/), 0, 0)", ssquery.toQuery().toString());
ssquery.without(new SpanRegexQueryWrapper("field", "z{5,9}"));
- assertEquals("spanNot(spanSegment(spanSegment(spanSegment(spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/)), field:c), field:d), field:e), spanOr([SpanMultiTermQueryWrapper(field:/x.?y/), SpanMultiTermQueryWrapper(field:/z{5,9}/)]))", ssquery.toQuery().toString());
+ assertEquals("spanNot(spanSegment(spanSegment(spanSegment(spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/)), field:c), field:d), field:e), spanOr([SpanMultiTermQueryWrapper(field:/x.?y/), SpanMultiTermQueryWrapper(field:/z{5,9}/)]), 0, 0)", ssquery.toQuery().toString());
};
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestKorapResult.java b/src/test/java/de/ids_mannheim/korap/search/TestKorapResult.java
new file mode 100644
index 0000000..10ca9bc
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKorapResult.java
@@ -0,0 +1,92 @@
+import java.util.*;
+import java.io.IOException;
+
+import org.apache.lucene.search.spans.SpanQuery;
+
+import de.ids_mannheim.korap.KorapIndex;
+import de.ids_mannheim.korap.KorapQuery;
+import de.ids_mannheim.korap.KorapResult;
+import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.KorapMatch;
+import de.ids_mannheim.korap.index.FieldDocument;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.JsonNode;
+
+import static de.ids_mannheim.korap.Test.*;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.junit.Ignore;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class TestKorapResult {
+
+ @Test
+ public void checkJSONResult () throws IOException {
+ KorapIndex ki = new KorapIndex();
+ FieldDocument fd = new FieldDocument();
+ fd.addString("ID", "doc-1");
+ fd.addString("UID", "1");
+ fd.addTV("base",
+ "abab",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>4]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]" +
+ "[(3-4)s:b|i:a|_3#3-4]");
+ ki.addDoc(fd);
+ fd = new FieldDocument();
+ fd.addString("ID", "doc-2");
+ fd.addString("UID", "2");
+ fd.addTV("base",
+ "aba",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>3]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]");
+ ki.addDoc(fd);
+
+ // Commit!
+ ki.commit();
+
+ KorapQuery kq = new KorapQuery("base");
+ SpanQuery q = (SpanQuery) kq.or(kq._(1, kq.seg("s:a"))).or(kq._(2, kq.seg("s:b"))).toQuery();
+ KorapResult kr = ki.search(q);
+ assertEquals(7, kr.getTotalResults());
+
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode res = mapper.readTree(kr.toJSON());
+ assertEquals(7, res.at("/totalResults").asInt());
+ assertEquals("spanOr([{1: base:s:a}, {2: base:s:b}])", res.at("/query").asText());
+ assertEquals(0, res.at("/startIndex").asInt());
+ assertEquals(25, res.at("/itemsPerPage").asInt());
+ assertEquals("token", res.at("/context/left/0").asText());
+ assertEquals(6, res.at("/context/left/1").asInt());
+ assertEquals("token", res.at("/context/right/0").asText());
+ assertEquals(6, res.at("/context/right/1").asInt());
+
+ assertEquals("base", res.at("/matches/0/field").asText());
+ /*
+ Probably a Jackson bug
+ assertTrue(res.at("/matches/0/startMore").asBoolean());
+ assertTrue(res.at("/matches/0/endMore").asBoolean());
+ */
+ assertEquals(1, res.at("/matches/0/UID").asInt());
+ assertEquals("doc-1", res.at("/matches/0/docID").asText());
+ assertEquals("match-doc-1-p0-1(1)0-0", res.at("/matches/0/ID").asText());
+ assertEquals("<span class=\"context-left\"></span><span class=\"match\"><em class=\"class-1 level-0\">a</em></span><span class=\"context-right\">bab</span>", res.at("/matches/0/snippet").asText());
+
+ assertEquals("base", res.at("/matches/6/field").asText());
+ /*
+ Probably a Jackson bug
+ assertEquals(true, res.at("/matches/6/startMore").asBoolean());
+ assertEquals(true, res.at("/matches/6/endMore").asBoolean());
+ */
+ assertEquals(2, res.at("/matches/6/UID").asInt());
+ assertEquals("doc-2", res.at("/matches/6/docID").asText());
+ assertEquals("match-doc-2-p2-3(1)2-2", res.at("/matches/6/ID").asText());
+ assertEquals("<span class=\"context-left\">ab</span><span class=\"match\"><em class=\"class-1 level-0\">a</em></span><span class=\"context-right\"></span>", res.at("/matches/6/snippet").asText());
+
+ };
+};