use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class QueryRewrite method rewriteSddocname.
/**
* Replaces and {@link SimpleIndexedItem} searching in the {@link Hit#SDDOCNAME_FIELD} with an item
* appropriate for the search node.
*/
public static void rewriteSddocname(Query query) {
Item oldRoot = query.getModel().getQueryTree().getRoot();
Item newRoot = rewriteSddocname(oldRoot);
if (oldRoot != newRoot) {
query.getModel().getQueryTree().setRoot(newRoot);
}
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class QueryRewrite method collapseSingleComposites.
private static Item collapseSingleComposites(Item item) {
if (!(item instanceof CompositeItem)) {
return item;
}
CompositeItem parent = (CompositeItem) item;
int numChildren = parent.getItemCount();
for (int i = 0; i < numChildren; ++i) {
Item oldChild = parent.getItem(i);
Item newChild = collapseSingleComposites(oldChild);
if (oldChild != newChild) {
parent.setItem(i, newChild);
}
}
return numChildren == 1 ? parent.getItem(0) : item;
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class QueryRewrite method extractAndNot.
private static CompositeItem extractAndNot(AndItem parent) {
NotItem theOnlyNot = null;
for (int i = 0; i < parent.getItemCount(); i++) {
Item child = parent.getItem(i);
if (child instanceof NotItem) {
NotItem thisNot = (NotItem) child;
parent.setItem(i, thisNot.getPositiveItem());
if (theOnlyNot == null) {
theOnlyNot = thisNot;
theOnlyNot.setPositiveItem(parent);
} else {
for (int j = 1; j < thisNot.getItemCount(); j++) {
theOnlyNot.addNegativeItem(thisNot.getItem(j));
}
}
}
}
return (theOnlyNot != null) ? theOnlyNot : parent;
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class CJKSearcher method transform.
private Item transform(Item root) {
if (root instanceof PhraseItem) {
PhraseItem asPhrase = (PhraseItem) root;
if (asPhrase.isExplicit() || hasOverlappingTokens(asPhrase))
return root;
AndItem replacement = new AndItem();
for (ListIterator<Item> i = ((CompositeItem) root).getItemIterator(); i.hasNext(); ) {
Item item = i.next();
if (item instanceof WordItem)
replacement.addItem(item);
else if (item instanceof PhraseSegmentItem) {
replacement.addItem(new AndSegmentItem((PhraseSegmentItem) item));
} else
// should never run, but hey... just convert and hope it's OK :)
replacement.addItem(item);
}
return replacement;
} else if (root instanceof PhraseSegmentItem) {
PhraseSegmentItem asSegment = (PhraseSegmentItem) root;
if (asSegment.isExplicit() || hasOverlappingTokens(asSegment))
return root;
else
return new AndSegmentItem(asSegment);
} else if (root instanceof SegmentItem) {
// avoid descending into AndSegmentItems and similar
return root;
} else if (root instanceof CompositeItem) {
for (ListIterator<Item> i = ((CompositeItem) root).getItemIterator(); i.hasNext(); ) {
Item item = i.next();
Item transformedItem = transform(item);
if (item != transformedItem) {
i.set(transformedItem);
}
}
return root;
}
return root;
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class ReferenceTermProduction method replaceMatches.
public void replaceMatches(RuleEvaluation e, ReferencedMatches referencedMatches) {
Item referencedItem = referencedMatches.toItem(getLabel());
if (referencedItem == null)
return;
e.removeMatches(referencedMatches);
insertMatch(e, referencedMatches.matchIterator().next(), referencedItem, 0);
}
Aggregations