use of com.yahoo.prelude.query.CompositeItem in project vespa by vespa-engine.
the class CollapsePhraseSearcher method simplifyPhrases.
private Item simplifyPhrases(Item root) {
if (root == null) {
return root;
} else if (root instanceof PhraseItem) {
return collapsePhrase((PhraseItem) root);
} else if (root instanceof CompositeItem) {
CompositeItem composite = (CompositeItem) root;
ListIterator<Item> i = composite.getItemIterator();
while (i.hasNext()) {
Item original = i.next();
Item transformed = simplifyPhrases(original);
if (original != transformed)
i.set(transformed);
}
return root;
} else {
return root;
}
}
use of com.yahoo.prelude.query.CompositeItem in project vespa by vespa-engine.
the class LiteralBoostSearcher method addLiterals.
private void addLiterals(RankItem rankTerms, Item item, IndexFacts.Session indexFacts) {
if (item == null)
return;
if (item instanceof NotItem) {
addLiterals(rankTerms, ((NotItem) item).getPositiveItem(), indexFacts);
} else if (item instanceof CompositeItem) {
for (Iterator<Item> i = ((CompositeItem) item).getItemIterator(); i.hasNext(); ) addLiterals(rankTerms, i.next(), indexFacts);
} else if (item instanceof TermItem) {
TermItem termItem = (TermItem) item;
Index index = indexFacts.getIndex(termItem.getIndexName());
if (index.getLiteralBoost())
rankTerms.addItem(new WordItem(toLowerCase(termItem.getRawWord()), index.getName() + "_literal"));
}
}
use of com.yahoo.prelude.query.CompositeItem in project vespa by vespa-engine.
the class QueryRewrite method rewriteSddocname.
private static Item rewriteSddocname(Item item) {
if (item instanceof CompositeItem) {
CompositeItem parent = (CompositeItem) item;
for (int i = 0, len = parent.getItemCount(); i < len; ++i) {
Item oldChild = parent.getItem(i);
Item newChild = rewriteSddocname(oldChild);
if (oldChild != newChild) {
parent.setItem(i, newChild);
}
}
} else if (item instanceof SimpleIndexedItem) {
SimpleIndexedItem oldItem = (SimpleIndexedItem) item;
if (Hit.SDDOCNAME_FIELD.equals(oldItem.getIndexName())) {
SubstringItem newItem = new SubstringItem(oldItem.getIndexedString());
newItem.setIndexName("[documentmetastore]");
return newItem;
}
}
return item;
}
use of com.yahoo.prelude.query.CompositeItem in project vespa by vespa-engine.
the class QueryRewrite method collapseSingleComposites.
/**
* Collapses all single-child {@link CompositeItem}s into their parent item.
*/
public static void collapseSingleComposites(Query query) {
Item oldRoot = query.getModel().getQueryTree().getRoot();
Item newRoot = collapseSingleComposites(oldRoot);
if (oldRoot != newRoot) {
query.getModel().getQueryTree().setRoot(newRoot);
}
}
use of com.yahoo.prelude.query.CompositeItem in project vespa by vespa-engine.
the class SubstringTestCase method testBug5968479.
@Test
public final void testBug5968479() {
String first = "\u0130\u015EBANKASI";
String second = "GAZ\u0130EM\u0130R";
Query q = new Query("/?query=" + enc(first) + "%20" + enc(second));
CompositeItem root = (CompositeItem) q.getModel().getQueryTree().getRoot();
assertEquals(first, ((WordItem) root.getItem(0)).getRawWord());
assertEquals(second, ((WordItem) root.getItem(1)).getRawWord());
}
Aggregations