use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class ParseTestCase method testPlusWordWebParsing2.
@Test
public void testPlusWordWebParsing2() {
Item root = tester.assertParsed("AND a b", "+a +b", Query.Type.WEB);
assertTrue(((AndItem) root).getItem(0).isProtected());
assertTrue(((AndItem) root).getItem(1).isProtected());
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class ParseTestCase method testFakeCJKSegmenting.
@Test
public void testFakeCJKSegmenting() {
// "first" "second" and "third" are segments in the test language
Item item = tester.parseQuery("name:firstsecondthird", null, Language.CHINESE_SIMPLIFIED, Query.Type.ANY, TestLinguistics.INSTANCE);
assertTrue(item instanceof PhraseSegmentItem);
PhraseSegmentItem phrase = (PhraseSegmentItem) item;
assertEquals(3, phrase.getItemCount());
assertEquals("name:first", phrase.getItem(0).toString());
assertEquals("name:second", phrase.getItem(1).toString());
assertEquals("name:third", phrase.getItem(2).toString());
assertEquals("name", ((WordItem) phrase.getItem(0)).getIndexName());
assertEquals("name", ((WordItem) phrase.getItem(1)).getIndexName());
assertEquals("name", ((WordItem) phrase.getItem(2)).getIndexName());
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class PhrasingSearcherTestCase method testTotalPhrasing.
@Test
public void testTotalPhrasing() {
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("vidor", "someindex"));
query.getModel().getQueryTree().setRoot(andItem);
new Execution(searcher, Execution.Context.createContextStub()).search(query);
Item item = ((CompositeItem) query.getModel().getQueryTree().getRoot()).getItem(0);
assertTrue(item instanceof PhraseItem);
PhraseItem phrase = (PhraseItem) item;
assertEquals(2, phrase.getItemCount());
assertEquals("tudor", phrase.getWordItem(0).getWord());
assertEquals("vidor", phrase.getWordItem(1).getWord());
assertEquals("someindex", phrase.getIndexName());
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class RecallSearcherTestCase method assertQueryTree.
private static void assertQueryTree(String query, List<String> ranked, List<String> unranked) {
RecallSearcher searcher = new RecallSearcher();
Query obj = new Query(query);
Result result = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())).search(obj);
if (result.hits().getError() != null) {
fail(result.hits().getError().toString());
}
List<String> myRanked = new ArrayList<>(ranked);
List<String> myUnranked = new ArrayList<>(unranked);
Stack<Item> stack = new Stack<>();
stack.push(obj.getModel().getQueryTree().getRoot());
while (!stack.isEmpty()) {
Item item = stack.pop();
if (item instanceof WordItem) {
String word = ((WordItem) item).getWord();
if (item.isRanked()) {
int idx = myRanked.indexOf(word);
if (idx < 0) {
fail("Term '" + word + "' not expected as ranked term.");
}
myRanked.remove(idx);
} else {
int idx = myUnranked.indexOf(word);
if (idx < 0) {
fail("Term '" + word + "' not expected as unranked term.");
}
myUnranked.remove(idx);
}
}
if (item instanceof CompositeItem) {
CompositeItem lst = (CompositeItem) item;
for (Iterator<?> it = lst.getItemIterator(); it.hasNext(); ) {
stack.push((Item) it.next());
}
}
}
if (!myRanked.isEmpty()) {
fail("Ranked terms " + myRanked + " not found.");
}
if (!myUnranked.isEmpty()) {
fail("Unranked terms " + myUnranked + " not found.");
}
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class CollapsePhraseSearcherTestCase method transformQuery.
private String transformQuery(String rawQuery) {
CollapsePhraseSearcher searcher = new CollapsePhraseSearcher();
Query query = new Query(rawQuery);
new Execution(searcher, Execution.Context.createContextStub()).search(query);
Item newRoot = query.getModel().getQueryTree().getRoot();
if (newRoot != null)
return newRoot.toString();
else
return null;
}
Aggregations