use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class CollapsePhraseSearcher method search.
public Result search(Query query, Execution execution) {
QueryTree tree = query.getModel().getQueryTree();
Item root = tree.getRoot();
if (root != null) {
Item newRoot = root.clone();
newRoot = simplifyPhrases(newRoot);
// to make code nicer if the root is a single term phrase
if (!root.equals(newRoot)) {
tree.setRoot(newRoot);
query.trace("Collapsing single term phrases to single terms", true, 2);
}
}
return execution.search(query);
}
use of com.yahoo.prelude.query.Item 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.Item 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.Item in project vespa by vespa-engine.
the class QueryRewrite method optimizeAndNot.
// ------------------- Start public API
/**
* Optimize multiple NotItems under and or by collapsing them in to one and leaving
* the positive ones behind in its place and moving itself with the original and as its positive item
* and the union of all the negative items of all the original NotItems as its negative items.
*/
public static void optimizeAndNot(Query query) {
Item root = query.getModel().getQueryTree().getRoot();
Item possibleNewRoot = optimizeAndNot(root);
if (root != possibleNewRoot) {
query.getModel().getQueryTree().setRoot(possibleNewRoot);
}
}
use of com.yahoo.prelude.query.Item 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);
}
}
Aggregations