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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations