Search in sources :

Example 16 with CompositeItem

use of com.yahoo.prelude.query.CompositeItem in project vespa by vespa-engine.

the class RewriterFeaturesTestCase method testConvertStringToQTree.

@Test
public final void testConvertStringToQTree() {
    Execution placeholder = new Execution(Context.createContextStub());
    SpecialTokenRegistry tokenRegistry = new SpecialTokenRegistry(new SpecialtokensConfig(new SpecialtokensConfig.Builder().tokenlist(new Tokenlist.Builder().name("default").tokens(new Tokens.Builder().token(ASCII_ELLIPSIS)))));
    placeholder.context().setTokenRegistry(tokenRegistry);
    Query query = new Query();
    query.getModel().setExecution(placeholder);
    Item parsed = RewriterFeatures.convertStringToQTree(query, "a b c " + ASCII_ELLIPSIS);
    assertSame(AndItem.class, parsed.getClass());
    assertEquals(4, ((CompositeItem) parsed).getItemCount());
    assertEquals(ASCII_ELLIPSIS, ((CompositeItem) parsed).getItem(3).toString());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) Execution(com.yahoo.search.searchchain.Execution) SpecialTokenRegistry(com.yahoo.prelude.query.parser.SpecialTokenRegistry) Query(com.yahoo.search.Query) SpecialtokensConfig(com.yahoo.vespa.configdefinition.SpecialtokensConfig) Tokenlist(com.yahoo.vespa.configdefinition.SpecialtokensConfig.Tokenlist) Tokens(com.yahoo.vespa.configdefinition.SpecialtokensConfig.Tokenlist.Tokens) Test(org.junit.Test)

Example 17 with CompositeItem

use of com.yahoo.prelude.query.CompositeItem in project vespa by vespa-engine.

the class QueryRewrite method extractAndNotRecursively.

private static CompositeItem extractAndNotRecursively(CompositeItem parent) {
    for (int i = 0; i < parent.getItemCount(); i++) {
        Item child = parent.getItem(i);
        Item possibleNewChild = optimizeAndNot(child);
        if (child != possibleNewChild) {
            parent.setItem(i, possibleNewChild);
        }
    }
    if (parent instanceof AndItem) {
        return extractAndNot((AndItem) parent);
    }
    return 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) AndItem(com.yahoo.prelude.query.AndItem)

Example 18 with CompositeItem

use of com.yahoo.prelude.query.CompositeItem 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 19 with CompositeItem

use of com.yahoo.prelude.query.CompositeItem 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 20 with CompositeItem

use of com.yahoo.prelude.query.CompositeItem 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)

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