Search in sources :

Example 46 with AndItem

use of com.yahoo.prelude.query.AndItem 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)

Example 47 with AndItem

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

the class PhrasingSearcherTestCase method testMultiplePhrases.

@Test
public void testMultiplePhrases() {
    Searcher searcher = new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa");
    Query query = new Query();
    AndItem andItem = new AndItem();
    andItem.addItem(new WordItem("tudor", "someindex"));
    andItem.addItem(new WordItem("tudor", "someindex"));
    andItem.addItem(new WordItem("vidor", "someindex"));
    andItem.addItem(new WordItem("vidor", "someindex"));
    OrItem orItem = new OrItem();
    andItem.addItem(orItem);
    orItem.addItem(new WordItem("tudor"));
    AndItem andItem2 = new AndItem();
    andItem2.addItem(new WordItem("this", "anotherindex"));
    andItem2.addItem(new WordItem("is", "anotherindex"));
    andItem2.addItem(new WordItem("a", "anotherindex"));
    andItem2.addItem(new WordItem("test", "anotherindex"));
    andItem2.addItem(new WordItem("tudor", "anotherindex"));
    andItem2.addItem(new WordItem("vidor", "anotherindex"));
    orItem.addItem(andItem2);
    orItem.addItem(new WordItem("vidor"));
    query.getModel().getQueryTree().setRoot(andItem);
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    assertEquals("AND someindex:tudor someindex:\"tudor vidor\" someindex:vidor (OR tudor (AND anotherindex:\"this is a test\" anotherindex:\"tudor vidor\") vidor)", query.getModel().getQueryTree().getRoot().toString());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) Searcher(com.yahoo.search.Searcher) PhrasingSearcher(com.yahoo.prelude.querytransform.PhrasingSearcher) WordItem(com.yahoo.prelude.query.WordItem) PhrasingSearcher(com.yahoo.prelude.querytransform.PhrasingSearcher) OrItem(com.yahoo.prelude.query.OrItem) Test(org.junit.Test)

Example 48 with AndItem

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

the class ParseTestCase method testOrAndSomeTermsFilterAndAnAnd.

// This is an ugly parse tree, but it's at least reasonable
@Test
public void testOrAndSomeTermsFilterAndAnAnd() {
    AndItem root = (AndItem) tester.assertParsed("AND (RANK d |c |a |b |e) (OR |e |f)", "d", "c (a b) e +(e f)", Query.Type.ALL);
    // AND
    assertFalse(root.isFilter());
    // RANK
    assertFalse(root.getItem(0).isFilter());
    // d
    assertFalse(((RankItem) root.getItem(0)).getItem(0).isFilter());
    // c
    assertTrue(((RankItem) root.getItem(0)).getItem(1).isFilter());
    // a
    assertTrue(((RankItem) root.getItem(0)).getItem(2).isFilter());
    // b
    assertTrue(((RankItem) root.getItem(0)).getItem(3).isFilter());
    // e
    assertTrue(((RankItem) root.getItem(0)).getItem(4).isFilter());
    // OR
    assertFalse(root.getItem(1).isFilter());
    // e
    assertTrue(((OrItem) root.getItem(1)).getItem(0).isFilter());
    // f
    assertTrue(((OrItem) root.getItem(1)).getItem(1).isFilter());
}
Also used : AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) OrItem(com.yahoo.prelude.query.OrItem) Test(org.junit.Test)

Example 49 with AndItem

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

the class LegacyCombinatorTestCase method testNewAndOld.

public void testNewAndOld() {
    Query q = new Query("?query.juhu=b&defidx.juhu=nalle&query.bamse=z&query.bamse.defidx=y");
    Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts()));
    Set<StringPair> nastierItems = new HashSet<>();
    nastierItems.add(new StringPair("nalle", "b"));
    nastierItems.add(new StringPair("y", "z"));
    e.search(q);
    AndItem root = (AndItem) q.getModel().getQueryTree().getRoot();
    Iterator<?> iterator = root.getItemIterator();
    while (iterator.hasNext()) {
        WordItem word = (WordItem) iterator.next();
        StringPair asPair = new StringPair(word.getIndexName(), word.stringValue());
        if (nastierItems.contains(asPair)) {
            nastierItems.remove(asPair);
        } else {
            assertFalse("Got unexpected item in query tree: (" + word.getIndexName() + ", " + word.stringValue() + ")", true);
        }
    }
    assertEquals("Not all expected items found in query.", 0, nastierItems.size());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) HashSet(java.util.HashSet)

Example 50 with AndItem

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

the class LegacyCombinatorTestCase method testMultiPart.

public void testMultiPart() {
    Query q = new Query("?query=a&query.juhu=b&query.nalle=c");
    Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts()));
    Set<String> items = new HashSet<>();
    items.add("a");
    items.add("b");
    items.add("c");
    e.search(q);
    // OK, the problem here is we have no way of knowing whether nalle or
    // juhu was added first, since we have passed through HashMap instances
    // inside the implementation
    AndItem root = (AndItem) q.getModel().getQueryTree().getRoot();
    Iterator<?> iterator = root.getItemIterator();
    while (iterator.hasNext()) {
        WordItem word = (WordItem) iterator.next();
        if (items.contains(word.stringValue())) {
            items.remove(word.stringValue());
        } else {
            assertFalse("Got unexpected item in query tree: " + word.stringValue(), true);
        }
    }
    assertEquals("Not all expected items found in query.", 0, items.size());
    Set<StringPair> nastierItems = new HashSet<>();
    nastierItems.add(new StringPair("", "a"));
    nastierItems.add(new StringPair("juhu.22[gnuff]", "b"));
    nastierItems.add(new StringPair("gnuff[8].name(\"tralala\")", "c"));
    q = new Query("?query=a&query.juhu=b&defidx.juhu=juhu.22[gnuff]&query.nalle=c&defidx.nalle=gnuff[8].name(%22tralala%22)");
    e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts()));
    e.search(q);
    root = (AndItem) q.getModel().getQueryTree().getRoot();
    iterator = root.getItemIterator();
    while (iterator.hasNext()) {
        WordItem word = (WordItem) iterator.next();
        StringPair asPair = new StringPair(word.getIndexName(), word.stringValue());
        if (nastierItems.contains(asPair)) {
            nastierItems.remove(asPair);
        } else {
            assertFalse("Got unexpected item in query tree: (" + word.getIndexName() + ", " + word.stringValue() + ")", true);
        }
    }
    assertEquals("Not all expected items found in query.", 0, nastierItems.size());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) HashSet(java.util.HashSet)

Aggregations

AndItem (com.yahoo.prelude.query.AndItem)50 Test (org.junit.Test)39 WordItem (com.yahoo.prelude.query.WordItem)36 Query (com.yahoo.search.Query)24 Item (com.yahoo.prelude.query.Item)13 CompositeItem (com.yahoo.prelude.query.CompositeItem)12 PhraseItem (com.yahoo.prelude.query.PhraseItem)12 OrItem (com.yahoo.prelude.query.OrItem)10 Execution (com.yahoo.search.searchchain.Execution)10 IntItem (com.yahoo.prelude.query.IntItem)9 NotItem (com.yahoo.prelude.query.NotItem)7 RankItem (com.yahoo.prelude.query.RankItem)7 SubstringItem (com.yahoo.prelude.query.SubstringItem)5 PhraseMatcher (com.yahoo.prelude.querytransform.PhraseMatcher)5 PhrasingSearcher (com.yahoo.prelude.querytransform.PhrasingSearcher)5 Searcher (com.yahoo.search.Searcher)5 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)4 WeakAndItem (com.yahoo.prelude.query.WeakAndItem)4 Result (com.yahoo.search.Result)4 IndexFacts (com.yahoo.prelude.IndexFacts)3