Search in sources :

Example 1 with CustomParser

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;
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) CustomParser(com.yahoo.prelude.query.parser.CustomParser)

Example 2 with CustomParser

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;
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) IndexedItem(com.yahoo.prelude.query.IndexedItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) NotItem(com.yahoo.prelude.query.NotItem) CustomParser(com.yahoo.prelude.query.parser.CustomParser)

Example 3 with CustomParser

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);
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) IndexedItem(com.yahoo.prelude.query.IndexedItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) IndexFacts(com.yahoo.prelude.IndexFacts) Language(com.yahoo.language.Language) Index(com.yahoo.prelude.Index) CustomParser(com.yahoo.prelude.query.parser.CustomParser) HashSet(java.util.HashSet)

Aggregations

CustomParser (com.yahoo.prelude.query.parser.CustomParser)3 IndexFacts (com.yahoo.prelude.IndexFacts)2 AndItem (com.yahoo.prelude.query.AndItem)2 CompositeItem (com.yahoo.prelude.query.CompositeItem)2 IndexedItem (com.yahoo.prelude.query.IndexedItem)2 Item (com.yahoo.prelude.query.Item)2 NullItem (com.yahoo.prelude.query.NullItem)2 Language (com.yahoo.language.Language)1 Index (com.yahoo.prelude.Index)1 NotItem (com.yahoo.prelude.query.NotItem)1 RankItem (com.yahoo.prelude.query.RankItem)1 HashSet (java.util.HashSet)1