Search in sources :

Example 46 with Item

use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.

the class ParseTestCase method testPrefixExtraStar.

/**
 * Extra star is ignored
 */
@Test
public void testPrefixExtraStar() {
    Item root = tester.assertParsed("prefix*", "prefix**", Query.Type.ANY);
    assertTrue(root instanceof PrefixItem);
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Test(org.junit.Test)

Example 47 with Item

use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.

the class LegacyCombinator method addRankItems.

private void addRankItems(Language language, Query query, Set<QueryPart> pieces, IndexFacts.Session session, Execution.Context context) {
    for (QueryPart part : pieces) {
        if (part.operator != Combinator.PREFERRED)
            continue;
        String defaultIndex = defaultIndex(session, part);
        Item item = parse(language, query, part, defaultIndex, context);
        if (item == null)
            continue;
        setDefaultIndex(part, defaultIndex, item);
        addRankItem(query.getModel().getQueryTree(), item);
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) IndexedItem(com.yahoo.prelude.query.IndexedItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) NotItem(com.yahoo.prelude.query.NotItem)

Example 48 with Item

use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.

the class QueryTreeUtil method andQueryItemWithRoot.

public static void andQueryItemWithRoot(QueryTree tree, Item item) {
    if (tree.isEmpty()) {
        tree.setRoot(item);
    } else {
        Item oldRoot = tree.getRoot();
        if (oldRoot.getClass() == AndItem.class) {
            ((AndItem) oldRoot).addItem(item);
        } else {
            AndItem newRoot = new AndItem();
            newRoot.addItem(oldRoot);
            newRoot.addItem(item);
            tree.setRoot(newRoot);
        }
    }
}
Also used : Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) AndItem(com.yahoo.prelude.query.AndItem)

Example 49 with Item

use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.

the class GroupingExecutor method performSearch.

/**
 * Performs the actual search passes to complete all the given {@link Grouping} requests. This method uses the
 * grouping map argument as both an input and an output variable, as the contained {@link Grouping} objects are
 * updates as results arrive from the back end.
 *
 * @param query       The query to execute.
 * @param execution   The execution context used to run the queries.
 * @param groupingMap The map of grouping requests to perform.
 * @return The search result to pass back from this searcher.
 */
private Result performSearch(Query query, Execution execution, Map<Integer, Grouping> groupingMap) {
    // Determine how many passes to perform.
    int lastPass = 0;
    for (Grouping grouping : groupingMap.values()) {
        if (!grouping.useSinglePass()) {
            lastPass = Math.max(lastPass, grouping.getLevels().size());
        }
    }
    // Perform multi-pass query to complete all grouping requests.
    Item origRoot = query.getModel().getQueryTree().getRoot();
    int prePassErrors = query.errors().size();
    Result ret = null;
    Item baseRoot = origRoot;
    if (lastPass > 0) {
        baseRoot = origRoot.clone();
    }
    if (query.isTraceable(3) && query.getGroupingSessionCache()) {
        query.trace("Grouping in " + (lastPass + 1) + " passes. SessionId='" + query.getSessionId(true) + "'.", 3);
    }
    for (int pass = 0; pass <= lastPass; ++pass) {
        boolean firstPass = (pass == 0);
        List<Grouping> passList = getGroupingListForPassN(groupingMap, pass);
        if (passList.isEmpty()) {
            throw new RuntimeException("No grouping request for pass " + pass + ", bug!");
        }
        if (log.isLoggable(LogLevel.DEBUG)) {
            for (Grouping grouping : passList) {
                log.log(LogLevel.DEBUG, "Pass(" + pass + "), Grouping(" + grouping.getId() + "): " + grouping);
            }
        }
        Item passRoot;
        if (firstPass) {
            // Use original query the first time.
            passRoot = origRoot;
        } else if (pass == lastPass) {
            // Has already been cloned once, use this for last pass.
            passRoot = baseRoot;
        } else {
            // noinspection ConstantConditions
            passRoot = baseRoot.clone();
        }
        if (query.isTraceable(4) && query.getGroupingSessionCache()) {
            query.trace("Grouping with session cache '" + query.getGroupingSessionCache() + "' enabled for pass #" + pass + ".", 4);
        }
        if (origRoot != passRoot) {
            query.getModel().getQueryTree().setRoot(passRoot);
        }
        setGroupingList(query, passList);
        Result passResult = execution.search(query);
        if (passResult.hits().getError() != null) {
            if (firstPass) {
                if (passResult.hits().getErrorHit().errors().size() > prePassErrors || passResult.hits().getErrorHit().errors().size() == 0) {
                    return passResult;
                }
            } else {
                return passResult;
            }
        }
        Map<Integer, Grouping> passGroupingMap = mergeGroupingResults(passResult);
        mergeGroupingMaps(groupingMap, passGroupingMap);
        if (firstPass) {
            ret = passResult;
        }
    }
    if (log.isLoggable(LogLevel.DEBUG)) {
        for (Grouping grouping : groupingMap.values()) {
            log.log(LogLevel.DEBUG, "Result Grouping(" + grouping.getId() + "): " + grouping);
        }
    }
    return ret;
}
Also used : Item(com.yahoo.prelude.query.Item) Grouping(com.yahoo.searchlib.aggregation.Grouping) Result(com.yahoo.search.Result)

Example 50 with Item

use of com.yahoo.prelude.query.Item 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)

Aggregations

Item (com.yahoo.prelude.query.Item)116 AndItem (com.yahoo.prelude.query.AndItem)85 CompositeItem (com.yahoo.prelude.query.CompositeItem)82 WordItem (com.yahoo.prelude.query.WordItem)73 PhraseItem (com.yahoo.prelude.query.PhraseItem)66 NotItem (com.yahoo.prelude.query.NotItem)62 RankItem (com.yahoo.prelude.query.RankItem)60 SubstringItem (com.yahoo.prelude.query.SubstringItem)60 Test (org.junit.Test)58 OrItem (com.yahoo.prelude.query.OrItem)57 PrefixItem (com.yahoo.prelude.query.PrefixItem)53 SuffixItem (com.yahoo.prelude.query.SuffixItem)53 IntItem (com.yahoo.prelude.query.IntItem)52 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)51 NullItem (com.yahoo.prelude.query.NullItem)24 Query (com.yahoo.search.Query)22 EquivItem (com.yahoo.prelude.query.EquivItem)14 NearItem (com.yahoo.prelude.query.NearItem)14 ExactStringItem (com.yahoo.prelude.query.ExactStringItem)12 IndexedItem (com.yahoo.prelude.query.IndexedItem)12