Search in sources :

Example 1 with Parser

use of com.yahoo.search.query.parser.Parser in project vespa by vespa-engine.

the class Model method getQueryTree.

/**
 * Returns the query as an object structure.
 * This causes parsing of the query string if it has changed since this was last called
 * (i.e query parsing is lazy)
 */
public QueryTree getQueryTree() {
    if (queryTree == null) {
        Parser parser = ParserFactory.newInstance(type, ParserEnvironment.fromExecutionContext(execution.context()));
        queryTree = parser.parse(Parsable.fromQueryModel(this));
        if (parent.getTraceLevel() >= 2) {
            parent.trace("Query parsed to: " + parent.yqlRepresentation(), 2);
        }
    }
    return queryTree;
}
Also used : Parser(com.yahoo.search.query.parser.Parser)

Example 2 with Parser

use of com.yahoo.search.query.parser.Parser in project vespa by vespa-engine.

the class YqlParser method parseUserInput.

@NonNull
private Item parseUserInput(String grammar, String defaultIndex, String wordData, Language language, boolean allowNullItem) {
    Query.Type parseAs = Query.Type.getType(grammar);
    Parser parser = ParserFactory.newInstance(parseAs, environment);
    // perhaps not use already resolved doctypes, but respect source and restrict
    Item item = parser.parse(new Parsable().setQuery(wordData).addSources(docTypes).setLanguage(language).setDefaultIndexName(defaultIndex)).getRoot();
    // the null check should be unnecessary, but is there to avoid having to suppress null warnings
    if (!allowNullItem && (item == null || item instanceof NullItem))
        throw new IllegalArgumentException("Parsing '" + wordData + "' only resulted in NullItem.");
    if (// mark the language used, unless it's the default
    language != Language.ENGLISH)
        item.setLanguage(language);
    return item;
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) NullItem(com.yahoo.prelude.query.NullItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) TaggableItem(com.yahoo.prelude.query.TaggableItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) EquivItem(com.yahoo.prelude.query.EquivItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) ONearItem(com.yahoo.prelude.query.ONearItem) DotProductItem(com.yahoo.prelude.query.DotProductItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) IntItem(com.yahoo.prelude.query.IntItem) WandItem(com.yahoo.prelude.query.WandItem) RegExpItem(com.yahoo.prelude.query.RegExpItem) RangeItem(com.yahoo.prelude.query.RangeItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) Query(com.yahoo.search.Query) Parsable(com.yahoo.search.query.parser.Parsable) NullItem(com.yahoo.prelude.query.NullItem) Parser(com.yahoo.search.query.parser.Parser) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 3 with Parser

use of com.yahoo.search.query.parser.Parser in project vespa by vespa-engine.

the class RangeQueryOptimizerTestCase method parseQuery.

private Item parseQuery(String query) {
    IndexFacts indexFacts = new IndexFacts();
    Parser parser = ParserFactory.newInstance(Query.Type.ADVANCED, new ParserEnvironment().setIndexFacts(indexFacts).setLinguistics(linguistics));
    return parser.parse(new Parsable().setQuery(query)).getRoot();
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) Parsable(com.yahoo.search.query.parser.Parsable) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment) Parser(com.yahoo.search.query.parser.Parser)

Example 4 with Parser

use of com.yahoo.search.query.parser.Parser in project vespa by vespa-engine.

the class WashPhrasesTestCase method transformQuery.

private String transformQuery(String rawQuery) {
    Parser parser = ParserFactory.newInstance(Query.Type.ALL, new ParserEnvironment());
    Item root = parser.parse(new Parsable().setQuery(rawQuery)).getRoot();
    if (root instanceof NullItem) {
        return null;
    }
    return root.toString();
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Parsable(com.yahoo.search.query.parser.Parsable) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment) NullItem(com.yahoo.prelude.query.NullItem) Parser(com.yahoo.search.query.parser.Parser) AbstractParser(com.yahoo.prelude.query.parser.AbstractParser)

Example 5 with Parser

use of com.yahoo.search.query.parser.Parser in project vespa by vespa-engine.

the class CJKSearcherTestCase method assertTransformed.

private void assertTransformed(String queryString, String expected, Query.Type mode, Language actualLanguage, Language queryLanguage, Linguistics linguistics) {
    Parser parser = ParserFactory.newInstance(mode, new ParserEnvironment().setIndexFacts(indexFacts).setLinguistics(linguistics));
    Item root = parser.parse(new Parsable().setQuery(queryString).setLanguage(actualLanguage)).getRoot();
    assertFalse(root instanceof NullItem);
    Query query = new Query("?language=" + queryLanguage.languageCode());
    query.getModel().getQueryTree().setRoot(root);
    new Execution(new Chain<Searcher>(new CJKSearcher()), new Execution.Context(null, indexFacts, null, null, linguistics)).search(query);
    assertEquals(expected, query.getModel().getQueryTree().getRoot().toString());
}
Also used : NullItem(com.yahoo.prelude.query.NullItem) Item(com.yahoo.prelude.query.Item) Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Parsable(com.yahoo.search.query.parser.Parsable) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment) CJKSearcher(com.yahoo.prelude.querytransform.CJKSearcher) NullItem(com.yahoo.prelude.query.NullItem) Parser(com.yahoo.search.query.parser.Parser)

Aggregations

Parser (com.yahoo.search.query.parser.Parser)6 Parsable (com.yahoo.search.query.parser.Parsable)5 Item (com.yahoo.prelude.query.Item)4 NullItem (com.yahoo.prelude.query.NullItem)4 ParserEnvironment (com.yahoo.search.query.parser.ParserEnvironment)4 AndItem (com.yahoo.prelude.query.AndItem)2 CompositeItem (com.yahoo.prelude.query.CompositeItem)2 PhraseItem (com.yahoo.prelude.query.PhraseItem)2 WordItem (com.yahoo.prelude.query.WordItem)2 Query (com.yahoo.search.Query)2 Chain (com.yahoo.component.chain.Chain)1 IndexFacts (com.yahoo.prelude.IndexFacts)1 AndSegmentItem (com.yahoo.prelude.query.AndSegmentItem)1 DotProductItem (com.yahoo.prelude.query.DotProductItem)1 EquivItem (com.yahoo.prelude.query.EquivItem)1 ExactStringItem (com.yahoo.prelude.query.ExactStringItem)1 IntItem (com.yahoo.prelude.query.IntItem)1 NearItem (com.yahoo.prelude.query.NearItem)1 NotItem (com.yahoo.prelude.query.NotItem)1 ONearItem (com.yahoo.prelude.query.ONearItem)1