Search in sources :

Example 6 with PredicateQueryItem

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

the class PredicateQueryItemTestCase method requireThatFeaturesCanBeAdded.

@Test
public void requireThatFeaturesCanBeAdded() {
    PredicateQueryItem item = new PredicateQueryItem();
    assertEquals(0, item.getFeatures().size());
    item.addFeature("foo", "bar");
    item.addFeature("foo", "baz", 0xffff);
    item.addFeature(new PredicateQueryItem.Entry("qux", "quux"));
    item.addFeature(new PredicateQueryItem.Entry("corge", "grault", 0xf00ba));
    assertEquals(4, item.getFeatures().size());
    Iterator<PredicateQueryItem.Entry> it = item.getFeatures().iterator();
    assertEquals(-1, it.next().getSubQueryBitmap());
    assertEquals(0xffffL, it.next().getSubQueryBitmap());
    assertEquals(-1, it.next().getSubQueryBitmap());
    assertEquals(0xf00baL, it.next().getSubQueryBitmap());
}
Also used : PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) Test(org.junit.Test)

Example 7 with PredicateQueryItem

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

the class BooleanSearcherTestCase method requireThatBooleanSearcherCanBuildPredicateQueryItem.

@Test
public void requireThatBooleanSearcherCanBuildPredicateQueryItem() {
    PredicateQueryItem root = buildPredicateQueryItem("{gender:female}", "{age:23:[2, 3, 5]}");
    Collection<PredicateQueryItem.Entry> features = root.getFeatures();
    assertEquals(1, features.size());
    PredicateQueryItem.Entry entry = (PredicateQueryItem.Entry) features.toArray()[0];
    assertEquals("gender", entry.getKey());
    assertEquals("female", entry.getValue());
    assertEquals(-1L, entry.getSubQueryBitmap());
    Collection<PredicateQueryItem.RangeEntry> rangeFeatures = root.getRangeFeatures();
    assertEquals(1, rangeFeatures.size());
    PredicateQueryItem.RangeEntry rangeEntry = (PredicateQueryItem.RangeEntry) rangeFeatures.toArray()[0];
    assertEquals("age", rangeEntry.getKey());
    assertEquals(23L, rangeEntry.getValue());
    assertEquals(44L, rangeEntry.getSubQueryBitmap());
}
Also used : PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) Test(org.junit.Test)

Example 8 with PredicateQueryItem

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

the class BooleanSearcherTestCase method requireThatAttributeListMapToMultipleFeatures.

@Test
public void requireThatAttributeListMapToMultipleFeatures() {
    PredicateQueryItem item = buildPredicateQueryItem("{gender:[female,male]}", null);
    assertEquals(2, item.getFeatures().size());
    assertEquals(0, item.getRangeFeatures().size());
    assertEquals("PREDICATE_QUERY_ITEM gender=female, gender=male", item.toString());
}
Also used : PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) Test(org.junit.Test)

Example 9 with PredicateQueryItem

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

the class BooleanSearcherTestCase method requireThatKeysAndValuesCanContainSpaces.

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

Example 10 with PredicateQueryItem

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

the class BooleanSearcher method addPredicateTerm.

// Adds a boolean term ANDed to the query, based on the supplied properties.
private void addPredicateTerm(Query query, String fieldName, String attributes, String rangeAttributes) {
    PredicateQueryItem item = new PredicateQueryItem();
    item.setIndexName(fieldName);
    new PredicateValueAttributeParser(item).parse(attributes);
    new PredicateRangeAttributeParser(item).parse(rangeAttributes);
    QueryTreeUtil.andQueryItemWithRoot(query, item);
}
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