| 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; |
| 20 | |
| 21 | public class TestRealIndex { |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 22 | KrillIndex ki; |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 23 | Result kr; |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 24 | Krill ks; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 25 | |
| 26 | |
| 27 | public TestRealIndex () throws IOException { |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 28 | InputStream is = getClass().getResourceAsStream("/server.properties"); |
| 29 | Properties prop = new Properties(); |
| 30 | prop.load(is); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 31 | |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 32 | String indexPath = prop.getProperty("lucene.indexDir"); |
| 33 | System.err.println(indexPath); |
| 34 | MMapDirectory md = new MMapDirectory(new File(indexPath)); |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 35 | ki = new KrillIndex(md); |
| Nils Diewald | d732e54 | 2014-11-12 17:54:02 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 38 | |
| Nils Diewald | d732e54 | 2014-11-12 17:54:02 +0000 | [diff] [blame] | 39 | @Test |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 40 | public void testCase1 () throws IOException, QueryException { |
| Nils Diewald | 8904c1d | 2015-02-26 16:13:18 +0000 | [diff] [blame] | 41 | QueryBuilder kq = new QueryBuilder("tokens"); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 42 | ks = new Krill(kq.within(kq.tag("base/s:s"), |
| 43 | kq.seq(kq.re("s:.*")).append(kq._(kq.re("s:.*")))).toQuery()); |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 44 | ks.getMeta().setTimeOut(10000); |
| 45 | kr = ks.apply(ki); |
| 46 | System.err.println(kr.toJsonString()); |
| 47 | assertEquals(8, kr.getTotalResults()); |
| Nils Diewald | d732e54 | 2014-11-12 17:54:02 +0000 | [diff] [blame] | 48 | }; |
| 49 | } |