Search in sources :

Example 1 with QuerySerializer

use of de.ids_mannheim.korap.query.serialize.QuerySerializer 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 QuerySerializer

use of de.ids_mannheim.korap.query.serialize.QuerySerializer 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 QuerySerializer

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

the class ServiceInfo method load.

private void load() {
    Properties props = new Properties();
    try {
        InputStream stream = getStream();
        props.load(stream);
        stream.close();
        this.version = (String) props.get("kustvakt.version");
        this.name = (String) props.get("kustvakt.name");
        this.config = (String) props.get("kustvakt.properties");
        this.logger = (String) props.get("kustvakt.logging");
        this.cacheable = Boolean.valueOf((String) props.get("kustvakt.cache"));
        this.cache_store = (String) props.get("kustvakt.cache_store");
        this.krillVersion = (String) props.get("krill.version");
        QuerySerializer s = new QuerySerializer();
        this.koralVersion = s.getVersion();
    } catch (IOException e) {
        this.version = UNKNOWN;
        this.name = UNKNOWN;
        this.logger = UNKNOWN;
        this.config = UNKNOWN;
        this.cacheable = false;
        this.cache_store = UNKNOWN;
        this.koralVersion = UNKNOWN;
        this.krillVersion = UNKNOWN;
    }
}
Also used : InputStream(java.io.InputStream) QuerySerializer(de.ids_mannheim.korap.query.serialize.QuerySerializer) IOException(java.io.IOException) Properties(java.util.Properties)

Example 4 with QuerySerializer

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

the class QueryService method serializeCorpusQuery.

private String serializeCorpusQuery(String corpusQuery) throws KustvaktException {
    QuerySerializer serializer = new QuerySerializer();
    serializer.setCollection(corpusQuery);
    String koralQuery;
    try {
        koralQuery = serializer.convertCollectionToJson();
    } catch (JsonProcessingException e) {
        throw new KustvaktException(StatusCodes.INVALID_ARGUMENT, "Invalid argument: " + corpusQuery, corpusQuery);
    }
    if (DEBUG) {
        jlog.debug(koralQuery);
    }
    return koralQuery;
}
Also used : KustvaktException(de.ids_mannheim.korap.exceptions.KustvaktException) QuerySerializer(de.ids_mannheim.korap.query.serialize.QuerySerializer) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 5 with QuerySerializer

use of de.ids_mannheim.korap.query.serialize.QuerySerializer 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)

Aggregations

QuerySerializer (de.ids_mannheim.korap.query.serialize.QuerySerializer)42 Test (org.junit.Test)36 JsonNode (com.fasterxml.jackson.databind.JsonNode)34 SpringJerseyTest (de.ids_mannheim.korap.config.SpringJerseyTest)26 KorAPUser (de.ids_mannheim.korap.user.KorAPUser)9 KoralCollectionQueryBuilder (de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder)9 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 MetaQueryBuilder (de.ids_mannheim.korap.query.serialize.MetaQueryBuilder)4 Ignore (org.junit.Ignore)3 KustvaktException (de.ids_mannheim.korap.exceptions.KustvaktException)2 IdWriter (de.ids_mannheim.korap.rewrite.IdWriter)2 RewriteHandler (de.ids_mannheim.korap.rewrite.RewriteHandler)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 KustvaktConfiguration (de.ids_mannheim.korap.config.KustvaktConfiguration)1 LiteJerseyTest (de.ids_mannheim.korap.config.LiteJerseyTest)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 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1