Search in sources :

Example 76 with Item

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

the class QueryCombinator method addAndItems.

private void addAndItems(Query query, Iterable<QueryPart> pieces, Execution.Context context) {
    IndexFacts indexFacts = context.getIndexFacts();
    IndexFacts.Session session = indexFacts.newSession(query);
    Set<String> usedSources = new HashSet<>(session.documentTypes());
    Language language = query.getModel().getParsingLanguage();
    for (QueryPart part : pieces) {
        String defaultIndex;
        Item item = null;
        Index index = session.getIndex(part.defaultIndex);
        if (index == Index.nullIndex) {
            defaultIndex = null;
        } else {
            defaultIndex = part.defaultIndex;
        }
        try {
            CustomParser parser = (CustomParser) ParserFactory.newInstance(query.getModel().getType(), ParserEnvironment.fromExecutionContext(context));
            item = parser.parse(part.query, null, language, usedSources, indexFacts, defaultIndex);
        } catch (RuntimeException e) {
            String err = Exceptions.toMessageString(e);
            query.trace("Query parser threw an exception: " + err, true, 1);
            getLogger().log(LogLevel.WARNING, "Query parser threw exception searcher QueryCombinator for " + query.getHttpRequest().toString() + ", query part " + part.query + ": " + err);
        }
        if (item == null) {
            continue;
        }
        if (defaultIndex == null) {
            assignDefaultIndex(item, part.defaultIndex);
        }
        addAndItem(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) IndexFacts(com.yahoo.prelude.IndexFacts) Language(com.yahoo.language.Language) Index(com.yahoo.prelude.Index) CustomParser(com.yahoo.prelude.query.parser.CustomParser) HashSet(java.util.HashSet)

Example 77 with Item

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

the class RangeQueryOptimizer method optimizeAnd.

private boolean optimizeAnd(AndItem and, IndexFacts.Session indexFacts) {
    // Find consolidated ranges by collecting a list of compatible ranges
    List<FieldRange> fieldRanges = null;
    for (Iterator<Item> i = and.getItemIterator(); i.hasNext(); ) {
        Item item = i.next();
        if (!(item instanceof IntItem))
            continue;
        IntItem intItem = (IntItem) item;
        // each such op gets a different partial set: Cannot be optimized
        if (intItem.getHitLimit() != 0)
            continue;
        // don't optimize searches for single numbers
        if (intItem.getFromLimit().equals(intItem.getToLimit()))
            continue;
        // May match different values in each range
        if (indexFacts.getIndex(intItem.getIndexName()).isMultivalue())
            continue;
        if (fieldRanges == null)
            fieldRanges = new ArrayList<>();
        Optional<FieldRange> compatibleRange = findCompatibleRange(intItem, fieldRanges);
        if (compatibleRange.isPresent())
            compatibleRange.get().addRange(intItem);
        else
            fieldRanges.add(new FieldRange(intItem));
        i.remove();
    }
    // Add consolidated ranges
    if (fieldRanges == null)
        return false;
    boolean optimized = false;
    for (FieldRange fieldRange : fieldRanges) {
        and.addItem(fieldRange.toItem());
        optimized |= fieldRange.isOptimization();
    }
    return optimized;
}
Also used : FalseItem(com.yahoo.prelude.query.FalseItem) IntItem(com.yahoo.prelude.query.IntItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) IntItem(com.yahoo.prelude.query.IntItem) ArrayList(java.util.ArrayList)

Example 78 with Item

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

the class CompositeConverter method itemToForm.

@Override
public DispatchForm itemToForm(Item item, ItemIdMapper itemIdMapper) {
    CompositeItem compositeItem = (CompositeItem) item;
    DispatchForm form = new DispatchForm(getFormName(item));
    for (ListIterator<Item> i = compositeItem.getItemIterator(); i.hasNext(); ) {
        form.addChild(i.next());
    }
    ItemInitializer.initializeForm(form, item, itemIdMapper);
    return form;
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Item(com.yahoo.prelude.query.Item) CompositeItem(com.yahoo.prelude.query.CompositeItem) DispatchForm(com.yahoo.search.query.textserialize.serializer.DispatchForm)

Example 79 with Item

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

the class YqlParser method leafStyleSettings.

@NonNull
private <T extends TaggableItem> T leafStyleSettings(OperatorNode<?> ast, @NonNull T out) {
    {
        Map<?, ?> connectivity = getAnnotation(ast, CONNECTIVITY, Map.class, null, "connectivity settings");
        if (connectivity != null) {
            connectedItems.add(new ConnectedItem(out, getMapValue(CONNECTIVITY, connectivity, CONNECTION_ID, Integer.class), getMapValue(CONNECTIVITY, connectivity, CONNECTION_WEIGHT, Number.class).doubleValue()));
        }
        Number significance = getAnnotation(ast, SIGNIFICANCE, Number.class, null, "term significance");
        if (significance != null) {
            out.setSignificance(significance.doubleValue());
        }
        Integer uniqueId = getAnnotation(ast, UNIQUE_ID, Integer.class, null, "term ID", false);
        if (uniqueId != null) {
            out.setUniqueID(uniqueId);
            identifiedItems.put(uniqueId, out);
        }
    }
    {
        Item leaf = (Item) out;
        Map<?, ?> itemAnnotations = getAnnotation(ast, ANNOTATIONS, Map.class, Collections.emptyMap(), "item annotation map");
        for (Map.Entry<?, ?> entry : itemAnnotations.entrySet()) {
            Preconditions.checkArgument(entry.getKey() instanceof String, "Expected String annotation key, got %s.", entry.getKey().getClass());
            Preconditions.checkArgument(entry.getValue() instanceof String, "Expected String annotation value, got %s.", entry.getValue().getClass());
            leaf.addAnnotation((String) entry.getKey(), entry.getValue());
        }
        Boolean filter = getAnnotation(ast, FILTER, Boolean.class, null, FILTER_DESCRIPTION);
        if (filter != null) {
            leaf.setFilter(filter);
        }
        Boolean isRanked = getAnnotation(ast, RANKED, Boolean.class, null, RANKED_DESCRIPTION);
        if (isRanked != null) {
            leaf.setRanked(isRanked);
        }
        String label = getAnnotation(ast, LABEL, String.class, null, "item label");
        if (label != null) {
            leaf.setLabel(label);
        }
        Integer weight = getAnnotation(ast, WEIGHT, Integer.class, null, "term weight for ranking");
        if (weight != null) {
            leaf.setWeight(weight);
        }
    }
    if (out instanceof IntItem) {
        IntItem number = (IntItem) out;
        Integer hitLimit = getCappedRangeSearchParameter(ast);
        if (hitLimit != null) {
            number.setHitLimit(hitLimit);
        }
    }
    return out;
}
Also used : BigInteger(java.math.BigInteger) 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) IntItem(com.yahoo.prelude.query.IntItem) Map(java.util.Map) LazyMap(com.yahoo.collections.LazyMap) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 80 with Item

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

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