Search in sources :

Example 1 with ParserEnvironment

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

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

the class VespaSerializerTestCase method setUp.

@Before
public void setUp() throws Exception {
    ParserEnvironment env = new ParserEnvironment();
    parser = new YqlParser(env);
}
Also used : ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment) Before(org.junit.Before)

Example 3 with ParserEnvironment

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

the class MinimalQueryInserter method search.

@Override
public Result search(Query query, Execution execution) {
    if (query.properties().get(YQL) == null) {
        return execution.search(query);
    }
    ParserEnvironment env = ParserEnvironment.fromExecutionContext(execution.context());
    YqlParser parser = (YqlParser) ParserFactory.newInstance(Query.Type.YQL, env);
    parser.setQueryParser(false);
    parser.setUserQuery(query);
    QueryTree newTree;
    try {
        newTree = parser.parse(Parsable.fromQueryModel(query.getModel()).setQuery(query.properties().getString(YQL)));
    } catch (RuntimeException e) {
        return new Result(query, ErrorMessage.createInvalidQueryParameter("Could not instantiate query from YQL", e));
    }
    if (parser.getOffset() != null) {
        int maxHits = query.properties().getInteger(MAX_HITS);
        int maxOffset = query.properties().getInteger(MAX_OFFSET);
        if (parser.getOffset() > maxOffset) {
            return new Result(query, ErrorMessage.createInvalidQueryParameter("Requested offset " + parser.getOffset() + ", but the max offset allowed is " + maxOffset + "."));
        }
        if (parser.getHits() > maxHits) {
            return new Result(query, ErrorMessage.createInvalidQueryParameter("Requested " + parser.getHits() + " hits returned, but max hits allowed is " + maxHits + "."));
        }
    }
    query.getModel().getQueryTree().setRoot(newTree.getRoot());
    query.getPresentation().getSummaryFields().addAll(parser.getYqlSummaryFields());
    for (VespaGroupingStep step : parser.getGroupingSteps()) {
        GroupingRequest.newInstance(query).setRootOperation(step.getOperation()).continuations().addAll(step.continuations());
    }
    if (parser.getYqlSources().size() == 0) {
        query.getModel().getSources().clear();
    } else {
        query.getModel().getSources().addAll(parser.getYqlSources());
    }
    if (parser.getOffset() != null) {
        query.setOffset(parser.getOffset());
        query.setHits(parser.getHits());
    }
    if (parser.getTimeout() != null) {
        query.setTimeout(parser.getTimeout().longValue());
    }
    if (parser.getSorting() != null) {
        query.getRanking().setSorting(parser.getSorting());
    }
    query.trace("YQL+ query parsed", true, 2);
    return execution.search(query);
}
Also used : QueryTree(com.yahoo.search.query.QueryTree) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment) Result(com.yahoo.search.Result)

Example 4 with ParserEnvironment

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

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

Aggregations

ParserEnvironment (com.yahoo.search.query.parser.ParserEnvironment)10 Parsable (com.yahoo.search.query.parser.Parsable)7 Parser (com.yahoo.search.query.parser.Parser)4 IndexFacts (com.yahoo.prelude.IndexFacts)3 Item (com.yahoo.prelude.query.Item)3 NullItem (com.yahoo.prelude.query.NullItem)3 QueryTree (com.yahoo.search.query.QueryTree)3 IndexModel (com.yahoo.prelude.IndexModel)2 Query (com.yahoo.search.Query)2 Execution (com.yahoo.search.searchchain.Execution)2 YqlParser (com.yahoo.search.yql.YqlParser)2 Before (org.junit.Before)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 AndItem (com.yahoo.prelude.query.AndItem)1 CompositeItem (com.yahoo.prelude.query.CompositeItem)1 IndexedItem (com.yahoo.prelude.query.IndexedItem)1 PhraseItem (com.yahoo.prelude.query.PhraseItem)1