Search in sources :

Example 66 with Searcher

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));
}
Also used : Chain(com.yahoo.component.chain.Chain) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 67 with Searcher

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);
}
Also used : Hit(com.yahoo.search.result.Hit) FastHit(com.yahoo.prelude.fastsearch.FastHit) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) Searcher(com.yahoo.search.Searcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) Result(com.yahoo.search.Result) Before(org.junit.Before)

Example 68 with Searcher

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;
}
Also used : Chain(com.yahoo.component.chain.Chain) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) Renderer(com.yahoo.processing.rendering.Renderer) Result(com.yahoo.search.Result)

Example 69 with Searcher

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);
}
Also used : Hit(com.yahoo.search.result.Hit) Searcher(com.yahoo.search.Searcher) ForkingSearcher(com.yahoo.search.searchchain.ForkingSearcher) ComponentId(com.yahoo.component.ComponentId) HitGroup(com.yahoo.search.result.HitGroup)

Example 70 with Searcher

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();
}
Also used : ClusterSearcher(com.yahoo.prelude.cluster.ClusterSearcher) Searcher(com.yahoo.search.Searcher) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry)

Aggregations

Searcher (com.yahoo.search.Searcher)130 Result (com.yahoo.search.Result)94 Execution (com.yahoo.search.searchchain.Execution)88 Query (com.yahoo.search.Query)82 Test (org.junit.Test)74 Chain (com.yahoo.component.chain.Chain)57 FeedContext (com.yahoo.feedapi.FeedContext)20 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)20 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)20 ClusterList (com.yahoo.vespaclient.ClusterList)20 Hit (com.yahoo.search.result.Hit)17 DocumentSourceSearcher (com.yahoo.search.searchchain.testutil.DocumentSourceSearcher)14 HashMap (java.util.HashMap)14 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)13 FederationSearcher (com.yahoo.search.federation.FederationSearcher)11 FieldCollapsingSearcher (com.yahoo.prelude.searcher.FieldCollapsingSearcher)10 ArrayList (java.util.ArrayList)10 AsyncExecution (com.yahoo.search.searchchain.AsyncExecution)9 ComponentId (com.yahoo.component.ComponentId)8 FastHit (com.yahoo.prelude.fastsearch.FastHit)8