Search in sources :

Example 1 with Parsable

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

the class GroupingParserTestCase method assertYqlParsable.

private static void assertYqlParsable(String request, String... expectedOperations) {
    YqlParser parser = new YqlParser(new ParserEnvironment());
    parser.parse(new Parsable().setQuery("select foo from bar where baz contains 'baz' | " + request + ";"));
    List<VespaGroupingStep> steps = parser.getGroupingSteps();
    List<String> actual = new ArrayList<>(steps.size());
    for (VespaGroupingStep step : steps) {
        actual.add(step.getOperation().toString());
    }
    if (expectedOperations.length > 0) {
        assertEquals(Arrays.asList(expectedOperations), actual);
    }
}
Also used : YqlParser(com.yahoo.search.yql.YqlParser) VespaGroupingStep(com.yahoo.search.yql.VespaGroupingStep) ArrayList(java.util.ArrayList) Parsable(com.yahoo.search.query.parser.Parsable) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment)

Example 2 with Parsable

use of com.yahoo.search.query.parser.Parsable 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 Parsable

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

the class ValidatePredicateSearcherTestCase method doSearch.

private static Result doSearch(ValidatePredicateSearcher searcher, String yqlQuery, String command) {
    QueryTree queryTree = new YqlParser(new ParserEnvironment()).parse(new Parsable().setQuery(yqlQuery));
    Query query = new Query();
    query.getModel().getQueryTree().setRoot(queryTree.getRoot());
    TreeMap<String, List<String>> masterClusters = new TreeMap<>();
    masterClusters.put("cluster", Arrays.asList("document"));
    SearchDefinition searchDefinition = new SearchDefinition("document");
    Index index = new Index("predicate_field");
    index.addCommand(command);
    searchDefinition.addIndex(index);
    Map<String, SearchDefinition> searchDefinitionMap = new HashMap<>();
    searchDefinitionMap.put("document", searchDefinition);
    IndexFacts indexFacts = new IndexFacts(new IndexModel(masterClusters, searchDefinitionMap, searchDefinition));
    Execution.Context context = new Execution.Context(null, indexFacts, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics());
    return new Execution(searcher, context).search(query);
}
Also used : Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) Parsable(com.yahoo.search.query.parser.Parsable) Index(com.yahoo.prelude.Index) IndexModel(com.yahoo.prelude.IndexModel) SearchDefinition(com.yahoo.prelude.SearchDefinition) SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) YqlParser(com.yahoo.search.yql.YqlParser) Execution(com.yahoo.search.searchchain.Execution) QueryTree(com.yahoo.search.query.QueryTree) RendererRegistry(com.yahoo.search.rendering.RendererRegistry) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment)

Example 4 with Parsable

use of com.yahoo.search.query.parser.Parsable 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 5 with Parsable

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

the class VespaSerializerTestCase method parseAndConfirm.

private void parseAndConfirm(String expected, String toParse) {
    QueryTree item = parser.parse(new Parsable().setQuery(SELECT + toParse + ";"));
    // System.out.println(item.toString());
    String q = VespaSerializer.serialize(item.getRoot());
    assertEquals(expected, q);
}
Also used : QueryTree(com.yahoo.search.query.QueryTree) Parsable(com.yahoo.search.query.parser.Parsable)

Aggregations

Parsable (com.yahoo.search.query.parser.Parsable)9 ParserEnvironment (com.yahoo.search.query.parser.ParserEnvironment)7 Parser (com.yahoo.search.query.parser.Parser)5 Item (com.yahoo.prelude.query.Item)4 NullItem (com.yahoo.prelude.query.NullItem)4 IndexFacts (com.yahoo.prelude.IndexFacts)3 Query (com.yahoo.search.Query)3 QueryTree (com.yahoo.search.query.QueryTree)3 IndexModel (com.yahoo.prelude.IndexModel)2 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 Execution (com.yahoo.search.searchchain.Execution)2 Chain (com.yahoo.component.chain.Chain)1 SimpleLinguistics (com.yahoo.language.simple.SimpleLinguistics)1 Index (com.yahoo.prelude.Index)1 SearchDefinition (com.yahoo.prelude.SearchDefinition)1 AndSegmentItem (com.yahoo.prelude.query.AndSegmentItem)1 DotProductItem (com.yahoo.prelude.query.DotProductItem)1