use of com.yahoo.search.searchchain.Execution 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.search.searchchain.Execution in project vespa by vespa-engine.
the class RecallSearcherTestCase method testDenyRankItems.
@Test
public void testDenyRankItems() {
RecallSearcher searcher = new RecallSearcher();
Query query = new Query("?recall=foo");
Result result = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())).search(query);
assertNotNull(result.hits().getError());
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class RecallSearcherTestCase method testIgnoreEmptyProperty.
@Test
public void testIgnoreEmptyProperty() {
RecallSearcher searcher = new RecallSearcher();
Query query = new Query();
Result result = new Execution(searcher, Execution.Context.createContextStub()).search(query);
assertNull(result.hits().getError());
assertTrue(query.getModel().getQueryTree().getRoot() instanceof NullItem);
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class BlendingSearcherTestCase method testOnlyFirstBackend.
@Test
public void testOnlyFirstBackend() {
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana&search=first");
Result result = new Execution(searcher, Execution.Context.createContextStub()).search(query);
assertEquals(1, result.getHitCount());
assertEquals(200.0, result.hits().get(0).getRelevance().getScore(), delta);
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class BlendingSearcherTestCase method testExistingAndNonExistingBackendCausesBothErrorAndResult.
@Test
public void testExistingAndNonExistingBackendCausesBothErrorAndResult() {
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana&search=first,nonesuch,second");
Result result = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())).search(query);
assertEquals(3, result.getConcreteHitCount());
assertEquals(300.0, result.hits().get(1).getRelevance().getScore(), delta);
assertEquals(200.0, result.hits().get(2).getRelevance().getScore(), delta);
assertEquals(100.0, result.hits().get(3).getRelevance().getScore(), delta);
assertNotNull(result.hits().getError());
ErrorMessage e = result.hits().getError();
// TODO: Do not depend on sources order
assertEquals("Could not resolve source ref 'nonesuch'. Valid source refs are first, second.", e.getDetailedMessage());
}
Aggregations