use of com.yahoo.prelude.query.parser.CustomParser in project vespa by vespa-engine.
the class RewriterFeatures method convertStringToQTree.
/**
* Convert String to query tree
*
* @param stringToParse The string to be converted to a
* query tree
* @param query Query object from searcher
* @return Item The resulting query tree
*/
static Item convertStringToQTree(Query query, String stringToParse) {
RewriterUtils.log(logger, query, "Converting string [" + stringToParse + "] to query tree");
if (stringToParse == null) {
return new NullItem();
}
Model model = query.getModel();
CustomParser parser = (CustomParser) ParserFactory.newInstance(model.getType(), ParserEnvironment.fromExecutionContext(query.getModel().getExecution().context()));
IndexFacts indexFacts = new IndexFacts();
Item item = parser.parse(stringToParse, null, model.getParsingLanguage(), indexFacts.newSession(model.getSources(), model.getRestrict()), model.getDefaultIndex());
RewriterUtils.log(logger, query, "Converted string: [" + item.toString() + "]");
return item;
}
use of com.yahoo.prelude.query.parser.CustomParser in project vespa by vespa-engine.
the class LegacyCombinator method parse.
private Item parse(Language language, Query query, QueryPart part, String defaultIndex, Execution.Context context) {
Item item = null;
try {
CustomParser parser = (CustomParser) ParserFactory.newInstance(part.syntax, ParserEnvironment.fromExecutionContext(context));
item = parser.parse(part.query, null, language, query.getModel().getSources(), context.getIndexFacts(), defaultIndex);
} catch (RuntimeException e) {
String err = Exceptions.toMessageString(e);
query.trace("Query parser threw an exception: " + err, true, 1);
getLogger().log(LogLevel.WARNING, "Query parser threw exception in searcher LegacyCombinator for " + query.getHttpRequest().toString() + ", query part " + part.query + ": " + err);
}
return item;
}
use of com.yahoo.prelude.query.parser.CustomParser in project vespa by vespa-engine.
the class QueryCombinator method addAndItems.
private void addAndItems(Query query, Iterable<QueryPart> pieces, Execution.Context context) {
IndexFacts indexFacts = context.getIndexFacts();
IndexFacts.Session session = indexFacts.newSession(query);
Set<String> usedSources = new HashSet<>(session.documentTypes());
Language language = query.getModel().getParsingLanguage();
for (QueryPart part : pieces) {
String defaultIndex;
Item item = null;
Index index = session.getIndex(part.defaultIndex);
if (index == Index.nullIndex) {
defaultIndex = null;
} else {
defaultIndex = part.defaultIndex;
}
try {
CustomParser parser = (CustomParser) ParserFactory.newInstance(query.getModel().getType(), ParserEnvironment.fromExecutionContext(context));
item = parser.parse(part.query, null, language, usedSources, indexFacts, defaultIndex);
} catch (RuntimeException e) {
String err = Exceptions.toMessageString(e);
query.trace("Query parser threw an exception: " + err, true, 1);
getLogger().log(LogLevel.WARNING, "Query parser threw exception searcher QueryCombinator for " + query.getHttpRequest().toString() + ", query part " + part.query + ": " + err);
}
if (item == null) {
continue;
}
if (defaultIndex == null) {
assignDefaultIndex(item, part.defaultIndex);
}
addAndItem(query.getModel().getQueryTree(), item);
}
}
Aggregations