use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class FieldCollapsingSearcherTestCase method testFieldCollapsingWithGrouping.
@Test
public void testFieldCollapsingWithGrouping() {
// Set up
FieldCollapsingSearcher collapse = new FieldCollapsingSearcher("other");
DocumentSourceSearcher docsource = new DocumentSourceSearcher();
Chain<Searcher> chain = new Chain<>(collapse, new AddAggregationStyleGroupingResultSearcher(), docsource);
// Caveat: Collapse is set to false, because that's what the
// collapser asks for
Query q = new Query("?query=test_collapse&collapsefield=amid");
// The searcher turns off collapsing further on in the chain
q.properties().set("collapse", "0");
Result r = new Result(q);
r.hits().add(createHit("http://acme.org/a.html", 10, 0));
r.hits().add(createHit("http://acme.org/b.html", 9, 0));
r.hits().add(createHit("http://acme.org/c.html", 9, 1));
r.hits().add(createHit("http://acme.org/d.html", 8, 1));
r.hits().add(createHit("http://acme.org/e.html", 8, 2));
r.hits().add(createHit("http://acme.org/f.html", 7, 2));
r.hits().add(createHit("http://acme.org/g.html", 7, 3));
r.hits().add(createHit("http://acme.org/h.html", 6, 3));
r.setTotalHitCount(8);
docsource.addResult(q, r);
// Test basic collapsing on mid
Query query = new Query("?query=test_collapse&collapsefield=amid");
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
// Assert that the regular hits are collapsed
assertEquals(4 + 1, result.getHitCount());
assertEquals(1, docsource.getQueryCount());
assertHit("http://acme.org/a.html", 10, 0, result.hits().get(0));
assertHit("http://acme.org/c.html", 9, 1, result.hits().get(1));
assertHit("http://acme.org/e.html", 8, 2, result.hits().get(2));
assertHit("http://acme.org/g.html", 7, 3, result.hits().get(3));
// Assert that the aggregation group hierarchy is left intact
HitGroup root = getFirstGroupIn(result.hits());
assertNotNull(root);
// The id ends by a global counter currently
assertEquals("group:root:", root.getId().stringValue().substring(0, 11));
assertEquals(1, root.size());
HitGroup groupList = (GroupList) root.get("grouplist:g1");
assertNotNull(groupList);
assertEquals(1, groupList.size());
HitGroup group = (HitGroup) groupList.get("group:long:37");
assertNotNull(group);
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class JuniperSearcherTestCase method createResult.
private Result createResult(String sdName, String content, boolean bolding) {
Chain<Searcher> chain = createSearchChain(sdName, content);
Query query = new Query("?query=12");
if (!bolding)
query = new Query("?query=12&bolding=false");
Execution execution = createExecution(chain);
Result result = execution.search(query);
execution.fill(result);
return result;
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class QueryValidatingSearcherTestCase method testBasic.
public void testBasic() {
// Setup
Map<Searcher, Searcher> chained = new HashMap<>();
Query query = new Query("?query=test");
Result result = new Result(query);
result.hits().add(new Hit("ymail://1111111111/AQAAAP7JgwEAj6XjQQAAAO/+ggA=", 950));
Searcher validator = new QueryValidatingSearcher();
DocumentSourceSearcher source = new DocumentSourceSearcher();
chained.put(validator, source);
source.addResult(query, result);
// Exercise
Result returnedResult = doSearch(validator, query, 0, 10, chained);
// Validate
assertEquals(1, returnedResult.getHitCount());
assertNull(returnedResult.hits().getError());
returnedResult = doSearch(validator, query, 0, 1001, chained);
assertEquals(0, returnedResult.getConcreteHitCount());
assertEquals(4, returnedResult.hits().getError().getCode());
returnedResult = doSearch(validator, query, 1001, 10, chained);
assertEquals(0, returnedResult.getConcreteHitCount());
assertEquals(4, returnedResult.hits().getError().getCode());
}
use of com.yahoo.search.Searcher 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.search.Searcher in project vespa by vespa-engine.
the class PhrasingSearcherTestCase method testNoPhrasingIfDifferentIndices.
@Test
public void testNoPhrasingIfDifferentIndices() {
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", "anotherindex"));
query.getModel().getQueryTree().setRoot(andItem);
new Execution(searcher, Execution.Context.createContextStub()).search(query);
CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot();
assertTrue(item.getItem(0) instanceof WordItem);
WordItem word = (WordItem) item.getItem(0);
assertEquals("tudor", word.getWord());
assertTrue(item.getItem(1) instanceof WordItem);
word = (WordItem) item.getItem(1);
assertEquals("vidor", word.getWord());
}
Aggregations