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