use of com.yahoo.prelude.query.NullItem in project vespa by vespa-engine.
the class RecallSearcherTestCase method testIgnoreEmptyProperty.
@Test
public void testIgnoreEmptyProperty() {
RecallSearcher searcher = new RecallSearcher();
Query query = new Query();
Result result = new Execution(searcher, Execution.Context.createContextStub()).search(query);
assertNull(result.hits().getError());
assertTrue(query.getModel().getQueryTree().getRoot() instanceof NullItem);
}
use of com.yahoo.prelude.query.NullItem in project vespa by vespa-engine.
the class YqlParser method buildUserInput.
@NonNull
private Item buildUserInput(OperatorNode<ExpressionOperator> ast) {
// TODO add support for default arguments if property results in nothing
List<OperatorNode<ExpressionOperator>> args = ast.getArgument(1);
String wordData = getStringContents(args.get(0));
Boolean allowEmpty = getAnnotation(ast, USER_INPUT_ALLOW_EMPTY, Boolean.class, Boolean.FALSE, "flag for allowing NullItem to be returned");
if (allowEmpty && (wordData == null || wordData.isEmpty()))
return new NullItem();
String grammar = getAnnotation(ast, USER_INPUT_GRAMMAR, String.class, Query.Type.ALL.toString(), "grammar for handling user input");
String defaultIndex = getAnnotation(ast, USER_INPUT_DEFAULT_INDEX, String.class, "default", "default index for user input terms");
Language language = decideParsingLanguage(ast, wordData);
Item item;
if (USER_INPUT_RAW.equals(grammar)) {
item = instantiateWordItem(defaultIndex, wordData, ast, null, SegmentWhen.NEVER, true, language);
} else if (USER_INPUT_SEGMENT.equals(grammar)) {
item = instantiateWordItem(defaultIndex, wordData, ast, null, SegmentWhen.ALWAYS, false, language);
} else {
item = parseUserInput(grammar, defaultIndex, wordData, language, allowEmpty);
propagateUserInputAnnotations(ast, item);
}
return item;
}
use of com.yahoo.prelude.query.NullItem in project vespa by vespa-engine.
the class VespaBackEndSearcher method search.
public Result search(Query query, Execution execution) {
// query root should not be null here
Item root = query.getModel().getQueryTree().getRoot();
if (root == null || root instanceof NullItem) {
return new Result(query, ErrorMessage.createNullQuery(query.getHttpRequest().getUri().toString()));
}
if (wantsRPCSummaryFill(query) && summaryNeedsQuery(query)) {
return new Result(query, ErrorMessage.createInvalidQueryParameter("When using dispatch.summaries and your summary/rankprofile require the query, " + " you need to enable ranking.queryCache."));
}
QueryRewrite.optimizeByRestrict(query);
QueryRewrite.optimizeAndNot(query);
QueryRewrite.collapseSingleComposites(query);
root = query.getModel().getQueryTree().getRoot();
if (// root can become null after optimization
root == null || root instanceof NullItem)
return new Result(query);
resolveDocumentDatabase(query);
transformQuery(query);
traceQuery(name, "search", query, query.getOffset(), query.getHits(), 1, Optional.empty());
root = query.getModel().getQueryTree().getRoot();
if (// root can become null after resolving and transformation?
root == null || root instanceof NullItem)
return new Result(query);
QueryPacket queryPacket = QueryPacket.create(query);
int compressionLimit = query.properties().getInteger(PACKET_COMPRESSION_LIMIT, 0);
queryPacket.setCompressionLimit(compressionLimit);
if (compressionLimit != 0)
queryPacket.setCompressionType(query.properties().getString(PACKET_COMPRESSION_TYPE, "lz4"));
if (isLoggingFine())
getLogger().fine("made QueryPacket: " + queryPacket);
Result result = null;
CacheKey cacheKey = null;
if (cacheControl.useCache(query)) {
cacheKey = new CacheKey(queryPacket);
result = getCached(cacheKey, queryPacket.getQueryPacketData(), query);
}
if (result == null) {
result = doSearch2(query, queryPacket, cacheKey, execution);
if (isLoggingFine())
getLogger().fine("Result NOT retrieved from cache");
if (query.getTraceLevel() >= 1)
query.trace(getName() + " dispatch response: " + result, false, 1);
result.trace(getName());
}
return result;
}
use of com.yahoo.prelude.query.NullItem 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.prelude.query.NullItem 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();
}
Aggregations