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);
}
}
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);
}
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);
}
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);
}
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();
}
Aggregations