Search in sources :

Example 11 with PredicateQueryItem

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

the class YqlParser method buildPredicate.

@NonNull
private Item buildPredicate(OperatorNode<ExpressionOperator> ast) {
    List<OperatorNode<ExpressionOperator>> args = ast.getArgument(1);
    Preconditions.checkArgument(args.size() == 3, "Expected 3 arguments, got %s.", args.size());
    PredicateQueryItem item = new PredicateQueryItem();
    item.setIndexName(getIndex(args.get(0)));
    addFeatures(args.get(1), (key, value, subqueryBitmap) -> item.addFeature(key, (String) value, subqueryBitmap), PredicateQueryItem.ALL_SUB_QUERIES);
    addFeatures(args.get(2), (key, value, subqueryBitmap) -> {
        if (value instanceof Long) {
            item.addRangeFeature(key, (Long) value, subqueryBitmap);
        } else {
            item.addRangeFeature(key, (Integer) value, subqueryBitmap);
        }
    }, PredicateQueryItem.ALL_SUB_QUERIES);
    return leafStyleSettings(ast, item);
}
Also used : PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 12 with PredicateQueryItem

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

the class BooleanSearcherTestCase method requireThatAttributeMapToSingleFeature.

@Test
public void requireThatAttributeMapToSingleFeature() {
    PredicateQueryItem item = buildPredicateQueryItem("{gender:female}", null);
    assertEquals(1, item.getFeatures().size());
    assertEquals(0, item.getRangeFeatures().size());
    assertEquals("gender", item.getFeatures().iterator().next().getKey());
    assertEquals("female", item.getFeatures().iterator().next().getValue());
    assertEquals("PREDICATE_QUERY_ITEM gender=female", item.toString());
}
Also used : PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) Test(org.junit.Test)

Example 13 with PredicateQueryItem

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

the class BooleanSearcherTestCase method requireThatRangeAttributesMapToRangeTerm.

@Test
public void requireThatRangeAttributesMapToRangeTerm() {
    PredicateQueryItem item = buildPredicateQueryItem(null, "{age:25}");
    assertEquals(0, item.getFeatures().size());
    assertEquals(1, item.getRangeFeatures().size());
    assertEquals("PREDICATE_QUERY_ITEM age:25", item.toString());
    item = buildPredicateQueryItem(null, "{age:25:0x43, height:170:[2,3,4]}");
    assertEquals(0, item.getFeatures().size());
    assertEquals(2, item.getRangeFeatures().size());
}
Also used : PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) Test(org.junit.Test)

Example 14 with PredicateQueryItem

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

the class BooleanSearcherTestCase method buildPredicateQueryItem.

private PredicateQueryItem buildPredicateQueryItem(String attributes, String rangeAttributes) {
    Query q = buildQuery("predicate", attributes, rangeAttributes);
    Result r = exec.search(q);
    return (PredicateQueryItem) r.getQuery().getModel().getQueryTree().getRoot();
}
Also used : PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result)

Example 15 with PredicateQueryItem

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

the class BooleanAttributeParserTest method assertException.

private void assertException(String s) {
    try {
        PredicateQueryItem item = new PredicateQueryItem();
        new BooleanSearcher.PredicateValueAttributeParser(item).parse(s);
        fail("Expected an exception");
    } catch (IllegalArgumentException e) {
    }
}
Also used : PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem)

Aggregations

PredicateQueryItem (com.yahoo.prelude.query.PredicateQueryItem)17 Test (org.junit.Test)12 ByteBuffer (java.nio.ByteBuffer)2 Query (com.yahoo.search.Query)1 Result (com.yahoo.search.Result)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 BigInteger (java.math.BigInteger)1