use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class FederationSearcher method fill.
@Override
public void fill(Result result, String summaryClass, Execution execution) {
UniqueExecutionsToResults uniqueExecutionsToResults = new UniqueExecutionsToResults();
addResultsToFill(result.hits(), result, summaryClass, uniqueExecutionsToResults);
Set<Entry<Chain<Searcher>, Map<Query, Result>>> resultsForAllChains = uniqueExecutionsToResults.resultsToFill.entrySet();
int numberOfCallsToFillNeeded = 0;
for (Entry<Chain<Searcher>, Map<Query, Result>> resultsToFillForAChain : resultsForAllChains) {
numberOfCallsToFillNeeded += resultsToFillForAChain.getValue().size();
}
List<Pair<Result, FutureResult>> futureFilledResults = new ArrayList<>();
for (Entry<Chain<Searcher>, Map<Query, Result>> resultsToFillForAChain : resultsForAllChains) {
Chain<Searcher> chain = resultsToFillForAChain.getKey();
Execution chainExecution = (chain == null) ? execution : new Execution(chain, execution.context());
for (Entry<Query, Result> resultsToFillForAChainAndQuery : resultsToFillForAChain.getValue().entrySet()) {
Result resultToFill = resultsToFillForAChainAndQuery.getValue();
if (numberOfCallsToFillNeeded == 1) {
chainExecution.fill(resultToFill, summaryClass);
propagateErrors(resultToFill, result);
} else {
AsyncExecution asyncFill = new AsyncExecution(chainExecution);
futureFilledResults.add(new Pair<>(resultToFill, asyncFill.fill(resultToFill, summaryClass)));
}
}
}
for (Pair<Result, FutureResult> futureFilledResult : futureFilledResults) {
// futureFilledResult is a pair of a result to be filled and the future in which that same result is filled
Optional<Result> filledResult = futureFilledResult.getSecond().getIfAvailable(result.getQuery().getTimeLeft(), TimeUnit.MILLISECONDS);
if (filledResult.isPresent()) {
// fill completed
propagateErrors(filledResult.get(), result);
} else {
// fill timed out: Remove these hits as they are incomplete and may cause a race when accessed later
result.hits().addError(futureFilledResult.getSecond().createTimeoutError());
for (Iterator<Hit> i = futureFilledResult.getFirst().hits().unorderedDeepIterator(); i.hasNext(); ) {
// Note that some of these hits may be filled, but as the fill thread may still be working on them
// and we do not synchronize with it we need to discard all
Hit removed = result.hits().remove(i.next().getId());
}
}
}
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class FederationSearcher method getSearchChainGroup.
private Result getSearchChainGroup(Hit hit, Result result, UniqueExecutionsToResults uniqueExecutionsToResults) {
@SuppressWarnings("unchecked") Chain<Searcher> chain = (Chain<Searcher>) hit.getSearcherSpecificMetaData(this);
Query query = hit.getQuery() != null ? hit.getQuery() : result.getQuery();
return uniqueExecutionsToResults.get(chain, query);
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class SearchChainTextRepresentation method outputChain.
private void outputChain(IndentStringBuilder str, Chain<Searcher> chain) {
if (chain == null) {
str.append(" [Unresolved Searchchain]");
} else {
str.append(chain.getId()).append(" [Searchchain] ");
Block block = new Block(str);
for (Searcher searcher : chain.components()) outputSearcher(str, searcher);
block.close();
}
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class FastSearcherTestCase method testPing.
@Test
public void testPing() throws IOException, InterruptedException {
Logger.getLogger(FastSearcher.class.getName()).setLevel(Level.ALL);
BackendTestCase.MockServer server = new BackendTestCase.MockServer();
FS4ResourcePool listeners = new FS4ResourcePool(new Fs4Config(new Fs4Config.Builder()));
Backend backend = listeners.getBackend(server.host.getHostString(), server.host.getPort());
FastSearcher fastSearcher = new FastSearcher(backend, new FS4ResourcePool(1), new MockDispatcher(Collections.emptyList()), new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(0, 0.0d), documentdbInfoConfig);
server.dispatch.packetData = BackendTestCase.PONG;
server.dispatch.setNoChannel();
Chain<Searcher> chain = new Chain<>(fastSearcher);
Execution e = new Execution(chain, Execution.Context.createContextStub());
Pong pong = e.ping(new Ping());
assertTrue(pong.getPongPacket().isPresent());
assertEquals(127, pong.getPongPacket().get().getDocstamp());
backend.shutdown();
server.dispatch.socket.close();
server.dispatch.connection.close();
server.worker.join();
pong.setPingInfo("blbl");
assertEquals("Result of pinging using blbl", pong.toString());
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class PageTemplateSearcherTestCase method testSearcher.
public void testSearcher() {
PageTemplateSearcher s = new PageTemplateSearcher(createPageTemplateRegistry(), new FirstChoiceResolver());
Chain<Searcher> chain = new Chain<>(s, new MockFederator());
{
// No template specified, should use default
Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.resolver=native.deterministic"));
assertSources("source1 source2", result);
}
{
Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.id=oneSource&page.resolver=native.deterministic"));
assertSources("source1", result);
}
{
Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.id=twoSources&model.sources=source1&page.resolver=native.deterministic"));
assertSources("source1", result);
}
{
Query query = new Query("?query=foo&page.resolver=native.deterministic");
addIntentModelSpecifyingSource3(query);
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source1 source2", result);
}
{
Query query = new Query("?query=foo&page.id=twoSourcesAndAny&page.resolver=native.deterministic");
addIntentModelSpecifyingSource3(query);
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source1 source2 source3", result);
}
{
Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
addIntentModelSpecifyingSource3(query);
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source3", result);
}
{
Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertTrue(query.getModel().getSources().isEmpty());
assertNotNull(result.hits().get("source1"));
assertNotNull(result.hits().get("source2"));
assertNotNull(result.hits().get("source3"));
}
{
Query query = new Query("?query=foo&page.id=choiceOfSources&page.resolver=native.deterministic");
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source1 source2", "source2", result);
}
{
Query query = new Query("?query=foo&page.id=choiceOfSources&page.resolver=test.firstChoice");
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source1 source2", "source1", result);
}
{
// Specifying two templates, should pick the last
Query query = new Query("?query=foo&page.id=threeSources+oneSource&page.resolver=native.deterministic");
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source1 source2 source3", "source1", result);
}
{
// Specifying two templates as a list, should override the page.id setting
Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
query.properties().set("page.idList", Arrays.asList("oneSource", "threeSources"));
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source1 source2 source3", "source1 source2 source3", result);
}
{
try {
Query query = new Query("?query=foo&page.id=oneSource+choiceOfSources&page.resolver=noneSuch");
new Execution(chain, Execution.Context.createContextStub()).search(query);
fail("Expected exception");
} catch (IllegalArgumentException e) {
assertEquals("No page template resolver 'noneSuch'", e.getMessage());
}
}
}
Aggregations