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