Search in sources :

Example 66 with Item

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);
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) SimpleIndexedItem(com.yahoo.prelude.query.SimpleIndexedItem) OrItem(com.yahoo.prelude.query.OrItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) EquivItem(com.yahoo.prelude.query.EquivItem)

Example 67 with Item

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;
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) SimpleIndexedItem(com.yahoo.prelude.query.SimpleIndexedItem) OrItem(com.yahoo.prelude.query.OrItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) EquivItem(com.yahoo.prelude.query.EquivItem) CompositeItem(com.yahoo.prelude.query.CompositeItem)

Example 68 with 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;
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) SimpleIndexedItem(com.yahoo.prelude.query.SimpleIndexedItem) OrItem(com.yahoo.prelude.query.OrItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) EquivItem(com.yahoo.prelude.query.EquivItem) NotItem(com.yahoo.prelude.query.NotItem)

Example 69 with Item

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;
}
Also used : AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) AndItem(com.yahoo.prelude.query.AndItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) WordItem(com.yahoo.prelude.query.WordItem) ListIterator(java.util.ListIterator) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem)

Example 70 with Item

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);
}
Also used : Item(com.yahoo.prelude.query.Item)

Aggregations

Item (com.yahoo.prelude.query.Item)116 AndItem (com.yahoo.prelude.query.AndItem)85 CompositeItem (com.yahoo.prelude.query.CompositeItem)82 WordItem (com.yahoo.prelude.query.WordItem)73 PhraseItem (com.yahoo.prelude.query.PhraseItem)66 NotItem (com.yahoo.prelude.query.NotItem)62 RankItem (com.yahoo.prelude.query.RankItem)60 SubstringItem (com.yahoo.prelude.query.SubstringItem)60 Test (org.junit.Test)58 OrItem (com.yahoo.prelude.query.OrItem)57 PrefixItem (com.yahoo.prelude.query.PrefixItem)53 SuffixItem (com.yahoo.prelude.query.SuffixItem)53 IntItem (com.yahoo.prelude.query.IntItem)52 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)51 NullItem (com.yahoo.prelude.query.NullItem)24 Query (com.yahoo.search.Query)22 EquivItem (com.yahoo.prelude.query.EquivItem)14 NearItem (com.yahoo.prelude.query.NearItem)14 ExactStringItem (com.yahoo.prelude.query.ExactStringItem)12 IndexedItem (com.yahoo.prelude.query.IndexedItem)12