Search in sources :

Example 21 with Result

use of com.yahoo.search.Result in project vespa by vespa-engine.

the class TiledTemplateSet method header.

@Override
public void header(Context context, XMLWriter writer) throws IOException {
    Result result = (Result) context.get("result");
    writer.xmlHeader(getRequestedEncoding(result.getQuery()));
    writer.openTag("result").attribute("version", "1.0");
    writer.attribute("layout", result.hits().getField("layout"));
    renderCoverageAttributes(result.getCoverage(false), writer);
    writer.closeStartTag();
    renderSectionContent(result.hits(), writer);
}
Also used : Result(com.yahoo.search.Result)

Example 22 with Result

use of com.yahoo.search.Result in project vespa by vespa-engine.

the class ClusterSearcher method search.

@Override
public final Result search(Query query, Execution execution) {
    int tries = 0;
    Hasher.NodeList<T> nodes = getHasher().getNodes();
    if (nodes.getNodeCount() == 0)
        return search(query, execution, ErrorMessage.createNoBackendsInService("No nodes in service in " + this + " (" + monitor.nodeMonitors().size() + " was configured, none is responding)"));
    int code = query.hashCode();
    Result result;
    T connection = getFirstConnection(nodes, code, tries, query);
    do {
        // The loop is in case there are other searchers available able to produce results
        if (connection == null)
            return search(query, execution, ErrorMessage.createNoBackendsInService("No in node could handle " + query + " according to " + hasher + " in " + this));
        if (timedOut(query))
            return new Result(query, ErrorMessage.createTimeout("No time left for searching"));
        if (query.getTraceLevel() >= 8)
            query.trace("Trying " + connection, false, 8);
        result = robustSearch(query, execution, connection);
        if (!shouldRetry(query, result))
            return result;
        if (query.getTraceLevel() >= 6)
            query.trace("Error from connection " + connection + " : " + result.hits().getError(), false, 6);
        if (result.hits().getError().getCode() == Error.TIMEOUT.code)
            // Retry is unlikely to help
            return result;
        log(LogLevel.FINER, "No result, checking for timeout.");
        tries++;
        connection = nodes.select(code, tries);
    } while (tries < nodes.getNodeCount());
    // only error result gets returned here.
    return result;
}
Also used : Result(com.yahoo.search.Result)

Example 23 with Result

use of com.yahoo.search.Result in project vespa by vespa-engine.

the class ResultBuilder method startDocument.

@Override
public void startDocument() throws SAXException {
    reset();
    result = new Result(query);
    hitGroups.addFirst(result.hits());
    location.addFirst(ResultPart.ROOT);
    return;
}
Also used : Result(com.yahoo.search.Result)

Example 24 with Result

use of com.yahoo.search.Result in project vespa by vespa-engine.

the class UniqueGroupingSearcher method dedupe.

/**
 * Until we can use the grouping pagination features in 5.1, we'll have to support offset
 * by simply requesting and discarding hit #0 up to hit #offset.
 */
private static Result dedupe(Query query, Execution execution, String dedupField) {
    Sorting sorting = query.getRanking().getSorting();
    if (sorting != null && sorting.fieldOrders().size() > 1) {
        query.trace("Can not use grouping for deduping with multi-level sorting.", 3);
        // we'd ever want to actually use it (and a bit harder to implement as well).
        return execution.search(query);
    }
    int hits = query.getHits();
    int offset = query.getOffset();
    int groupingHits = hits + offset;
    GroupingRequest groupingRequest = GroupingRequest.newInstance(query);
    groupingRequest.setRootOperation(buildGroupingExpression(dedupField, groupingHits, query.getPresentation().getSummary(), sorting));
    query.setHits(0);
    query.setOffset(0);
    Result result = execution.search(query);
    // query could have changed further down in the chain
    query = result.getQuery();
    query.setHits(hits);
    query.setOffset(offset);
    Group root = groupingRequest.getResultGroup(result);
    if (null == root) {
        String msg = "Result group not found for deduping grouping request, returning empty result.";
        query.trace(msg, 3);
        log.log(LogLevel.WARNING, msg);
        throw new IllegalStateException("Failed to produce deduped result set.");
    }
    // hide our tracks
    result.hits().remove(root.getId().toString());
    GroupList resultGroups = root.getGroupList(dedupField);
    if (resultGroups == null) {
        query.trace("Deduping grouping request returned no hits, returning empty result.", 3);
        return result;
    }
    // Make sure that .addAll() doesn't re-order the hits we copy from the grouping
    // framework. The groups are already in the order they should be.
    result.hits().setOrderer(NOP_ORDERER);
    result.hits().addAll(getRequestedHits(resultGroups, offset, hits));
    Long countField = (Long) root.getField(LABEL_COUNT);
    long count = countField != null ? countField : 0;
    result.setTotalHitCount(count);
    return result;
}
Also used : Group(com.yahoo.search.grouping.result.Group) GroupList(com.yahoo.search.grouping.result.GroupList) Sorting(com.yahoo.search.query.Sorting) Result(com.yahoo.search.Result)

Example 25 with Result

use of com.yahoo.search.Result in project vespa by vespa-engine.

the class PageTemplateSet method header.

@Override
public void header(Context context, XMLWriter writer) throws IOException {
    Result result = (Result) context.get("result");
    writer.xmlHeader(getRequestedEncoding(result.getQuery()));
    writer.openTag("page").attribute("version", "1.0").attribute("layout", result.hits().getField("layout"));
    renderCoverageAttributes(result.getCoverage(false), writer);
    writer.closeStartTag();
    renderSectionContent(result.hits(), writer);
}
Also used : Result(com.yahoo.search.Result)

Aggregations

Result (com.yahoo.search.Result)398 Test (org.junit.Test)231 Query (com.yahoo.search.Query)229 Execution (com.yahoo.search.searchchain.Execution)127 Searcher (com.yahoo.search.Searcher)94 Hit (com.yahoo.search.result.Hit)72 Chain (com.yahoo.component.chain.Chain)48 FastHit (com.yahoo.prelude.fastsearch.FastHit)36 HitGroup (com.yahoo.search.result.HitGroup)29 JSONString (com.yahoo.prelude.hitfield.JSONString)26 HashMap (java.util.HashMap)21 FeedContext (com.yahoo.feedapi.FeedContext)19 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)19 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)19 ClusterList (com.yahoo.vespaclient.ClusterList)19 ErrorMessage (com.yahoo.search.result.ErrorMessage)17 Choice (com.yahoo.search.pagetemplates.model.Choice)16 Organizer (com.yahoo.search.pagetemplates.engine.Organizer)15 DocumentSourceSearcher (com.yahoo.search.searchchain.testutil.DocumentSourceSearcher)15 DeterministicResolver (com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver)14