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