Search in sources :

Example 1 with MetaQueryBuilder

use of de.ids_mannheim.korap.query.serialize.MetaQueryBuilder in project Kustvakt by KorAP.

the class SearchService method search.

@SuppressWarnings("unchecked")
public String search(String engine, String username, HttpHeaders headers, String q, String ql, String v, List<String> cqList, String fields, String pipes, Integer pageIndex, Integer pageInteger, String ctx, Integer pageLength, Boolean cutoff, boolean accessRewriteDisabled, boolean showTokens) throws KustvaktException {
    if (pageInteger != null && pageInteger < 1) {
        throw new KustvaktException(StatusCodes.INVALID_ARGUMENT, "page must start from 1", "page");
    }
    String[] pipeArray = null;
    if (pipes != null && !pipes.isEmpty()) {
        pipeArray = pipes.split(",");
    }
    KustvaktConfiguration.BACKENDS eng = this.config.chooseBackend(engine);
    User user = createUser(username, headers);
    CorpusAccess corpusAccess = user.getCorpusAccess();
    // it is not needed because all metadata are public.
    if (accessRewriteDisabled) {
        corpusAccess = CorpusAccess.ALL;
        user.setCorpusAccess(CorpusAccess.ALL);
    }
    QuerySerializer serializer = new QuerySerializer();
    serializer.setQuery(q, ql, v);
    String cq = combineMultipleCorpusQuery(cqList);
    if (cq != null)
        serializer.setCollection(cq);
    List<String> fieldList = convertFieldsToList(fields);
    handleNonPublicFields(fieldList, accessRewriteDisabled, serializer);
    MetaQueryBuilder meta = createMetaQuery(pageIndex, pageInteger, ctx, pageLength, cutoff, corpusAccess, fieldList, accessRewriteDisabled, showTokens);
    serializer.setMeta(meta.raw());
    // - either query, corpus or meta
    if (serializer.hasErrors()) {
        throw new KustvaktException(serializer.toJSON());
    }
    String query = serializer.toJSON();
    if (accessRewriteDisabled && showTokens) {
        Notifications n = new Notifications();
        n.addWarning(StatusCodes.NOT_ALLOWED, "Tokens cannot be shown without access.");
        JsonNode warning = n.toJsonNode();
        query = addWarning(query, warning);
    }
    query = runPipes(query, pipeArray);
    query = this.rewriteHandler.processQuery(query, user);
    if (DEBUG) {
        jlog.debug("the serialized query " + query);
    }
    String result;
    if (eng.equals(KustvaktConfiguration.BACKENDS.NEO4J)) {
        result = searchNeo4J(query, pageLength, meta, false);
    } else {
        result = searchKrill.search(query);
    }
    // jlog.debug("Query result: " + result);
    return result;
}
Also used : KustvaktException(de.ids_mannheim.korap.exceptions.KustvaktException) KustvaktConfiguration(de.ids_mannheim.korap.config.KustvaktConfiguration) User(de.ids_mannheim.korap.user.User) CorpusAccess(de.ids_mannheim.korap.user.User.CorpusAccess) QuerySerializer(de.ids_mannheim.korap.query.serialize.QuerySerializer) MetaQueryBuilder(de.ids_mannheim.korap.query.serialize.MetaQueryBuilder) JsonNode(com.fasterxml.jackson.databind.JsonNode) Notifications(de.ids_mannheim.korap.response.Notifications)

Example 2 with MetaQueryBuilder

use of de.ids_mannheim.korap.query.serialize.MetaQueryBuilder in project Kustvakt by KorAP.

the class SearchService method serializeQuery.

@SuppressWarnings("unchecked")
public String serializeQuery(String q, String ql, String v, String cq, Integer pageIndex, Integer startPage, Integer pageLength, String context, Boolean cutoff, boolean accessRewriteDisabled) throws KustvaktException {
    QuerySerializer ss = new QuerySerializer().setQuery(q, ql, v);
    if (cq != null)
        ss.setCollection(cq);
    MetaQueryBuilder meta = new MetaQueryBuilder();
    if (pageIndex != null)
        meta.addEntry("startIndex", pageIndex);
    if (pageIndex == null && startPage != null)
        meta.addEntry("startPage", startPage);
    if (pageLength != null)
        meta.addEntry("count", pageLength);
    if (context != null)
        meta.setSpanContext(context);
    meta.addEntry("cutOff", cutoff);
    ss.setMeta(meta.raw());
    // return ss.toJSON();
    String query = ss.toJSON();
    query = rewriteHandler.processQuery(ss.toJSON(), null);
    return query;
}
Also used : QuerySerializer(de.ids_mannheim.korap.query.serialize.QuerySerializer) MetaQueryBuilder(de.ids_mannheim.korap.query.serialize.MetaQueryBuilder)

Example 3 with MetaQueryBuilder

use of de.ids_mannheim.korap.query.serialize.MetaQueryBuilder in project Kustvakt by KorAP.

the class SearchKrillTest method testTimeOut.

@Test
public void testTimeOut() throws KustvaktException {
    QuerySerializer s = new QuerySerializer();
    s.setQuery("[orth=der]", "poliqarp");
    // s.setQuery("node ->malt/d[func=/.*/] node", "annis");
    MetaQueryBuilder meta = new MetaQueryBuilder();
    meta.addEntry("timeout", 1);
    s.setMeta(meta);
    String query = s.toJSON();
    JsonNode node = JsonUtils.readTree(query);
    assertEquals(1, node.at("/meta/timeout").asInt());
    String result = krill.search(query);
    node = JsonUtils.readTree(result);
    assertEquals(true, node.at("/meta/timeExceeded").asBoolean());
}
Also used : QuerySerializer(de.ids_mannheim.korap.query.serialize.QuerySerializer) MetaQueryBuilder(de.ids_mannheim.korap.query.serialize.MetaQueryBuilder) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test) SpringJerseyTest(de.ids_mannheim.korap.config.SpringJerseyTest)

Example 4 with MetaQueryBuilder

use of de.ids_mannheim.korap.query.serialize.MetaQueryBuilder in project Kustvakt by KorAP.

the class MetaQueryBuilderTest method testSpanContext.

@Test
public void testSpanContext() {
    MetaQueryBuilder m = QueryBuilderUtil.defaultMetaBuilder(0, 1, 5, "sentence", false);
    Map<?, ?> map = m.raw();
    assertEquals("sentence", map.get("context"));
    assertEquals(1, map.get("startPage"));
    assertEquals(0, map.get("startIndex"));
    assertEquals(false, map.get("cutOff"));
}
Also used : MetaQueryBuilder(de.ids_mannheim.korap.query.serialize.MetaQueryBuilder) Test(org.junit.Test)

Example 5 with MetaQueryBuilder

use of de.ids_mannheim.korap.query.serialize.MetaQueryBuilder in project Kustvakt by KorAP.

the class SearchPublicMetadataTest method testSearchPostPublicMetadata.

// EM: The API is disabled
@Ignore
@Test
public void testSearchPostPublicMetadata() throws KustvaktException {
    QuerySerializer s = new QuerySerializer();
    s.setQuery("[orth=der]", "poliqarp");
    s.setCollection("corpusSigle=GOE");
    s.setQuery("Wasser", "poliqarp");
    MetaQueryBuilder meta = new MetaQueryBuilder();
    meta.addEntry("snippets", "true");
    s.setMeta(meta);
    ClientResponse response = resource().path(API_VERSION).path("search").post(ClientResponse.class, s.toJSON());
    assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
    String ent = response.getEntity(String.class);
    JsonNode node = JsonUtils.readTree(ent);
    assertEquals("availability(ALL)", node.at("/collection/rewrites/0/scope").asText());
    assertTrue(node.at("/matches/0/snippet").isMissingNode());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) QuerySerializer(de.ids_mannheim.korap.query.serialize.QuerySerializer) MetaQueryBuilder(de.ids_mannheim.korap.query.serialize.MetaQueryBuilder) JsonNode(com.fasterxml.jackson.databind.JsonNode) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringJerseyTest(de.ids_mannheim.korap.config.SpringJerseyTest)

Aggregations

MetaQueryBuilder (de.ids_mannheim.korap.query.serialize.MetaQueryBuilder)7 QuerySerializer (de.ids_mannheim.korap.query.serialize.QuerySerializer)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Test (org.junit.Test)3 SpringJerseyTest (de.ids_mannheim.korap.config.SpringJerseyTest)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 KustvaktConfiguration (de.ids_mannheim.korap.config.KustvaktConfiguration)1 KustvaktException (de.ids_mannheim.korap.exceptions.KustvaktException)1 Notifications (de.ids_mannheim.korap.response.Notifications)1 User (de.ids_mannheim.korap.user.User)1 CorpusAccess (de.ids_mannheim.korap.user.User.CorpusAccess)1 Ignore (org.junit.Ignore)1