Search in sources :

Example 1 with EquivItem

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

the class ItemEncodingTestCase method testEquivItemEncoding.

@Test
public void testEquivItemEncoding() {
    WordItem a = new WordItem("a");
    WordItem b = new WordItem("b");
    EquivItem equiv = new EquivItem();
    equiv.addItem(a);
    equiv.addItem(b);
    ByteBuffer buffer = ByteBuffer.allocate(128);
    int count = equiv.encode(buffer);
    buffer.flip();
    assertEquals("Serialization count", 3, count);
    assertType(buffer, 14, 0);
    assertEquals("Equiv arity", 2, buffer.get());
    assertWord(buffer, "a");
    assertWord(buffer, "b");
}
Also used : EquivItem(com.yahoo.prelude.query.EquivItem) MarkerWordItem(com.yahoo.prelude.query.MarkerWordItem) WordItem(com.yahoo.prelude.query.WordItem) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with EquivItem

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

the class SerializeItemTestCase method serialize_unique_id.

@Test
public void serialize_unique_id() throws ParseException {
    EquivItem equivItem = new EquivItem();
    equivItem.setUniqueID(42);
    EquivItem deSerialized = serializeThenParse(equivItem);
    assertThat(deSerialized.getUniqueID(), is(42));
}
Also used : EquivItem(com.yahoo.prelude.query.EquivItem) Test(org.junit.Test)

Example 3 with EquivItem

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

the class SerializeItemTestCase method serialize_weight.

@Test
public void serialize_weight() throws ParseException {
    EquivItem equivItem = new EquivItem();
    equivItem.setWeight(42);
    EquivItem deSerialized = serializeThenParse(equivItem);
    assertThat(deSerialized.getWeight(), is(42));
}
Also used : EquivItem(com.yahoo.prelude.query.EquivItem) Test(org.junit.Test)

Example 4 with EquivItem

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

the class YqlParser method instantiateEquivItem.

@NonNull
private Item instantiateEquivItem(String field, OperatorNode<ExpressionOperator> ast) {
    List<OperatorNode<ExpressionOperator>> args = ast.getArgument(1);
    Preconditions.checkArgument(args.size() >= 2, "Expected 2 or more arguments, got %s.", args.size());
    EquivItem equiv = new EquivItem();
    equiv.setIndexName(field);
    for (OperatorNode<ExpressionOperator> arg : args) {
        switch(arg.getOperator()) {
            case LITERAL:
                equiv.addItem(instantiateWordItem(field, arg, equiv.getClass()));
                break;
            case CALL:
                assertHasFunctionName(arg, PHRASE);
                equiv.addItem(instantiatePhraseItem(field, arg));
                break;
            default:
                throw newUnexpectedArgumentException(arg.getOperator(), ExpressionOperator.CALL, ExpressionOperator.LITERAL);
        }
    }
    return leafStyleSettings(ast, equiv);
}
Also used : EquivItem(com.yahoo.prelude.query.EquivItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 5 with EquivItem

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

the class SerializeItemTestCase method serialize_significance.

@Test
public void serialize_significance() throws ParseException {
    EquivItem equivItem = new EquivItem();
    equivItem.setSignificance(24.2);
    EquivItem deSerialized = serializeThenParse(equivItem);
    assertThat(deSerialized.getSignificance(), is(24.2));
}
Also used : EquivItem(com.yahoo.prelude.query.EquivItem) Test(org.junit.Test)

Aggregations

EquivItem (com.yahoo.prelude.query.EquivItem)6 Test (org.junit.Test)5 WordItem (com.yahoo.prelude.query.WordItem)2 MarkerWordItem (com.yahoo.prelude.query.MarkerWordItem)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 ByteBuffer (java.nio.ByteBuffer)1