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;
}
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;
}
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());
}
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"));
}
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());
}
Aggregations