Search in sources :

Example 6 with NearItem

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

the class YqlParser method instantiateNearItem.

@NonNull
private Item instantiateNearItem(String field, OperatorNode<ExpressionOperator> ast) {
    assertHasFunctionName(ast, NEAR);
    NearItem near = new NearItem();
    near.setIndexName(field);
    for (OperatorNode<ExpressionOperator> word : ast.<List<OperatorNode<ExpressionOperator>>>getArgument(1)) {
        near.addItem(instantiateWordItem(field, word, near.getClass()));
    }
    Integer distance = getAnnotation(ast, DISTANCE, Integer.class, null, "term distance for NEAR operator");
    if (distance != null) {
        near.setDistance(distance);
    }
    return near;
}
Also used : BigInteger(java.math.BigInteger) List(java.util.List) ArrayList(java.util.ArrayList) ONearItem(com.yahoo.prelude.query.ONearItem) NearItem(com.yahoo.prelude.query.NearItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 7 with NearItem

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

the class ItemEncodingTestCase method testONearItemEncoding.

@Test
public void testONearItemEncoding() {
    WordItem a = new WordItem("a");
    WordItem b = new WordItem("b");
    NearItem onear = new ONearItem(7);
    onear.addItem(a);
    onear.addItem(b);
    ByteBuffer buffer = ByteBuffer.allocate(128);
    int count = onear.encode(buffer);
    buffer.flip();
    assertEquals("Serialization count", 3, count);
    assertType(buffer, 12, 0);
    assertEquals("Near arity", 2, buffer.get());
    assertEquals("Limit", 7, buffer.get());
    assertWord(buffer, "a");
    assertWord(buffer, "b");
}
Also used : ONearItem(com.yahoo.prelude.query.ONearItem) MarkerWordItem(com.yahoo.prelude.query.MarkerWordItem) WordItem(com.yahoo.prelude.query.WordItem) ONearItem(com.yahoo.prelude.query.ONearItem) NearItem(com.yahoo.prelude.query.NearItem) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

NearItem (com.yahoo.prelude.query.NearItem)7 ONearItem (com.yahoo.prelude.query.ONearItem)4 WordItem (com.yahoo.prelude.query.WordItem)3 Test (org.junit.Test)3 MarkerWordItem (com.yahoo.prelude.query.MarkerWordItem)2 NonNull (edu.umd.cs.findbugs.annotations.NonNull)2 BigInteger (java.math.BigInteger)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DispatchForm (com.yahoo.search.query.textserialize.serializer.DispatchForm)1