Search in sources :

Example 56 with WordItem

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

the class VespaSerializerTestCase method testLongAndNot.

@Test
public final void testLongAndNot() {
    NotItem item = new NotItem();
    item.addItem(new WordItem("a"));
    item.addItem(new WordItem("b"));
    item.addItem(new WordItem("c"));
    item.addItem(new WordItem("d"));
    String q = VespaSerializer.serialize(item);
    assertEquals("(default contains ([{\"implicitTransforms\": false}]\"a\")) AND !(default contains ([{\"implicitTransforms\": false}]\"b\") OR default contains ([{\"implicitTransforms\": false}]\"c\") OR default contains ([{\"implicitTransforms\": false}]\"d\"))", q);
}
Also used : NotItem(com.yahoo.prelude.query.NotItem) MarkerWordItem(com.yahoo.prelude.query.MarkerWordItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 57 with WordItem

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

the class VespaSerializerTestCase method requireThatGroupingContinuationsAreSerialized.

@Test
public void requireThatGroupingContinuationsAreSerialized() {
    Query query = new Query();
    query.getModel().getQueryTree().setRoot(new WordItem("foo"));
    assertEquals("default contains ([{\"implicitTransforms\": false}]\"foo\")", VespaSerializer.serialize(query));
    newGroupingRequest(query, new AllOperation().setGroupBy(new AttributeFunction("a")).addChild(new EachOperation().addOutput(new CountAggregator())), Continuation.fromString("BCBCBCBEBG"), Continuation.fromString("BCBKCBACBKCCK"));
    assertEquals("default contains ([{\"implicitTransforms\": false}]\"foo\") " + "| [{ 'continuations':['BCBCBCBEBG', 'BCBKCBACBKCCK'] }]" + "all(group(attribute(a)) each(output(count())))", VespaSerializer.serialize(query));
    newGroupingRequest(query, new AllOperation().setGroupBy(new AttributeFunction("b")).addChild(new EachOperation().addOutput(new CountAggregator())), Continuation.fromString("BCBBBBBDBF"), Continuation.fromString("BCBJBPCBJCCJ"));
    assertEquals("default contains ([{\"implicitTransforms\": false}]\"foo\") " + "| [{ 'continuations':['BCBCBCBEBG', 'BCBKCBACBKCCK'] }]" + "all(group(attribute(a)) each(output(count()))) " + "| [{ 'continuations':['BCBBBBBDBF', 'BCBJBPCBJCCJ'] }]" + "all(group(attribute(b)) each(output(count())))", VespaSerializer.serialize(query));
}
Also used : EachOperation(com.yahoo.search.grouping.request.EachOperation) Query(com.yahoo.search.Query) CountAggregator(com.yahoo.search.grouping.request.CountAggregator) AllOperation(com.yahoo.search.grouping.request.AllOperation) MarkerWordItem(com.yahoo.prelude.query.MarkerWordItem) WordItem(com.yahoo.prelude.query.WordItem) AttributeFunction(com.yahoo.search.grouping.request.AttributeFunction) Test(org.junit.Test)

Example 58 with WordItem

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

the class VespaSerializerTestCase method testAnnotatedPhraseSegment.

@Test
public final void testAnnotatedPhraseSegment() {
    PhraseSegmentItem phraseSegment = new PhraseSegmentItem("abc", true, false);
    phraseSegment.addItem(new WordItem("a", "indexNamePlaceholder"));
    phraseSegment.addItem(new WordItem("b", "indexNamePlaceholder"));
    phraseSegment.setIndexName("someIndexName");
    phraseSegment.setLabel("labeled");
    phraseSegment.lock();
    String q = VespaSerializer.serialize(phraseSegment);
    assertEquals("someIndexName contains ([{\"origin\": {\"original\": \"abc\", \"offset\": 0, \"length\": 3}, \"label\": \"labeled\"}]phrase(\"a\", \"b\"))", q);
}
Also used : MarkerWordItem(com.yahoo.prelude.query.MarkerWordItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) Test(org.junit.Test)

Example 59 with WordItem

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

the class LiteralTermProduction method produce.

public void produce(RuleEvaluation e, int offset) {
    WordItem newItem = new WordItem(literal, getLabel());
    if (replacing) {
        Match matched = e.getNonreferencedMatch(0);
        insertMatch(e, matched, newItem, offset);
    } else {
        newItem.setWeight(getWeight());
        if (e.getTraceLevel() >= 6)
            e.trace(6, "Adding '" + newItem + "'");
        e.addItem(newItem, getTermType());
    }
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) Match(com.yahoo.prelude.semantics.engine.Match)

Example 60 with WordItem

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

WordItem (com.yahoo.prelude.query.WordItem)93 Test (org.junit.Test)76 AndItem (com.yahoo.prelude.query.AndItem)45 PhraseItem (com.yahoo.prelude.query.PhraseItem)31 Query (com.yahoo.search.Query)25 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)20 CompositeItem (com.yahoo.prelude.query.CompositeItem)18 Item (com.yahoo.prelude.query.Item)17 MarkerWordItem (com.yahoo.prelude.query.MarkerWordItem)16 NotItem (com.yahoo.prelude.query.NotItem)16 OrItem (com.yahoo.prelude.query.OrItem)13 ByteBuffer (java.nio.ByteBuffer)11 PrefixItem (com.yahoo.prelude.query.PrefixItem)10 SubstringItem (com.yahoo.prelude.query.SubstringItem)10 SuffixItem (com.yahoo.prelude.query.SuffixItem)10 Execution (com.yahoo.search.searchchain.Execution)10 RankItem (com.yahoo.prelude.query.RankItem)9 PhraseMatcher (com.yahoo.prelude.querytransform.PhraseMatcher)9 IntItem (com.yahoo.prelude.query.IntItem)8 WeakAndItem (com.yahoo.prelude.query.WeakAndItem)7