use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class PhrasingSearcherTestCase method testNoFileNoChange.
@Test
public void testNoFileNoChange() {
Searcher searcher = new PhrasingSearcher("");
Query query = new Query();
AndItem andItem = new AndItem();
andItem.addItem(new WordItem("no", "anindex"));
andItem.addItem(new WordItem("such", "anindex"));
andItem.addItem(new WordItem("phrase", "indexo"));
OrItem orItem = new OrItem();
orItem.addItem(new WordItem("habla"));
orItem.addItem(new WordItem("babla"));
orItem.addItem(new WordItem("habla"));
andItem.addItem(orItem);
query.getModel().getQueryTree().setRoot(andItem);
new Execution(searcher, Execution.Context.createContextStub()).search(query);
assertEquals("AND anindex:no anindex:such indexo:phrase (OR habla babla habla)", query.getModel().getQueryTree().getRoot().toString());
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class PhrasingSearcherTestCase method testNoDetection.
@Test
public void testNoDetection() {
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("no"));
andItem.addItem(new WordItem("such"));
andItem.addItem(new WordItem("phrase"));
query.getModel().getQueryTree().setRoot(andItem);
new Execution(searcher, Execution.Context.createContextStub()).search(query);
assertEquals("AND no such phrase", query.getModel().getQueryTree().getRoot().toString());
}
use of com.yahoo.prelude.query.WordItem 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.WordItem in project vespa by vespa-engine.
the class QueryLanguageTestCase method testPhrase.
@Test
public void testPhrase() {
PhraseItem p = new PhraseItem();
p.addItem(new WordItem("part"));
p.addItem(new WordItem("of"));
p.addItem(new WordItem("phrase"));
assertEquals("\"part of phrase\"", p.toString());
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class QueryLanguageTestCase method testNotItem.
@Test
public void testNotItem() {
NotItem n = new NotItem();
n.addNegativeItem(new WordItem("notthis"));
n.addNegativeItem(new WordItem("andnotthis"));
n.addPositiveItem(new WordItem("butthis"));
assertEquals("+butthis -notthis -andnotthis", n.toString());
}
Aggregations