Search in sources :

Example 1 with CompositeItem

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;
    }
}
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 2 with CompositeItem

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"));
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NotItem(com.yahoo.prelude.query.NotItem) Iterator(java.util.Iterator) Index(com.yahoo.prelude.Index) WordItem(com.yahoo.prelude.query.WordItem) TermItem(com.yahoo.prelude.query.TermItem)

Example 3 with CompositeItem

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

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

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());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Query(com.yahoo.search.Query) Test(org.junit.Test)

Aggregations

CompositeItem (com.yahoo.prelude.query.CompositeItem)25 AndItem (com.yahoo.prelude.query.AndItem)13 Test (org.junit.Test)13 Item (com.yahoo.prelude.query.Item)12 PhraseItem (com.yahoo.prelude.query.PhraseItem)10 WordItem (com.yahoo.prelude.query.WordItem)10 Query (com.yahoo.search.Query)10 Execution (com.yahoo.search.searchchain.Execution)9 NotItem (com.yahoo.prelude.query.NotItem)6 NullItem (com.yahoo.prelude.query.NullItem)6 OrItem (com.yahoo.prelude.query.OrItem)6 EquivItem (com.yahoo.prelude.query.EquivItem)5 NearItem (com.yahoo.prelude.query.NearItem)5 RankItem (com.yahoo.prelude.query.RankItem)5 SimpleIndexedItem (com.yahoo.prelude.query.SimpleIndexedItem)5 SubstringItem (com.yahoo.prelude.query.SubstringItem)5 PhrasingSearcher (com.yahoo.prelude.querytransform.PhrasingSearcher)4 Searcher (com.yahoo.search.Searcher)4 NonPhrasingSearcher (com.yahoo.prelude.querytransform.NonPhrasingSearcher)3 TermItem (com.yahoo.prelude.query.TermItem)2