Search in sources :

Example 16 with IntItem

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

the class RangeQueryOptimizerTestCase method testNoRangeOptimizingWhenAttributesAreIncompatible.

@Test
public void testNoRangeOptimizingWhenAttributesAreIncompatible() {
    Query query = new Query();
    AndItem root = new AndItem();
    query.getModel().getQueryTree().setRoot(root);
    Item intItem1 = new IntItem(">" + 15, "s");
    intItem1.setFilter(true);
    intItem1.setRanked(false);
    intItem1.setWeight(500);
    root.addItem(intItem1);
    Item intItem2 = new IntItem("<" + 30, "s");
    // Disagrees with item1
    intItem2.setFilter(false);
    intItem2.setRanked(false);
    intItem2.setWeight(500);
    root.addItem(intItem2);
    assertOptimized("Not optimized", "AND |s:<15;]!500 s:[;30>!500", query);
    IntItem transformedIntItem1 = (IntItem) ((AndItem) query.getModel().getQueryTree().getRoot()).getItem(0);
    assertTrue("Filter was carried over", transformedIntItem1.isFilter());
    assertFalse("Ranked was carried over", transformedIntItem1.isRanked());
    assertEquals("Weight was carried over", 500, transformedIntItem1.getWeight());
    IntItem transformedIntItem2 = (IntItem) ((AndItem) query.getModel().getQueryTree().getRoot()).getItem(1);
    assertFalse("Filter was carried over", transformedIntItem2.isFilter());
    assertFalse("Ranked was carried over", transformedIntItem2.isRanked());
    assertEquals("Weight was carried over", 500, transformedIntItem2.getWeight());
}
Also used : IntItem(com.yahoo.prelude.query.IntItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) IntItem(com.yahoo.prelude.query.IntItem) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) Test(org.junit.Test)

Example 17 with IntItem

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

the class RangeQueryOptimizerTestCase method testDifferentCompatibleRangesPerFieldAreOptimizedSeparately.

@Test
public void testDifferentCompatibleRangesPerFieldAreOptimizedSeparately() {
    Query query = new Query();
    AndItem root = new AndItem();
    query.getModel().getQueryTree().setRoot(root);
    // Two internally compatible items
    Item intItem1 = new IntItem(">" + 15, "s");
    intItem1.setRanked(false);
    root.addItem(intItem1);
    Item intItem2 = new IntItem("<" + 30, "s");
    intItem2.setRanked(false);
    root.addItem(intItem2);
    // Two other internally compatible items incompatible with the above
    Item intItem3 = new IntItem(">" + 100, "s");
    root.addItem(intItem3);
    Item intItem4 = new IntItem("<" + 150, "s");
    root.addItem(intItem4);
    assertOptimized("Optimized", "AND s:<15;30> s:<100;150>", query);
    IntItem transformedIntItem1 = (IntItem) ((AndItem) query.getModel().getQueryTree().getRoot()).getItem(0);
    assertFalse("Ranked was carried over", transformedIntItem1.isRanked());
    IntItem transformedIntItem2 = (IntItem) ((AndItem) query.getModel().getQueryTree().getRoot()).getItem(1);
    assertTrue("Ranked was carried over", transformedIntItem2.isRanked());
}
Also used : IntItem(com.yahoo.prelude.query.IntItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) IntItem(com.yahoo.prelude.query.IntItem) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) Test(org.junit.Test)

Example 18 with IntItem

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

the class ParseTestCase method testZipCodeShortcutWeb.

@Test
public void testZipCodeShortcutWeb() {
    tester.assertParsed("12345", "12345", Query.Type.WEB);
    IntItem root = (IntItem) tester.assertParsed("00012!150", "00012!", Query.Type.WEB);
    assertEquals('!', root.getOrigin().charAfter(0));
}
Also used : IntItem(com.yahoo.prelude.query.IntItem) Test(org.junit.Test)

Example 19 with IntItem

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

the class ParseTestCase method testLong.

@Test
public void testLong() {
    Item number = tester.assertParsed("3000000000000", "3000000000000", Query.Type.ALL);
    assertTrue(number instanceof IntItem);
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) IntItem(com.yahoo.prelude.query.IntItem) Test(org.junit.Test)

Example 20 with IntItem

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

the class IntItemTestCase method testEquals.

@Test
public void testEquals() {
    Query q1 = new Query("/?query=123%20456%20789");
    Query q2 = new Query("/?query=123%20456");
    AndItem andItem = (AndItem) q2.getModel().getQueryTree().getRoot();
    andItem.addItem(new IntItem(789l, ""));
    assertEquals(q1, q2);
}
Also used : IntItem(com.yahoo.prelude.query.IntItem) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) Test(org.junit.Test)

Aggregations

IntItem (com.yahoo.prelude.query.IntItem)21 Test (org.junit.Test)12 AndItem (com.yahoo.prelude.query.AndItem)11 Item (com.yahoo.prelude.query.Item)9 NonNull (edu.umd.cs.findbugs.annotations.NonNull)7 CompositeItem (com.yahoo.prelude.query.CompositeItem)5 WordItem (com.yahoo.prelude.query.WordItem)5 Query (com.yahoo.search.Query)5 NotItem (com.yahoo.prelude.query.NotItem)4 OrItem (com.yahoo.prelude.query.OrItem)4 PhraseItem (com.yahoo.prelude.query.PhraseItem)4 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)4 PrefixItem (com.yahoo.prelude.query.PrefixItem)4 RankItem (com.yahoo.prelude.query.RankItem)4 SubstringItem (com.yahoo.prelude.query.SubstringItem)4 SuffixItem (com.yahoo.prelude.query.SuffixItem)4 RangeItem (com.yahoo.prelude.query.RangeItem)2 LazyMap (com.yahoo.collections.LazyMap)1 AndSegmentItem (com.yahoo.prelude.query.AndSegmentItem)1 DotProductItem (com.yahoo.prelude.query.DotProductItem)1