| Nils Diewald | d732e54 | 2014-11-12 17:54:02 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.index; |
| 2 | |
| 3 | import static org.junit.Assert.assertEquals; |
| 4 | |
| 5 | import java.io.File; |
| 6 | import java.io.IOException; |
| 7 | import java.io.InputStream; |
| 8 | import java.util.Properties; |
| 9 | |
| 10 | import org.apache.lucene.index.Term; |
| 11 | import org.apache.lucene.search.spans.SpanQuery; |
| 12 | import org.apache.lucene.search.spans.SpanTermQuery; |
| 13 | import org.apache.lucene.store.MMapDirectory; |
| 14 | import org.junit.Test; |
| 15 | |
| 16 | import de.ids_mannheim.korap.*; |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 17 | import de.ids_mannheim.korap.response.Result; |
| Nils Diewald | 8904c1d | 2015-02-26 16:13:18 +0000 | [diff] [blame] | 18 | import de.ids_mannheim.korap.query.QueryBuilder; |
| Nils Diewald | d732e54 | 2014-11-12 17:54:02 +0000 | [diff] [blame] | 19 | import de.ids_mannheim.korap.util.QueryException; |
| Akron | 700c1eb | 2015-09-25 16:57:30 +0200 | [diff] [blame] | 20 | import java.nio.file.Paths; |
| Nils Diewald | d732e54 | 2014-11-12 17:54:02 +0000 | [diff] [blame] | 21 | |
| 22 | public class TestRealIndex { |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 23 | KrillIndex ki; |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 24 | Result kr; |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 25 | Krill ks; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 26 | |
| 27 | |
| 28 | public TestRealIndex () throws IOException { |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 29 | InputStream is = getClass().getResourceAsStream("/server.properties"); |
| 30 | Properties prop = new Properties(); |
| 31 | prop.load(is); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 32 | |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 33 | String indexPath = prop.getProperty("lucene.indexDir"); |
| 34 | System.err.println(indexPath); |
| Akron | 700c1eb | 2015-09-25 16:57:30 +0200 | [diff] [blame] | 35 | MMapDirectory md = new MMapDirectory(Paths.get(indexPath)); |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 36 | ki = new KrillIndex(md); |
| Nils Diewald | d732e54 | 2014-11-12 17:54:02 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 39 | |
| Nils Diewald | d732e54 | 2014-11-12 17:54:02 +0000 | [diff] [blame] | 40 | @Test |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 41 | public void testCase1 () throws IOException, QueryException { |
| Nils Diewald | 8904c1d | 2015-02-26 16:13:18 +0000 | [diff] [blame] | 42 | QueryBuilder kq = new QueryBuilder("tokens"); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 43 | ks = new Krill(kq |
| Akron | 567b6fe | 2018-12-06 15:06:58 +0100 | [diff] [blame] | 44 | .contains(kq.tag("base/s:s"), |
| Akron | 4f52a63 | 2018-02-09 19:02:40 +0100 | [diff] [blame] | 45 | kq.seq(kq.re("s:.*")).append(kq.nr(kq.re("s:.*")))) |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 46 | .toQuery()); |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 47 | ks.getMeta().setTimeOut(10000); |
| 48 | kr = ks.apply(ki); |
| 49 | System.err.println(kr.toJsonString()); |
| 50 | assertEquals(8, kr.getTotalResults()); |
| Nils Diewald | d732e54 | 2014-11-12 17:54:02 +0000 | [diff] [blame] | 51 | }; |
| 52 | } |