use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class PhrasingSearcherTestCase method testMultiplePhrases.
@Test
public void testMultiplePhrases() {
Searcher searcher = new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa");
Query query = new Query();
AndItem andItem = new AndItem();
andItem.addItem(new WordItem("tudor", "someindex"));
andItem.addItem(new WordItem("tudor", "someindex"));
andItem.addItem(new WordItem("vidor", "someindex"));
andItem.addItem(new WordItem("vidor", "someindex"));
OrItem orItem = new OrItem();
andItem.addItem(orItem);
orItem.addItem(new WordItem("tudor"));
AndItem andItem2 = new AndItem();
andItem2.addItem(new WordItem("this", "anotherindex"));
andItem2.addItem(new WordItem("is", "anotherindex"));
andItem2.addItem(new WordItem("a", "anotherindex"));
andItem2.addItem(new WordItem("test", "anotherindex"));
andItem2.addItem(new WordItem("tudor", "anotherindex"));
andItem2.addItem(new WordItem("vidor", "anotherindex"));
orItem.addItem(andItem2);
orItem.addItem(new WordItem("vidor"));
query.getModel().getQueryTree().setRoot(andItem);
new Execution(searcher, Execution.Context.createContextStub()).search(query);
assertEquals("AND someindex:tudor someindex:\"tudor vidor\" someindex:vidor (OR tudor (AND anotherindex:\"this is a test\" anotherindex:\"tudor vidor\") vidor)", query.getModel().getQueryTree().getRoot().toString());
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class ItemEncodingTestCase method testWandItemEncoding.
@Test
public void testWandItemEncoding() {
WordItem a = new WordItem("a");
WordItem b = new WordItem("b");
WeakAndItem wand = new WeakAndItem();
wand.addItem(a);
wand.addItem(b);
ByteBuffer buffer = ByteBuffer.allocate(128);
int count = wand.encode(buffer);
buffer.flip();
assertEquals("Serialization count", 3, count);
assertType(buffer, 16, 0);
assertEquals("WeakAnd arity", 2, buffer.get());
assertEquals("WeakAnd N", 100, buffer.getShort() & 0x3fff);
assertEquals(0, buffer.get());
assertWord(buffer, "a");
assertWord(buffer, "b");
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class ItemEncodingTestCase method testONearItemEncoding.
@Test
public void testONearItemEncoding() {
WordItem a = new WordItem("a");
WordItem b = new WordItem("b");
NearItem onear = new ONearItem(7);
onear.addItem(a);
onear.addItem(b);
ByteBuffer buffer = ByteBuffer.allocate(128);
int count = onear.encode(buffer);
buffer.flip();
assertEquals("Serialization count", 3, count);
assertType(buffer, 12, 0);
assertEquals("Near arity", 2, buffer.get());
assertEquals("Limit", 7, buffer.get());
assertWord(buffer, "a");
assertWord(buffer, "b");
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class NormalizingSearcherTestCase method testPhraseSegmentNormalization.
@Test
public void testPhraseSegmentNormalization() {
Query query = new Query("/search?query=&search=cluster1&restrict=type1");
PhraseSegmentItem phraseSegment = new PhraseSegmentItem("default", false, false);
phraseSegment.addItem(new WordItem("net"));
query.getModel().getQueryTree().setRoot(phraseSegment);
assertEquals("'net'", query.getModel().getQueryTree().getRoot().toString());
createExecution().search(query);
assertEquals("'net'", query.getModel().getQueryTree().getRoot().toString());
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class InputCheckingSearcher method countSingleCharacterUserTerms.
private int countSingleCharacterUserTerms(Item queryItem) {
if (queryItem instanceof CompositeItem) {
int sum = 0;
CompositeItem asComposite = (CompositeItem) queryItem;
for (ListIterator<Item> i = asComposite.getItemIterator(); i.hasNext(); ) {
sum += countSingleCharacterUserTerms(i.next());
}
return sum;
} else if (queryItem instanceof WordItem) {
WordItem word = (WordItem) queryItem;
return (word.isFromQuery() && word.stringValue().length() == 1) ? 1 : 0;
} else {
return 0;
}
}
Aggregations