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;
}
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;
}
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)));
}
}
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;
}
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());
}
Aggregations