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