Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 1 | import de.ids_mannheim.korap.KrillCollection; |
| 2 | import de.ids_mannheim.korap.config.BeanConfigTest; |
| 3 | import de.ids_mannheim.korap.exceptions.KustvaktException; |
| 4 | import de.ids_mannheim.korap.query.serialize.CollectionQueryProcessor; |
| 5 | import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder; |
| 6 | import de.ids_mannheim.korap.utils.JsonUtils; |
| 7 | import de.ids_mannheim.korap.web.SearchKrill; |
| 8 | import org.junit.AfterClass; |
| 9 | import org.junit.BeforeClass; |
| 10 | import org.junit.Test; |
| 11 | |
| 12 | import java.io.IOException; |
| 13 | |
| 14 | /** |
| 15 | * @author hanl |
| 16 | * @date 14/01/2016 |
| 17 | */ |
| 18 | public class LocalQueryTest extends BeanConfigTest { |
| 19 | |
| 20 | private static String index; |
| 21 | private static String qstring; |
| 22 | |
| 23 | |
| 24 | @BeforeClass |
| 25 | public static void setup () throws Exception { |
| 26 | qstring = "creationDate since 1786 & creationDate until 1788"; |
| 27 | // qstring = "creationDate since 1765 & creationDate until 1768"; |
| 28 | // qstring = "textType = Aphorismus"; |
| 29 | // qstring = "title ~ \"Werther\""; |
| 30 | } |
| 31 | |
| 32 | |
| 33 | @AfterClass |
| 34 | public static void drop () {} |
| 35 | |
| 36 | |
| 37 | @Test |
| 38 | public void testQuery () { |
| 39 | SearchKrill krill = new SearchKrill(index); |
| 40 | KoralCollectionQueryBuilder coll = new KoralCollectionQueryBuilder(); |
| 41 | coll.with(qstring); |
| 42 | String stats = krill.getStatistics(coll.toJSON()); |
| 43 | assert stats != null && !stats.isEmpty() && !stats.equals("null"); |
| 44 | } |
| 45 | |
| 46 | |
| 47 | @Test |
| 48 | public void testCollQuery () throws IOException { |
| 49 | CollectionQueryProcessor processor = new CollectionQueryProcessor(); |
| 50 | processor.process(qstring); |
| 51 | |
| 52 | String s = JsonUtils.toJSON(processor.getRequestMap()); |
| 53 | KrillCollection c = new KrillCollection(s); |
| 54 | c.setIndex(new SearchKrill(index).getIndex()); |
| 55 | long docs = c.numberOf("documents"); |
| 56 | assert docs > 0 && docs < 15; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | @Test |
| 61 | public void testCollQuery2 () throws IOException { |
| 62 | String query = "{\"@context\":\"http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld\",\"errors\":[],\"warnings\":[],\"messages\":[],\"collection\":{\"@type\":\"koral:docGroup\",\"operation\":\"operation:and\",\"operands\":[{\"@type\":\"koral:doc\",\"key\":\"creationDate\",\"type\":\"type:date\",\"value\":\"1786\",\"match\":\"match:geq\"},{\"@type\":\"koral:doc\",\"key\":\"creationDate\",\"type\":\"type:date\",\"value\":\"1788\",\"match\":\"match:leq\"}]},\"query\":{},\"meta\":{}}"; |
| 63 | KrillCollection c = new KrillCollection(query); |
| 64 | c.setIndex(new SearchKrill(index).getIndex()); |
| 65 | long sent = c.numberOf("base/sentences"); |
| 66 | long docs = c.numberOf("documents"); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | @Test |
| 71 | public void testQueryHash () {} |
| 72 | |
| 73 | |
| 74 | @Override |
| 75 | public void initMethod () throws KustvaktException { |
| 76 | helper().runBootInterfaces(); |
| 77 | index = helper().getContext().getConfiguration().getIndexDir(); |
| 78 | } |
| 79 | } |