Search in sources :

Example 1 with NearItem

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

the class NearConverter method itemToForm.

@Override
public DispatchForm itemToForm(Item item, ItemIdMapper itemIdMapper) {
    DispatchForm dispatchForm = super.itemToForm(item, itemIdMapper);
    NearItem nearItem = (NearItem) item;
    dispatchForm.setProperty(distanceProperty, nearItem.getDistance());
    return dispatchForm;
}
Also used : DispatchForm(com.yahoo.search.query.textserialize.serializer.DispatchForm) NearItem(com.yahoo.prelude.query.NearItem)

Example 2 with NearItem

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

the class ItemEncodingTestCase method testNearItemEncoding.

@Test
public void testNearItemEncoding() {
    WordItem a = new WordItem("a");
    WordItem b = new WordItem("b");
    NearItem near = new NearItem(7);
    near.addItem(a);
    near.addItem(b);
    ByteBuffer buffer = ByteBuffer.allocate(128);
    int count = near.encode(buffer);
    buffer.flip();
    assertEquals("Serialization count", 3, count);
    assertType(buffer, 11, 0);
    assertEquals("Near arity", 2, buffer.get());
    assertEquals("Limit", 7, buffer.get());
    assertWord(buffer, "a");
    assertWord(buffer, "b");
}
Also used : 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)

Example 3 with NearItem

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

the class SerializeItemTestCase method serialize_near_item.

@Test
public void serialize_near_item() throws ParseException {
    int distance = 23;
    NearItem nearItem = new NearItem(distance);
    {
        nearItem.addItem(new WordItem("first"));
        nearItem.addItem(new WordItem("second"));
    }
    NearItem deSerialized = serializeThenParse(nearItem);
    assertThat(deSerialized.getDistance(), is(distance));
    assertThat(deSerialized.getItemCount(), is(2));
}
Also used : NearItem(com.yahoo.prelude.query.NearItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 4 with NearItem

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

the class NearConverter method formToItem.

@Override
public Object formToItem(String name, ItemArguments arguments, ItemContext itemContext) {
    NearItem nearItem = (NearItem) super.formToItem(name, arguments, itemContext);
    setDistance(nearItem, arguments);
    return nearItem;
}
Also used : NearItem(com.yahoo.prelude.query.NearItem)

Example 5 with NearItem

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

the class YqlParser method instantiateONearItem.

@NonNull
private Item instantiateONearItem(String field, OperatorNode<ExpressionOperator> ast) {
    assertHasFunctionName(ast, ONEAR);
    NearItem onear = new ONearItem();
    onear.setIndexName(field);
    for (OperatorNode<ExpressionOperator> word : ast.<List<OperatorNode<ExpressionOperator>>>getArgument(1)) {
        onear.addItem(instantiateWordItem(field, word, onear.getClass()));
    }
    Integer distance = getAnnotation(ast, DISTANCE, Integer.class, null, "term distance for ONEAR operator");
    if (distance != null) {
        onear.setDistance(distance);
    }
    return onear;
}
Also used : BigInteger(java.math.BigInteger) ONearItem(com.yahoo.prelude.query.ONearItem) 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)

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