use of com.yahoo.search.result.Hit 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.result.Hit in project vespa by vespa-engine.
the class HTTPClientSearcher method doHttpRequest.
private Hit doHttpRequest(Query query, Connection connection) {
URI uri;
// Create default meta hit for holding logging information
Hit requestMeta = createRequestMeta();
query.properties().set(REQUEST_META_CARRIER, requestMeta);
query.trace("Created request information hit", false, 9);
try {
uri = getURI(query, connection);
} catch (MalformedURLException e) {
query.errors().add(createMalformedUrlError(query, e));
return requestMeta;
} catch (URISyntaxException e) {
query.errors().add(createMalformedUrlError(query, e));
return requestMeta;
}
HttpEntity entity;
try {
if (query.getTraceLevel() >= 1)
query.trace("Fetching " + uri.toString(), false, 1);
entity = getEntity(uri, requestMeta, query);
} catch (IOException e) {
query.errors().add(ErrorMessage.createBackendCommunicationError("Error when trying to connect to HTTP backend in " + this + " using " + connection + " for " + query + ": " + Exceptions.toMessageString(e)));
return requestMeta;
} catch (TimeoutException e) {
query.errors().add(ErrorMessage.createTimeout("HTTP traffic timed out in " + this + " for " + query + ": " + e.getMessage()));
return requestMeta;
}
if (entity == null) {
query.errors().add(ErrorMessage.createBackendCommunicationError("No result from connecting to HTTP backend in " + this + " using " + connection + " for " + query));
return requestMeta;
}
try {
query = handleResponse(entity, query);
} catch (IOException e) {
query.errors().add(ErrorMessage.createBackendCommunicationError("Error when trying to consume input in " + this + ": " + Exceptions.toMessageString(e)));
} finally {
cleanupHttpEntity(entity);
}
return requestMeta;
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class Dispatcher method hitsByNode.
/**
* Return a map of hits by their search node (partition) id
*/
private static ListMap<Integer, FastHit> hitsByNode(Result result) {
ListMap<Integer, FastHit> hitsByPartition = new ListMap<>();
for (Iterator<Hit> i = result.hits().unorderedDeepIterator(); i.hasNext(); ) {
Hit h = i.next();
if (!(h instanceof FastHit))
continue;
FastHit hit = (FastHit) h;
hitsByPartition.put(hit.getDistributionKey(), hit);
}
return hitsByPartition;
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class PageTemplateSet method hit.
@Override
public void hit(Context context, XMLWriter writer) throws IOException {
Hit hit = (Hit) context.get("hit");
if (!hit.isMeta() && !writer.isIn("content"))
writer.openTag("content");
super.hit(context, writer);
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class GroupedResultTestCase method testGroupedResult.
public void testGroupedResult() {
Result result = new Result(new Query("?query=foo"));
HitGroup hitGroup1 = new HitGroup("group1", 300);
hitGroup1.add(new Hit("group1.1", 200));
HitGroup hitGroup2 = new HitGroup("group2", 600);
Hit topLevelHit1 = new Hit("toplevel.1", 500);
Hit topLevelHit2 = new Hit("toplevel.2", 700);
result.hits().add(hitGroup1);
result.hits().add(topLevelHit1);
result.hits().add(hitGroup2);
result.hits().add(topLevelHit2);
hitGroup1.add(new Hit("group1.2", 800));
hitGroup2.add(new Hit("group2.1", 800));
hitGroup2.add(new Hit("group2.2", 300));
hitGroup2.add(new Hit("group2.3", 500));
// Should have 7 concrete hits, ordered as
// toplevel.2
// group2
// group2.1
// group2.3
// group2.2
// toplevel.1
// group1
// group1.2
// group1.1
// Assert this:
assertEquals(7, result.getConcreteHitCount());
assertEquals(4, result.getHitCount());
Hit topLevel2 = result.hits().get(0);
assertEquals("toplevel.2", topLevel2.getId().stringValue());
HitGroup returnedGroup2 = (HitGroup) result.hits().get(1);
assertEquals(3, returnedGroup2.getConcreteSize());
assertEquals(3, returnedGroup2.size());
assertEquals("group2.1", returnedGroup2.get(0).getId().stringValue());
assertEquals("group2.3", returnedGroup2.get(1).getId().stringValue());
assertEquals("group2.2", returnedGroup2.get(2).getId().stringValue());
Hit topLevel1 = result.hits().get(2);
assertEquals("toplevel.1", topLevel1.getId().stringValue());
HitGroup returnedGroup1 = (HitGroup) result.hits().get(3);
assertEquals(2, returnedGroup1.getConcreteSize());
assertEquals(2, returnedGroup1.size());
assertEquals("group1.2", returnedGroup1.get(0).getId().stringValue());
assertEquals("group1.1", returnedGroup1.get(1).getId().stringValue());
}
Aggregations