Search in sources :

Example 1 with WeightedSetItem

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

the class SemanticSearcherTestCase method testWeightedSetItem.

// This test is order dependent. Fix it!!
public void testWeightedSetItem() {
    Query q = new Query();
    WeightedSetItem weightedSet = new WeightedSetItem("fieldName");
    weightedSet.addToken("a", 1);
    weightedSet.addToken("b", 2);
    q.getModel().getQueryTree().setRoot(weightedSet);
    assertSemantics("WEIGHTEDSET fieldName{[1]:\"a\",[2]:\"b\"}", q);
}
Also used : Query(com.yahoo.search.Query) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem)

Example 2 with WeightedSetItem

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

the class LowercasingTestCase method testWeightedSet.

@Test
public void testWeightedSet() {
    Query q = new Query();
    AndItem root = new AndItem();
    WeightedSetItem tmp;
    tmp = new WeightedSetItem(BAMSE);
    tmp.addToken("AbC", 3);
    root.addItem(tmp);
    tmp = new WeightedSetItem(TEDDY);
    tmp.addToken("dEf", 5);
    root.addItem(tmp);
    q.getModel().getQueryTree().setRoot(root);
    Result r = execution.search(q);
    root = (AndItem) r.getQuery().getModel().getQueryTree().getRoot();
    WeightedSetItem w0 = (WeightedSetItem) root.getItem(0);
    WeightedSetItem w1 = (WeightedSetItem) root.getItem(1);
    assertEquals(1, w0.getNumTokens());
    assertEquals(1, w1.getNumTokens());
    assertEquals("abc", w0.getTokens().next().getKey());
    assertEquals("dEf", w1.getTokens().next().getKey());
}
Also used : Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 3 with WeightedSetItem

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

the class LowercasingTestCase method testDisableLowercasingWeightedSet.

@Test
public void testDisableLowercasingWeightedSet() {
    execution = new Execution(new Chain<Searcher>(new VespaLowercasingSearcher(new LowercasingConfig(new LowercasingConfig.Builder().transform_weighted_sets(false)))), Execution.Context.createContextStub(settings));
    Query q = new Query();
    AndItem root = new AndItem();
    WeightedSetItem tmp;
    tmp = new WeightedSetItem(BAMSE);
    tmp.addToken("AbC", 3);
    root.addItem(tmp);
    tmp = new WeightedSetItem(TEDDY);
    tmp.addToken("dEf", 5);
    root.addItem(tmp);
    q.getModel().getQueryTree().setRoot(root);
    Result r = execution.search(q);
    root = (AndItem) r.getQuery().getModel().getQueryTree().getRoot();
    WeightedSetItem w0 = (WeightedSetItem) root.getItem(0);
    WeightedSetItem w1 = (WeightedSetItem) root.getItem(1);
    assertEquals(1, w0.getNumTokens());
    assertEquals(1, w1.getNumTokens());
    assertEquals("AbC", w0.getTokens().next().getKey());
    assertEquals("dEf", w1.getTokens().next().getKey());
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 4 with WeightedSetItem

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

the class YqlParser method buildWeightedSet.

@NonNull
private Item buildWeightedSet(OperatorNode<ExpressionOperator> ast) {
    List<OperatorNode<ExpressionOperator>> args = ast.getArgument(1);
    Preconditions.checkArgument(args.size() == 2, "Expected 2 arguments, got %s.", args.size());
    return fillWeightedSet(ast, args.get(1), new WeightedSetItem(getIndex(args.get(0))));
}
Also used : WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 5 with WeightedSetItem

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

the class WeightedSetItemTestCase method testNegativeWeight.

@Test
public void testNegativeWeight() {
    WeightedSetItem ws = new WeightedSetItem("index");
    assertEquals(new Integer(-10), ws.addToken("bad", -10));
    assertEquals(1, ws.getNumTokens());
    assertEquals(new Integer(-10), ws.getTokenWeight("bad"));
}
Also used : WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) Test(org.junit.Test)

Aggregations

WeightedSetItem (com.yahoo.prelude.query.WeightedSetItem)8 Test (org.junit.Test)6 Query (com.yahoo.search.Query)4 AndItem (com.yahoo.prelude.query.AndItem)3 Result (com.yahoo.search.Result)2 Chain (com.yahoo.component.chain.Chain)1 QueryPacket (com.yahoo.fs4.QueryPacket)1 PureWeightedString (com.yahoo.prelude.query.PureWeightedString)1 WordItem (com.yahoo.prelude.query.WordItem)1 Execution (com.yahoo.search.searchchain.Execution)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 ByteBuffer (java.nio.ByteBuffer)1