Search in sources :

Example 11 with IntItem

use of com.yahoo.prelude.query.IntItem 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 12 with IntItem

use of com.yahoo.prelude.query.IntItem 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 13 with IntItem

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

the class YqlParser method instantiateRangeItem.

@NonNull
private IntItem instantiateRangeItem(List<OperatorNode<ExpressionOperator>> args, OperatorNode<ExpressionOperator> spec) {
    Preconditions.checkArgument(args.size() == 3, "Expected 3 arguments, got %s.", args.size());
    Number lowerArg = getBound(args.get(1));
    Number upperArg = getBound(args.get(2));
    String bounds = getAnnotation(spec, BOUNDS, String.class, null, "whether bounds should be open or closed");
    // TODO: add support for implicit transforms
    if (bounds == null) {
        return new RangeItem(lowerArg, upperArg, getIndex(args.get(0)));
    } else {
        Limit from;
        Limit to;
        if (BOUNDS_OPEN.equals(bounds)) {
            from = new Limit(lowerArg, false);
            to = new Limit(upperArg, false);
        } else if (BOUNDS_LEFT_OPEN.equals(bounds)) {
            from = new Limit(lowerArg, false);
            to = new Limit(upperArg, true);
        } else if (BOUNDS_RIGHT_OPEN.equals(bounds)) {
            from = new Limit(lowerArg, true);
            to = new Limit(upperArg, false);
        } else {
            throw newUnexpectedArgumentException(bounds, BOUNDS_OPEN, BOUNDS_LEFT_OPEN, BOUNDS_RIGHT_OPEN);
        }
        return new IntItem(from, to, getIndex(args.get(0)));
    }
}
Also used : RangeItem(com.yahoo.prelude.query.RangeItem) IntItem(com.yahoo.prelude.query.IntItem) Limit(com.yahoo.prelude.query.Limit) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 14 with IntItem

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

the class YqlParser method buildGreaterThan.

@NonNull
private IntItem buildGreaterThan(OperatorNode<ExpressionOperator> ast) {
    IntItem number;
    if (isIndexOnLeftHandSide(ast)) {
        number = new IntItem(">" + fetchConditionWord(ast), fetchConditionIndex(ast));
        number = leafStyleSettings(ast.getArgument(1, OperatorNode.class), number);
    } else {
        number = new IntItem("<" + fetchConditionWord(ast), fetchConditionIndex(ast));
        number = leafStyleSettings(ast.getArgument(0, OperatorNode.class), number);
    }
    return number;
}
Also used : IntItem(com.yahoo.prelude.query.IntItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 15 with IntItem

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

the class RangeQueryOptimizerTestCase method testRangeOptimizingCarriesOverItemAttributesWhenOptimized.

@Test
public void testRangeOptimizingCarriesOverItemAttributesWhenOptimized() {
    Query query = new Query();
    AndItem root = new AndItem();
    query.getModel().getQueryTree().setRoot(root);
    Item intItem1 = new IntItem(">" + 15, "s");
    intItem1.setFilter(true);
    intItem1.setRanked(false);
    intItem1.setWeight(500);
    root.addItem(intItem1);
    Item intItem2 = new IntItem("<" + 30, "s");
    intItem2.setFilter(true);
    intItem2.setRanked(false);
    intItem2.setWeight(500);
    root.addItem(intItem2);
    assertOptimized("Optimized", "AND |s:<15;30>!500", query);
    IntItem transformedIntItem = (IntItem) ((AndItem) query.getModel().getQueryTree().getRoot()).getItem(0);
    assertTrue("Filter was carried over", transformedIntItem.isFilter());
    assertFalse("Ranked was carried over", transformedIntItem.isRanked());
    assertEquals("Weight was carried over", 500, transformedIntItem.getWeight());
}
Also used : IntItem(com.yahoo.prelude.query.IntItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) IntItem(com.yahoo.prelude.query.IntItem) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) Test(org.junit.Test)

Aggregations

IntItem (com.yahoo.prelude.query.IntItem)21 Test (org.junit.Test)12 AndItem (com.yahoo.prelude.query.AndItem)11 Item (com.yahoo.prelude.query.Item)9 NonNull (edu.umd.cs.findbugs.annotations.NonNull)7 CompositeItem (com.yahoo.prelude.query.CompositeItem)5 WordItem (com.yahoo.prelude.query.WordItem)5 Query (com.yahoo.search.Query)5 NotItem (com.yahoo.prelude.query.NotItem)4 OrItem (com.yahoo.prelude.query.OrItem)4 PhraseItem (com.yahoo.prelude.query.PhraseItem)4 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)4 PrefixItem (com.yahoo.prelude.query.PrefixItem)4 RankItem (com.yahoo.prelude.query.RankItem)4 SubstringItem (com.yahoo.prelude.query.SubstringItem)4 SuffixItem (com.yahoo.prelude.query.SuffixItem)4 RangeItem (com.yahoo.prelude.query.RangeItem)2 LazyMap (com.yahoo.collections.LazyMap)1 AndSegmentItem (com.yahoo.prelude.query.AndSegmentItem)1 DotProductItem (com.yahoo.prelude.query.DotProductItem)1