use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class PeakQpsTestCase method checkSearch.
@Test
public void checkSearch() {
MeasureQpsConfig config = new MeasureQpsConfig(new MeasureQpsConfig.Builder().outputmethod(MeasureQpsConfig.Outputmethod.METAHIT).queryproperty("qpsprobe"));
Searcher s = new PeakQpsSearcher(config, Statistics.nullImplementation);
Chain<Searcher> c = new Chain<>(s);
Execution e = new Execution(c, Execution.Context.createContextStub());
e.search(new Query("/?query=a"));
new Execution(c, Execution.Context.createContextStub());
Result r = e.search(new Query("/?query=a&qpsprobe=true"));
final Hit hit = r.hits().get(0);
assertTrue(hit instanceof PeakQpsSearcher.QpsHit);
assertNotNull(hit.fields().get(PeakQpsSearcher.QpsHit.MEAN_QPS));
assertNotNull(hit.fields().get(PeakQpsSearcher.QpsHit.PEAK_QPS));
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class FieldFilterTestCase method setUp.
@Before
public void setUp() throws Exception {
Query query = new Query("?query=test");
Result result = new Result(query);
Hit hit = createHit("lastHit", .1d, FIELD_A, FIELD_B, FIELD_C);
result.hits().add(hit);
DocumentSourceSearcher mockBackend = new DocumentSourceSearcher();
mockBackend.addResult(query, result);
searchChain = new Chain<Searcher>(new FieldFilter(), mockBackend);
context = Execution.Context.createContextStub(null);
execution = new Execution(searchChain, context);
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class SearchHandler method handleBody.
private HttpSearchResponse handleBody(HttpRequest request) {
// Find query profile
String queryProfileName = request.getProperty("queryProfile");
CompiledQueryProfile queryProfile = queryProfileRegistry.findQueryProfile(queryProfileName);
boolean benchmarkOutput = VespaHeaders.benchmarkOutput(request);
// Create query
Query query = new Query(request, queryProfile);
boolean benchmarkCoverage = VespaHeaders.benchmarkCoverage(benchmarkOutput, request.getJDiscRequest().headers());
// Find and execute search chain if we have a valid query
String invalidReason = query.validate();
Chain<Searcher> searchChain = null;
String searchChainName = null;
if (invalidReason == null) {
Tuple2<String, Chain<Searcher>> nameAndChain = resolveChain(query.properties().getString(Query.SEARCH_CHAIN));
searchChainName = nameAndChain.first;
searchChain = nameAndChain.second;
}
// Create the result
Result result;
if (invalidReason != null) {
result = new Result(query, ErrorMessage.createIllegalQuery(invalidReason));
} else if (queryProfile == null && queryProfileName != null) {
result = new Result(query, ErrorMessage.createIllegalQuery("Could not resolve query profile '" + queryProfileName + "'"));
} else if (searchChain == null) {
result = new Result(query, ErrorMessage.createInvalidQueryParameter("No search chain named '" + searchChainName + "' was found"));
} else {
String pathAndQuery = UriTools.rawRequest(request.getUri());
result = search(pathAndQuery, query, searchChain, searchChainRegistry);
}
Renderer renderer;
if (result.getTemplating().usesDefaultTemplate()) {
renderer = toRendererCopy(query.getPresentation().getRenderer());
// pre-Vespa 6 Result.getEncoding() expects this to be set. TODO: Remove
result.getTemplating().setRenderer(renderer);
} else {
// somebody explicitly assigned a old style template
renderer = perRenderingCopy(result.getTemplating().getRenderer());
}
// Transform result to response
HttpSearchResponse response = new HttpSearchResponse(getHttpResponseStatus(request, result), result, query, renderer);
if (hostResponseHeaderKey.isPresent())
response.headers().add(hostResponseHeaderKey.get(), selfHostname);
if (benchmarkOutput)
VespaHeaders.benchmarkOutput(response.headers(), benchmarkCoverage, response.getTiming(), response.getHitCounts(), getErrors(result), response.getCoverage());
return response;
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class FederationSearcher method mergeResult.
private void mergeResult(Query query, Target target, Result mergedResults, Result result) {
target.modifyTargetResult(result);
ComponentId searchChainId = target.getId();
Chain<Searcher> searchChain = target.getChain();
mergedResults.mergeWith(result);
HitGroup group = result.hits();
group.setId("source:" + searchChainId.getName());
group.setSearcherSpecificMetaData(this, searchChain);
// Set hit groups as non-meta as a default
group.setMeta(false);
// Set hit group as auxiliary so that it doesn't contribute to count
group.setAuxiliary(true);
group.setSource(searchChainId.getName());
group.setQuery(result.getQuery());
for (Iterator<Hit> it = group.unorderedDeepIterator(); it.hasNext(); ) {
Hit hit = it.next();
hit.setSearcherSpecificMetaData(this, searchChain);
hit.setSource(searchChainId.stringValue());
// See HTTPBackendSearcher, where this hit is created
if (hit.isMeta() && hit.types().contains("logging")) {
// Augment this hit with count fields
hit.setField(LOG_COUNT_PREFIX + "deep", result.getDeepHitCount());
hit.setField(LOG_COUNT_PREFIX + "total", result.getTotalHitCount());
int offset = result.getQuery().getOffset();
hit.setField(LOG_COUNT_PREFIX + "first", offset + 1);
hit.setField(LOG_COUNT_PREFIX + "last", result.getConcreteHitCount() + offset);
}
}
if (query.getTraceLevel() >= 4)
query.trace("Got " + group.getConcreteSize() + " hits from " + group.getId(), false, 4);
mergedResults.hits().add(group);
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class SearcherUtils method allSearchers.
private static Collection<Searcher> allSearchers() {
SearchChainRegistry searchChainRegistry = getSearchHandler().getSearchChainRegistry();
ComponentRegistry<Searcher> searcherRegistry = searchChainRegistry.getSearcherRegistry();
return searcherRegistry.allComponents();
}
Aggregations