| Eliza Margaretha | 0192918 | 2014-02-19 11:48:59 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.index; |
| 2 | |
| margaretha | 50c7633 | 2015-03-19 10:10:39 +0100 | [diff] [blame] | 3 | import static org.junit.Assert.assertEquals; |
| 4 | import static org.junit.Assert.fail; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 5 | |
| margaretha | 50c7633 | 2015-03-19 10:10:39 +0100 | [diff] [blame] | 6 | import java.io.IOException; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 7 | |
| margaretha | 50c7633 | 2015-03-19 10:10:39 +0100 | [diff] [blame] | 8 | import org.apache.lucene.index.Term; |
| 9 | import org.apache.lucene.search.spans.SpanOrQuery; |
| 10 | import org.apache.lucene.search.spans.SpanQuery; |
| 11 | import org.apache.lucene.search.spans.SpanTermQuery; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 12 | import org.junit.Ignore; |
| margaretha | 50c7633 | 2015-03-19 10:10:39 +0100 | [diff] [blame] | 13 | import org.junit.Test; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 14 | import org.junit.runner.RunWith; |
| 15 | import org.junit.runners.JUnit4; |
| 16 | |
| Nils Diewald | 2d5f810 | 2015-02-26 21:07:54 +0000 | [diff] [blame] | 17 | import de.ids_mannheim.korap.KrillCollection; |
| margaretha | 50c7633 | 2015-03-19 10:10:39 +0100 | [diff] [blame] | 18 | import de.ids_mannheim.korap.KrillIndex; |
| 19 | import de.ids_mannheim.korap.query.QueryBuilder; |
| 20 | import de.ids_mannheim.korap.query.SpanClassQuery; |
| 21 | import de.ids_mannheim.korap.query.SpanElementQuery; |
| 22 | import de.ids_mannheim.korap.query.SpanFocusQuery; |
| 23 | import de.ids_mannheim.korap.query.SpanNextQuery; |
| 24 | import de.ids_mannheim.korap.query.SpanWithinQuery; |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 25 | import de.ids_mannheim.korap.response.Match; |
| margaretha | 50c7633 | 2015-03-19 10:10:39 +0100 | [diff] [blame] | 26 | import de.ids_mannheim.korap.response.Result; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 27 | |
| 28 | // mvn -Dtest=TestWithinIndex#indexExample1 test |
| 29 | |
| Nils Diewald | 85f9c42 | 2015-02-06 21:09:16 +0000 | [diff] [blame] | 30 | // match is focus and split |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 31 | |
| 32 | @RunWith(JUnit4.class) |
| 33 | public class TestMatchIndex { |
| margaretha | 50c7633 | 2015-03-19 10:10:39 +0100 | [diff] [blame] | 34 | @Test |
| 35 | public void testEmbeddedClassQuery () throws IOException { |
| 36 | KrillIndex ki = new KrillIndex(); |
| 37 | |
| 38 | // abcabcabac |
| 39 | FieldDocument fd = new FieldDocument(); |
| 40 | fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10]" |
| 41 | + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:c|i:c|_2#2-3]" |
| 42 | + "[(3-4)s:a|i:a|_3#3-4]" + "[(4-5)s:b|i:b|_4#4-5]" |
| 43 | + "[(5-6)s:c|i:c|_5#5-6]" + "[(6-7)s:a|i:a|_6#6-7]" |
| 44 | + "[(7-8)s:b|i:b|_7#7-8]" + "[(8-9)s:a|i:a|_8#8-9]" |
| 45 | + "[(9-10)s:c|i:c|_9#9-10]"); |
| 46 | ki.addDoc(fd); |
| 47 | |
| 48 | ki.commit(); |
| 49 | |
| 50 | SpanQuery sq; |
| 51 | Result kr; |
| 52 | |
| 53 | sq = new SpanFocusQuery(new SpanClassQuery(new SpanNextQuery( |
| 54 | new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), |
| 55 | (byte) 1), new SpanClassQuery(new SpanTermQuery( |
| 56 | new Term("base", "s:c")), (byte) 2)), (byte) 3), |
| 57 | (byte) 3); |
| 58 | |
| 59 | kr = ki.search(sq, (short) 10); |
| 60 | |
| 61 | assertEquals("totalResults", kr.getTotalResults(), 2); |
| 62 | assertEquals("StartPos (0)", 1, kr.getMatch(0).startPos); |
| 63 | assertEquals("EndPos (0)", 3, kr.getMatch(0).endPos); |
| 64 | assertEquals("SnippetBrackets (0)", "a[{3:{1:b}{2:c}}]abcaba ...", kr |
| 65 | .getMatch(0).getSnippetBrackets()); |
| 66 | assertEquals("StartPos (1)", 4, kr.getMatch(1).startPos); |
| 67 | assertEquals("EndPos (1)", 6, kr.getMatch(1).endPos); |
| 68 | assertEquals("SnippetBrackets (1)", "abca[{3:{1:b}{2:c}}]abac", kr |
| 69 | .getMatch(1).getSnippetBrackets()); |
| 70 | |
| 71 | assertEquals("Document count", 1, ki.numberOf("base", "documents")); |
| 72 | assertEquals("Token count", 10, ki.numberOf("base", "t")); |
| 73 | |
| 74 | } |
| 75 | |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 76 | |
| 77 | @Test |
| 78 | public void indexExample1 () throws IOException { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 79 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 80 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 81 | // abcabcabac |
| 82 | FieldDocument fd = new FieldDocument(); |
| 83 | fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10]" |
| 84 | + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:c|i:c|_2#2-3]" |
| 85 | + "[(3-4)s:a|i:a|_3#3-4]" + "[(4-5)s:b|i:b|_4#4-5]" |
| 86 | + "[(5-6)s:c|i:c|_5#5-6]" + "[(6-7)s:a|i:a|_6#6-7]" |
| 87 | + "[(7-8)s:b|i:b|_7#7-8]" + "[(8-9)s:a|i:a|_8#8-9]" |
| 88 | + "[(9-10)s:c|i:c|_9#9-10]"); |
| 89 | ki.addDoc(fd); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 90 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 91 | ki.commit(); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 92 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 93 | SpanQuery sq; |
| 94 | Result kr; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 95 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 96 | sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:b")), |
| 97 | new SpanClassQuery(new SpanTermQuery(new Term("base", "s:a")))); |
| 98 | kr = ki.search(sq, (short) 10); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 99 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 100 | assertEquals("totalResults", kr.getTotalResults(), 1); |
| 101 | assertEquals("StartPos (0)", 7, kr.getMatch(0).startPos); |
| 102 | assertEquals("EndPos (0)", 9, kr.getMatch(0).endPos); |
| 103 | assertEquals("SnippetBrackets (0)", "... bcabca[b{1:a}]c", |
| 104 | kr.getMatch(0).getSnippetBrackets()); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 105 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 106 | assertEquals( |
| 107 | "Test no 'more' context", |
| 108 | "<span class=\"context-left\"><span class=\"more\"></span>bcabca</span><mark>b<mark class=\"class-1 level-0\">a</mark></mark><span class=\"context-right\">c</span>", |
| 109 | kr.getMatch(0).getSnippetHTML()); |
| 110 | sq = new SpanFocusQuery(new SpanNextQuery(new SpanTermQuery(new Term( |
| 111 | "base", "s:b")), new SpanClassQuery(new SpanTermQuery(new Term( |
| 112 | "base", "s:a"))))); |
| 113 | kr = ki.search(sq, (short) 10); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 114 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 115 | assertEquals("totalResults", kr.getTotalResults(), 1); |
| 116 | assertEquals("StartPos (0)", 8, kr.getMatch(0).startPos); |
| 117 | assertEquals("EndPos (0)", 9, kr.getMatch(0).endPos); |
| 118 | assertEquals("SnippetBrackets (0)", "... cabcab[{1:a}]c", kr |
| 119 | .getMatch(0).getSnippetBrackets()); |
| 120 | sq = new SpanFocusQuery(new SpanNextQuery(new SpanClassQuery( |
| 121 | new SpanTermQuery(new Term("base", "s:a")), (byte) 2), |
| 122 | new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), |
| 123 | (byte) 3)), (byte) 3); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 124 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 125 | kr = ki.search(sq, (short) 10); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 126 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 127 | assertEquals("totalResults", kr.getTotalResults(), 3); |
| 128 | assertEquals("StartPos (0)", 1, kr.getMatch(0).startPos); |
| 129 | assertEquals("EndPos (0)", 2, kr.getMatch(0).endPos); |
| 130 | assertEquals("SnippetBrackets (0)", "a[{3:b}]cabcab ...", kr |
| 131 | .getMatch(0).getSnippetBrackets()); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 132 | |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 133 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 134 | assertEquals( |
| 135 | "<span class=\"context-left\">a</span><mark><mark class=\"class-3 level-0\">b</mark></mark><span class=\"context-right\">cabcab<span class=\"more\"></span></span>", |
| 136 | kr.getMatch(0).getSnippetHTML()); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 137 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 138 | assertEquals("StartPos (1)", 4, kr.getMatch(1).startPos); |
| 139 | assertEquals("EndPos (1)", 5, kr.getMatch(1).endPos); |
| 140 | assertEquals("SnippetBrackets (1)", "abca[{3:b}]cabac", kr.getMatch(1) |
| 141 | .getSnippetBrackets()); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 142 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 143 | assertEquals( |
| 144 | "<span class=\"context-left\">abca</span><mark><mark class=\"class-3 level-0\">b</mark></mark><span class=\"context-right\">cabac</span>", |
| 145 | kr.getMatch(1).getSnippetHTML()); |
| 146 | |
| 147 | assertEquals("StartPos (2)", 7, kr.getMatch(2).startPos); |
| 148 | assertEquals("EndPos (2)", 8, kr.getMatch(2).endPos); |
| 149 | assertEquals("SnippetBrackets (2)", "... bcabca[{3:b}]ac", |
| 150 | kr.getMatch(2).getSnippetBrackets()); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 151 | |
| 152 | |
| 153 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 154 | // abcabcabac |
| 155 | sq = new SpanFocusQuery( |
| 156 | new SpanNextQuery(new SpanTermQuery(new Term("base", "s:a")), |
| 157 | new SpanClassQuery(new SpanNextQuery(new SpanTermQuery( |
| 158 | new Term("base", "s:b")), new SpanClassQuery( |
| 159 | new SpanTermQuery(new Term("base", "s:a")))), |
| 160 | (byte) 2)), (byte) 2); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 161 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 162 | kr = ki.search(sq, (short) 10); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 163 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 164 | assertEquals("totalResults", kr.getTotalResults(), 1); |
| 165 | assertEquals("SnippetBrackets (0)", "... bcabca[{2:b{1:a}}]c", kr |
| 166 | .getMatch(0).getSnippetBrackets()); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 167 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 168 | assertEquals( |
| 169 | "SnippetHTML (0) 1", |
| 170 | "<span class=\"context-left\"><span class=\"more\"></span>bcabca</span><mark><mark class=\"class-2 level-0\">b<mark class=\"class-1 level-1\">a</mark></mark></mark><span class=\"context-right\">c</span>", |
| 171 | kr.getMatch(0).getSnippetHTML()); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 172 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 173 | // Offset tokens |
| 174 | kr = ki.search(sq, 0, (short) 10, true, (short) 2, true, (short) 2); |
| 175 | assertEquals("totalResults", kr.getTotalResults(), 1); |
| 176 | assertEquals("SnippetBrackets (0)", "... ca[{2:b{1:a}}]c", |
| 177 | kr.getMatch(0).getSnippetBrackets()); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 178 | |
| 179 | |
| 180 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 181 | // Offset Characters |
| 182 | kr = ki.search(sq, 0, (short) 10, false, (short) 1, false, (short) 0); |
| 183 | assertEquals("totalResults", kr.getTotalResults(), 1); |
| 184 | assertEquals("SnippetBrackets (0)", "... a[{2:b{1:a}}] ...", kr |
| 185 | .getMatch(0).getSnippetBrackets()); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 186 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 187 | assertEquals( |
| 188 | "SnippetHTML (0) 2", |
| 189 | "<span class=\"context-left\"><span class=\"more\"></span>a</span><mark><mark class=\"class-2 level-0\">b<mark class=\"class-1 level-1\">a</mark></mark></mark><span class=\"context-right\"><span class=\"more\"></span></span>", |
| 190 | kr.getMatch(0).getSnippetHTML()); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 191 | |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 192 | |
| Nils Diewald | 1455e1e | 2014-08-01 16:12:43 +0000 | [diff] [blame] | 193 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 194 | // Don't match the expected class! |
| 195 | sq = new SpanFocusQuery(new SpanNextQuery(new SpanClassQuery( |
| 196 | new SpanTermQuery(new Term("base", "s:b")), (byte) 1), |
| 197 | new SpanClassQuery(new SpanTermQuery(new Term("base", "s:c")), |
| 198 | (byte) 2)), (byte) 3); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 199 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 200 | kr = ki.search(sq, (short) 10); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 201 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 202 | assertEquals("totalResults", kr.getTotalResults(), 0); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 203 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 204 | sq = new SpanFocusQuery(new SpanNextQuery(new SpanTermQuery(new Term( |
| 205 | "base", "s:a")), new SpanClassQuery(new SpanNextQuery( |
| 206 | new SpanTermQuery(new Term("base", "s:b")), new SpanTermQuery( |
| 207 | new Term("base", "s:c")))))); |
| 208 | |
| 209 | kr = ki.search(sq, (short) 2); |
| 210 | |
| 211 | assertEquals("totalResults", kr.getTotalResults(), 2); |
| 212 | assertEquals("StartPos (0)", 1, kr.getMatch(0).startPos); |
| 213 | assertEquals("EndPos (0)", 3, kr.getMatch(0).endPos); |
| 214 | assertEquals("SnippetBrackets (0)", "a[{1:bc}]abcaba ...", |
| 215 | kr.getMatch(0).getSnippetBrackets()); |
| 216 | assertEquals("StartPos (1)", 4, kr.getMatch(1).startPos); |
| 217 | assertEquals("EndPos (1)", 6, kr.getMatch(1).endPos); |
| 218 | assertEquals("SnippetBrackets (1)", "abca[{1:bc}]abac", kr.getMatch(1) |
| 219 | .getSnippetBrackets()); |
| 220 | |
| 221 | assertEquals(1, ki.numberOf("base", "documents")); |
| 222 | assertEquals(10, ki.numberOf("base", "t")); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 223 | }; |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 224 | |
| 225 | |
| 226 | @Test |
| 227 | public void indexExample2 () throws IOException { |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 228 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 229 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 230 | // abcabcabac |
| 231 | FieldDocument fd = new FieldDocument(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 232 | fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10]" |
| 233 | + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:c|i:c|_2#2-3]" |
| 234 | + "[(3-4)s:a|i:a|_3#3-4]" + "[(4-5)s:b|i:b|_4#4-5]" |
| 235 | + "[(5-6)s:c|i:c|_5#5-6]" + "[(6-7)s:a|i:a|_6#6-7]" |
| 236 | + "[(7-8)s:b|i:b|_7#7-8]" + "[(8-9)s:a|i:a|_8#8-9]" |
| 237 | + "[(9-10)s:c|i:c|_9#9-10]"); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 238 | ki.addDoc(fd); |
| 239 | ki.commit(); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 240 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 241 | SpanQuery sq; |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 242 | Result kr; |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 243 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 244 | // No contexts: |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 245 | sq = new SpanOrQuery(new SpanTermQuery(new Term("base", "s:a")), |
| 246 | new SpanTermQuery(new Term("base", "s:c"))); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 247 | kr = ki.search(sq, (short) 20); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 248 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 249 | assertEquals("totalResults", kr.getTotalResults(), 7); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 250 | assertEquals( |
| 251 | "SnippetBrackets (0)", |
| 252 | "<span class=\"context-left\"></span><mark>a</mark><span class=\"context-right\">bcabca<span class=\"more\"></span></span>", |
| 253 | kr.getMatch(0).getSnippetHTML()); |
| 254 | assertEquals("SnippetBrackets (0)", "[a]bcabca ...", kr.getMatch(0) |
| 255 | .getSnippetBrackets()); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 256 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 257 | assertEquals("SnippetBrackets (1)", "ab[c]abcaba ...", kr.getMatch(1) |
| 258 | .getSnippetBrackets()); |
| 259 | assertEquals( |
| 260 | "SnippetBrackets (1)", |
| 261 | "<span class=\"context-left\">ab</span><mark>c</mark><span class=\"context-right\">abcaba<span class=\"more\"></span></span>", |
| 262 | kr.getMatch(1).getSnippetHTML()); |
| 263 | |
| 264 | assertEquals("SnippetBrackets (6)", "... abcaba[c]", kr.getMatch(6) |
| 265 | .getSnippetBrackets()); |
| 266 | assertEquals( |
| 267 | "SnippetBrackets (6)", |
| 268 | "<span class=\"context-left\"><span class=\"more\"></span>abcaba</span><mark>c</mark><span class=\"context-right\"></span>", |
| 269 | kr.getMatch(6).getSnippetHTML()); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 270 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 271 | kr = ki.search(sq, 0, (short) 20, true, (short) 0, true, (short) 0); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 272 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 273 | assertEquals("totalResults", kr.getTotalResults(), 7); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 274 | assertEquals("SnippetBrackets (0)", "[a] ...", kr.getMatch(0) |
| 275 | .getSnippetBrackets()); |
| 276 | assertEquals( |
| 277 | "SnippetHTML (0)", |
| 278 | "<span class=\"context-left\"></span><mark>a</mark><span class=\"context-right\"><span class=\"more\"></span></span>", |
| 279 | kr.getMatch(0).getSnippetHTML()); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 280 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 281 | assertEquals("SnippetBrackets (1)", "... [c] ...", kr.getMatch(1) |
| 282 | .getSnippetBrackets()); |
| 283 | assertEquals( |
| 284 | "SnippetHTML (1)", |
| 285 | "<span class=\"context-left\"><span class=\"more\"></span></span><mark>c</mark><span class=\"context-right\"><span class=\"more\"></span></span>", |
| 286 | kr.getMatch(1).getSnippetHTML()); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 287 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 288 | assertEquals("SnippetBrackets (6)", "... [c]", kr.getMatch(6) |
| 289 | .getSnippetBrackets()); |
| 290 | assertEquals( |
| 291 | "SnippetBrackets (6)", |
| 292 | "<span class=\"context-left\"><span class=\"more\"></span></span><mark>c</mark><span class=\"context-right\"></span>", |
| 293 | kr.getMatch(6).getSnippetHTML()); |
| Nils Diewald | f3b30ae | 2013-11-27 17:42:37 +0000 | [diff] [blame] | 294 | }; |
| Nils Diewald | 3ef9a47 | 2013-12-02 16:06:09 +0000 | [diff] [blame] | 295 | |
| 296 | |
| 297 | @Test |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 298 | public void indexExample3 () throws Exception { |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 299 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | 3ef9a47 | 2013-12-02 16:06:09 +0000 | [diff] [blame] | 300 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 301 | // abcabcabac |
| 302 | FieldDocument fd = new FieldDocument(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 303 | fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10]" |
| 304 | + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:c|i:c|_2#2-3]" |
| 305 | + "[(3-4)s:a|i:a|_3#3-4]" + "[(4-5)s:b|i:b|_4#4-5]" |
| 306 | + "[(5-6)s:c|i:c|_5#5-6]" + "[(6-7)s:a|i:a|_6#6-7]" |
| 307 | + "[(7-8)s:b|i:b|_7#7-8]" + "[(8-9)s:a|i:a|_8#8-9]" |
| 308 | + "[(9-10)s:c|i:c|_9#9-10]"); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 309 | ki.addDoc(fd); |
| 310 | ki.commit(); |
| Nils Diewald | 3ef9a47 | 2013-12-02 16:06:09 +0000 | [diff] [blame] | 311 | |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 312 | Result kr; |
| Nils Diewald | 3ef9a47 | 2013-12-02 16:06:09 +0000 | [diff] [blame] | 313 | |
| Nils Diewald | 8904c1d | 2015-02-26 16:13:18 +0000 | [diff] [blame] | 314 | QueryBuilder kq = new QueryBuilder("base"); |
| Nils Diewald | 3ef9a47 | 2013-12-02 16:06:09 +0000 | [diff] [blame] | 315 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 316 | SpanQuery sq = kq._( |
| 317 | 1, |
| 318 | kq.seq(kq.seg("s:b")).append(kq.seg("s:a")) |
| 319 | .append(kq._(2, kq.seg("s:c")))).toQuery(); |
| 320 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 321 | kr = ki.search(sq, 0, (short) 20, true, (short) 2, true, (short) 5); |
| Nils Diewald | 3ef9a47 | 2013-12-02 16:06:09 +0000 | [diff] [blame] | 322 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 323 | assertEquals("totalResults", kr.getTotalResults(), 1); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 324 | assertEquals("SnippetBrackets (0)", "... ca[{1:ba{2:c}}]", |
| 325 | kr.getMatch(0).getSnippetBrackets()); |
| Nils Diewald | 3ef9a47 | 2013-12-02 16:06:09 +0000 | [diff] [blame] | 326 | }; |
| Nils Diewald | d4401ec | 2014-06-16 17:04:02 +0000 | [diff] [blame] | 327 | |
| 328 | |
| 329 | @Test |
| 330 | public void indexExampleExtend () throws IOException { |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 331 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | d4401ec | 2014-06-16 17:04:02 +0000 | [diff] [blame] | 332 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 333 | // abcabcabac |
| 334 | FieldDocument fd = new FieldDocument(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 335 | fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10]" |
| 336 | + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:c|i:c|_2#2-3]" |
| 337 | + "[(3-4)s:a|i:a|_3#3-4]" + "[(4-5)s:b|i:b|_4#4-5]" |
| 338 | + "[(5-6)s:c|i:c|_5#5-6]" + "[(6-7)s:a|i:a|_6#6-7]" |
| 339 | + "[(7-8)s:b|i:b|_7#7-8]" + "[(8-9)s:a|i:a|_8#8-9]" |
| 340 | + "[(9-10)s:c|i:c|_9#9-10]"); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 341 | ki.addDoc(fd); |
| 342 | ki.commit(); |
| Nils Diewald | d4401ec | 2014-06-16 17:04:02 +0000 | [diff] [blame] | 343 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 344 | SpanQuery sq; |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 345 | Result kr; |
| Nils Diewald | d4401ec | 2014-06-16 17:04:02 +0000 | [diff] [blame] | 346 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 347 | sq = new SpanFocusQuery(new SpanNextQuery(new SpanClassQuery( |
| 348 | new SpanTermQuery(new Term("base", "s:a")), (byte) 2), |
| 349 | new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), |
| 350 | (byte) 3)), (byte) 3); |
| Nils Diewald | d4401ec | 2014-06-16 17:04:02 +0000 | [diff] [blame] | 351 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 352 | kr = ki.search(sq, (short) 10); |
| Nils Diewald | d4401ec | 2014-06-16 17:04:02 +0000 | [diff] [blame] | 353 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 354 | assertEquals("totalResults", kr.getTotalResults(), 3); |
| Nils Diewald | d4401ec | 2014-06-16 17:04:02 +0000 | [diff] [blame] | 355 | |
| Nils Diewald | 392bcf3 | 2015-02-26 20:01:17 +0000 | [diff] [blame] | 356 | Match km = kr.getMatch(0); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 357 | assertEquals("StartPos (0)", 1, km.startPos); |
| 358 | assertEquals("EndPos (0)", 2, km.endPos); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 359 | assertEquals("SnippetBrackets (0)", "a[{3:b}]cabcab ...", |
| 360 | km.getSnippetBrackets()); |
| Nils Diewald | d4401ec | 2014-06-16 17:04:02 +0000 | [diff] [blame] | 361 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 362 | sq = new SpanFocusQuery(new SpanFocusQuery(new SpanNextQuery( |
| 363 | new SpanClassQuery(new SpanTermQuery(new Term("base", "s:a")), |
| 364 | (byte) 2), new SpanClassQuery(new SpanTermQuery( |
| 365 | new Term("base", "s:b")), (byte) 3)), (byte) 3), |
| 366 | (byte) 2); |
| 367 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 368 | kr = ki.search(sq, (short) 10); |
| Nils Diewald | d4401ec | 2014-06-16 17:04:02 +0000 | [diff] [blame] | 369 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 370 | km = kr.getMatch(0); |
| 371 | assertEquals("StartPos (0)", 0, km.startPos); |
| 372 | assertEquals("EndPos (0)", 1, km.endPos); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 373 | assertEquals("SnippetBrackets (0)", "[{2:a}]bcabca ...", |
| 374 | km.getSnippetBrackets()); |
| Nils Diewald | d4401ec | 2014-06-16 17:04:02 +0000 | [diff] [blame] | 375 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 376 | // TODO: Check ID |
| Nils Diewald | d4401ec | 2014-06-16 17:04:02 +0000 | [diff] [blame] | 377 | }; |
| Nils Diewald | 44693e8 | 2014-11-05 18:00:12 +0000 | [diff] [blame] | 378 | |
| 379 | |
| 380 | @Test |
| Nils Diewald | 85f9c42 | 2015-02-06 21:09:16 +0000 | [diff] [blame] | 381 | public void indexExampleFocusWithSpan () throws IOException { |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 382 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 383 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 384 | // abcabcabac |
| 385 | FieldDocument fd = new FieldDocument(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 386 | fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10]" |
| 387 | + "[(1-2)s:b|i:b|_1#1-2|<>:s#1-5$<i>5]" |
| 388 | + "[(2-3)s:c|i:c|_2#2-3|<>:s#2-7$<i>7]" |
| 389 | + "[(3-4)s:a|i:a|_3#3-4]" + "[(4-5)s:b|i:b|_4#4-5]" |
| 390 | + "[(5-6)s:c|i:c|_5#5-6]" + "[(6-7)s:a|i:a|_6#6-7]" |
| 391 | + "[(7-8)s:b|i:b|_7#7-8]" + "[(8-9)s:a|i:a|_8#8-9]" |
| 392 | + "[(9-10)s:c|i:c|_9#9-10]"); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 393 | ki.addDoc(fd); |
| 394 | ki.commit(); |
| Nils Diewald | 44693e8 | 2014-11-05 18:00:12 +0000 | [diff] [blame] | 395 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 396 | SpanQuery sq; |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 397 | Result kr; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 398 | |
| margaretha | 50c7633 | 2015-03-19 10:10:39 +0100 | [diff] [blame] | 399 | // sq = new SpanWithinQuery(new SpanClassQuery(new SpanElementQuery( |
| 400 | // "base", "s"), (byte) 2), new SpanClassQuery(new SpanTermQuery( |
| 401 | // new Term("base", "s:b")), (byte) 3)); |
| 402 | // |
| 403 | // kr = ki.search(sq, (short) 10); |
| 404 | // assertEquals(kr.getSerialQuery(), |
| 405 | // "spanContain({2: <base:s />}, {3: base:s:b})"); |
| 406 | // assertEquals(kr.getMatch(0).getSnippetBrackets(), |
| 407 | // "a[{2:{3:b}cab}]cabac"); |
| Nils Diewald | 44693e8 | 2014-11-05 18:00:12 +0000 | [diff] [blame] | 408 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 409 | sq = new SpanFocusQuery(new SpanWithinQuery(new SpanClassQuery( |
| 410 | new SpanElementQuery("base", "s"), (byte) 2), |
| 411 | new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), |
| 412 | (byte) 3)), (byte) 3); |
| Nils Diewald | 44693e8 | 2014-11-05 18:00:12 +0000 | [diff] [blame] | 413 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 414 | kr = ki.search(sq, (short) 10); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 415 | assertEquals(kr.getSerialQuery(), |
| 416 | "focus(3: spanContain({2: <base:s />}, {3: base:s:b}))"); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 417 | assertEquals(kr.getMatch(0).getSnippetBrackets(), "a[{3:b}]cabcab ..."); |
| Nils Diewald | 44693e8 | 2014-11-05 18:00:12 +0000 | [diff] [blame] | 418 | }; |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 419 | |
| 420 | |
| Nils Diewald | f075df0 | 2015-03-03 20:34:00 +0000 | [diff] [blame] | 421 | @Ignore |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 422 | public void indexExampleFocusWithSkip () throws IOException { |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 423 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 424 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 425 | // abcabcabac |
| 426 | FieldDocument fd = new FieldDocument(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 427 | fd.addTV("base", "abcabcabac", |
| 428 | // The payload should be ignored |
| 429 | "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10]" |
| 430 | + // |<>:p#0-10<i>9]" + |
| 431 | "[(1-2)s:b|i:b|_1#1-2|<>:s#1-5$<i>5]" |
| 432 | + "[(2-3)s:c|i:c|_2#2-3|<>:s#2-7$<i>7]" |
| 433 | + "[(3-4)s:a|i:a|_3#3-4]" + "[(4-5)s:b|i:b|_4#4-5]" |
| 434 | + "[(5-6)s:c|i:c|_5#5-6]" + "[(6-7)s:a|i:a|_6#6-7]" |
| 435 | + "[(7-8)s:b|i:b|_7#7-8]" + "[(8-9)s:a|i:a|_8#8-9]" |
| 436 | + "[(9-10)s:c|i:c|_9#9-10]"); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 437 | ki.addDoc(fd); |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 438 | fd = new FieldDocument(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 439 | fd.addTV("base", "gbcgbcgbgc", |
| 440 | "[(0-1)s:g|i:g|_0#0-1|-:t$<i>10|<>:p#0-10$<i>9]" |
| 441 | + "[(1-2)s:b|i:b|_1#1-2|<>:s#1-5$<i>5]" |
| 442 | + "[(2-3)s:c|i:c|_2#2-3|<>:s#2-7$<i>7]" |
| 443 | + "[(3-4)s:g|i:g|_3#3-4]" + "[(4-5)s:b|i:b|_4#4-5]" |
| 444 | + "[(5-6)s:c|i:c|_5#5-6]" + "[(6-7)s:g|i:g|_6#6-7]" |
| 445 | + "[(7-8)s:b|i:b|_7#7-8]" + "[(8-9)s:g|i:g|_8#8-9]" |
| 446 | + "[(9-10)s:c|i:c|_9#9-10]"); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 447 | ki.addDoc(fd); |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 448 | fd = new FieldDocument(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 449 | fd.addTV("base", "gbcgbcgbgc", "[(0-1)s:g|i:g|_0#0-1|-:t$<i>10]" |
| 450 | + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:c|i:c|_2#2-3]" |
| 451 | + "[(3-4)s:g|i:g|_3#3-4]" + "[(4-5)s:b|i:b|_4#4-5]" |
| 452 | + "[(5-6)s:c|i:c|_5#5-6]" + "[(6-7)s:g|i:g|_6#6-7]" |
| 453 | + "[(7-8)s:b|i:b|_7#7-8]" + "[(8-9)s:g|i:g|_8#8-9]" |
| 454 | + "[(9-10)s:c|i:c|_9#9-10]"); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 455 | ki.addDoc(fd); |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 456 | fd = new FieldDocument(); |
| 457 | // contains(<p>, focus(3: contains({2:<s>}, {3:a}))) |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 458 | fd.addTV("base", "acabcabac", |
| 459 | "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10|<>:p#0-9$<i>8]" |
| 460 | + "[(1-2)s:b|i:b|_1#1-2|<>:s#1-5$<i>5]" |
| 461 | + "[(2-3)s:a|i:a|_2#2-3|<>:s#2-7$<i>7]" |
| 462 | + "[(3-4)s:b|i:b|_3#3-4]" + "[(4-5)s:c|i:c|_4#4-5]" |
| 463 | + "[(5-6)s:a|i:a|_5#5-6]" + "[(6-7)s:b|i:b|_6#6-7]" |
| 464 | + "[(7-8)s:a|i:a|_7#7-8]" + "[(8-9)s:c|i:c|_8#8-9]"); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 465 | ki.addDoc(fd); |
| 466 | ki.commit(); |
| 467 | |
| 468 | SpanQuery sq; |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 469 | Result kr; |
| Nils Diewald | 2d5f810 | 2015-02-26 21:07:54 +0000 | [diff] [blame] | 470 | KrillCollection kc = new KrillCollection(ki); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 471 | |
| 472 | assertEquals("Documents", 4, kc.numberOf("documents")); |
| 473 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 474 | // within(<p>, focus(3:within({2:<s>}, {3:a}))) |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 475 | sq = new SpanWithinQuery(new SpanElementQuery("base", "p"), |
| 476 | new SpanFocusQuery(new SpanWithinQuery(new SpanClassQuery( |
| 477 | new SpanElementQuery("base", "s"), (byte) 2), |
| 478 | new SpanClassQuery(new SpanTermQuery(new Term("base", |
| 479 | "s:a")), (byte) 3)), (byte) 3)); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 480 | |
| 481 | fail("Skipping may go horribly wrong! (Known issue)"); |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 482 | |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 483 | kr = kc.search(sq); |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 484 | // System.err.println(kr.getOverview()); |
| 485 | |
| 486 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 487 | assertEquals( |
| 488 | kr.getSerialQuery(), |
| 489 | "spanContain(<base:p />, focus(3: spanContain({2: <base:s />}, {3: base:s:a})))"); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 490 | assertEquals(12, kr.getTotalResults()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 491 | assertEquals("[a{2:bc{3:a}b}cabac]", kr.getMatch(0) |
| 492 | .getSnippetBrackets()); |
| 493 | assertEquals("[ab{2:c{3:a}bcab}ac]", kr.getMatch(1) |
| 494 | .getSnippetBrackets()); |
| 495 | assertEquals("[ab{2:cabc{3:a}}bac]", kr.getMatch(2) |
| 496 | .getSnippetBrackets()); |
| Nils Diewald | 5c37570 | 2015-02-09 20:58:24 +0000 | [diff] [blame] | 497 | }; |
| 498 | |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 499 | }; |