use of com.yahoo.prelude.query.RankItem in project vespa by vespa-engine.
the class QueryCanonicalizerMicroBenchmark method canonicalize.
private void canonicalize() {
AndItem and = new AndItem();
and.addItem(new WordItem("shoe", "prod"));
and.addItem(new WordItem("apparel & accessories", "tcnm"));
RankItem rank = new RankItem();
rank.addItem(and);
for (int i = 0; i < 25; i++) rank.addItem(new WordItem("word" + i, "normbrnd"));
QueryTree tree = new QueryTree(rank);
QueryCanonicalizer.canonicalize(tree);
}
use of com.yahoo.prelude.query.RankItem in project vespa by vespa-engine.
the class QueryTestCase method testCloneWithConnectivity.
@Test
public void testCloneWithConnectivity() {
List<String> l = new ArrayList();
l.add("a");
l.add("b");
l.add("c");
l.add("a");
printIt(l.stream().filter(i -> isA(i)).collect(Collectors.toList()));
printIt(l.stream().filter(i -> !isA(i)).collect(Collectors.toList()));
Query q = new Query();
WordItem a = new WordItem("a");
WordItem b = new WordItem("b");
WordItem c = new WordItem("c");
WordItem d = new WordItem("d");
WordItem e = new WordItem("e");
WordItem f = new WordItem("f");
WordItem g = new WordItem("g");
OrItem or = new OrItem();
or.addItem(c);
or.addItem(d);
AndItem and1 = new AndItem();
and1.addItem(a);
and1.addItem(b);
and1.addItem(or);
and1.addItem(e);
AndItem and2 = new AndItem();
and2.addItem(f);
and2.addItem(g);
RankItem rank = new RankItem();
rank.addItem(and1);
rank.addItem(and2);
a.setConnectivity(b, 0.1);
b.setConnectivity(c, 0.2);
c.setConnectivity(d, 0.3);
d.setConnectivity(e, 0.4);
e.setConnectivity(f, 0.5);
f.setConnectivity(g, 0.6);
q.getModel().getQueryTree().setRoot(rank);
Query qClone = q.clone();
assertEquals(q, qClone);
RankItem rankClone = (RankItem) qClone.getModel().getQueryTree().getRoot();
AndItem and1Clone = (AndItem) rankClone.getItem(0);
AndItem and2Clone = (AndItem) rankClone.getItem(1);
OrItem orClone = (OrItem) and1Clone.getItem(2);
WordItem aClone = (WordItem) and1Clone.getItem(0);
WordItem bClone = (WordItem) and1Clone.getItem(1);
WordItem cClone = (WordItem) orClone.getItem(0);
WordItem dClone = (WordItem) orClone.getItem(1);
WordItem eClone = (WordItem) and1Clone.getItem(3);
WordItem fClone = (WordItem) and2Clone.getItem(0);
WordItem gClone = (WordItem) and2Clone.getItem(1);
assertTrue(rankClone != rank);
assertTrue(and1Clone != and1);
assertTrue(and2Clone != and2);
assertTrue(orClone != or);
assertTrue(aClone != a);
assertTrue(bClone != b);
assertTrue(cClone != c);
assertTrue(dClone != d);
assertTrue(eClone != e);
assertTrue(fClone != f);
assertTrue(gClone != g);
assertTrue(aClone.getConnectedItem() == bClone);
assertTrue(bClone.getConnectedItem() == cClone);
assertTrue(cClone.getConnectedItem() == dClone);
assertTrue(dClone.getConnectedItem() == eClone);
assertTrue(eClone.getConnectedItem() == fClone);
assertTrue(fClone.getConnectedItem() == gClone);
double delta = 0.0000001;
assertEquals(0.1, aClone.getConnectivity(), delta);
assertEquals(0.2, bClone.getConnectivity(), delta);
assertEquals(0.3, cClone.getConnectivity(), delta);
assertEquals(0.4, dClone.getConnectivity(), delta);
assertEquals(0.5, eClone.getConnectivity(), delta);
assertEquals(0.6, fClone.getConnectivity(), delta);
}
use of com.yahoo.prelude.query.RankItem in project vespa by vespa-engine.
the class LiteralBoostSearcher method addTopLevelRankTerms.
/**
* Adds a RankItem at the root of a query, but only if there is
* at least one rank term in the specified RankItem.
* If the root is already a RankItem, just append the new rank terms.
*
* @param rankTerms the new rank item to add.
* @param query the query to add to
*/
private void addTopLevelRankTerms(RankItem rankTerms, Query query) {
Item root = query.getModel().getQueryTree().getRoot();
if (root instanceof RankItem) {
for (Iterator<Item> i = rankTerms.getItemIterator(); i.hasNext(); ) {
((RankItem) root).addItem(i.next());
}
} else {
rankTerms.addItem(0, root);
query.getModel().getQueryTree().setRoot(rankTerms);
}
}
use of com.yahoo.prelude.query.RankItem in project vespa by vespa-engine.
the class LiteralBoostSearcher method addRankTerms.
private void addRankTerms(Query query, IndexFacts.Session indexFacts) {
RankItem newRankTerms = new RankItem();
addLiterals(newRankTerms, query.getModel().getQueryTree().getRoot(), indexFacts);
if (newRankTerms.getItemCount() > 0)
addTopLevelRankTerms(newRankTerms, query);
if (query.getTraceLevel() >= 2 && newRankTerms.getItemCount() > 0)
query.trace("Added rank terms for possible literal field matches.", true, 2);
}
use of com.yahoo.prelude.query.RankItem 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());
}
Aggregations