Search in sources :

Example 1 with Item

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

Example 2 with Item

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

Example 3 with Item

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;
}
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) SimpleIndexedItem(com.yahoo.prelude.query.SimpleIndexedItem) SubstringItem(com.yahoo.prelude.query.SubstringItem)

Example 4 with 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);
    }
}
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 5 with Item

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);
    }
}
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)

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