Search in sources :

Example 1 with NullItem

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);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) RecallSearcher(com.yahoo.prelude.querytransform.RecallSearcher) NullItem(com.yahoo.prelude.query.NullItem) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 2 with 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;
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) NullItem(com.yahoo.prelude.query.NullItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) TaggableItem(com.yahoo.prelude.query.TaggableItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) EquivItem(com.yahoo.prelude.query.EquivItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) ONearItem(com.yahoo.prelude.query.ONearItem) DotProductItem(com.yahoo.prelude.query.DotProductItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) IntItem(com.yahoo.prelude.query.IntItem) WandItem(com.yahoo.prelude.query.WandItem) RegExpItem(com.yahoo.prelude.query.RegExpItem) RangeItem(com.yahoo.prelude.query.RangeItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) Language(com.yahoo.language.Language) NullItem(com.yahoo.prelude.query.NullItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 3 with NullItem

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;
}
Also used : NullItem(com.yahoo.prelude.query.NullItem) Item(com.yahoo.prelude.query.Item) NullItem(com.yahoo.prelude.query.NullItem) QueryPacket(com.yahoo.fs4.QueryPacket) Result(com.yahoo.search.Result)

Example 4 with NullItem

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;
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) NullItem(com.yahoo.prelude.query.NullItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) TaggableItem(com.yahoo.prelude.query.TaggableItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) EquivItem(com.yahoo.prelude.query.EquivItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) ONearItem(com.yahoo.prelude.query.ONearItem) DotProductItem(com.yahoo.prelude.query.DotProductItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) IntItem(com.yahoo.prelude.query.IntItem) WandItem(com.yahoo.prelude.query.WandItem) RegExpItem(com.yahoo.prelude.query.RegExpItem) RangeItem(com.yahoo.prelude.query.RangeItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) Query(com.yahoo.search.Query) Parsable(com.yahoo.search.query.parser.Parsable) NullItem(com.yahoo.prelude.query.NullItem) Parser(com.yahoo.search.query.parser.Parser) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 5 with NullItem

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();
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Parsable(com.yahoo.search.query.parser.Parsable) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment) NullItem(com.yahoo.prelude.query.NullItem) Parser(com.yahoo.search.query.parser.Parser) AbstractParser(com.yahoo.prelude.query.parser.AbstractParser)

Aggregations

NullItem (com.yahoo.prelude.query.NullItem)7 Item (com.yahoo.prelude.query.Item)6 Parsable (com.yahoo.search.query.parser.Parsable)4 Parser (com.yahoo.search.query.parser.Parser)4 AndItem (com.yahoo.prelude.query.AndItem)3 CompositeItem (com.yahoo.prelude.query.CompositeItem)3 PhraseItem (com.yahoo.prelude.query.PhraseItem)3 WordItem (com.yahoo.prelude.query.WordItem)3 Query (com.yahoo.search.Query)3 ParserEnvironment (com.yahoo.search.query.parser.ParserEnvironment)3 AndSegmentItem (com.yahoo.prelude.query.AndSegmentItem)2 DotProductItem (com.yahoo.prelude.query.DotProductItem)2 EquivItem (com.yahoo.prelude.query.EquivItem)2 ExactStringItem (com.yahoo.prelude.query.ExactStringItem)2 IntItem (com.yahoo.prelude.query.IntItem)2 NearItem (com.yahoo.prelude.query.NearItem)2 NotItem (com.yahoo.prelude.query.NotItem)2 ONearItem (com.yahoo.prelude.query.ONearItem)2 OrItem (com.yahoo.prelude.query.OrItem)2 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)2