Search in sources :

Example 6 with Result

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

the class SimpleSearcher method search.

public Result search(Query query, Execution execution) {
    try {
        BooleanParser.parseBoolean("true");
        XMLString xmlString = new XMLString("<sampleXmlString/>");
        Hit hit = new Hit("Hello world!");
        hit.setField("json", new JSONObject().put("price", 42).toString());
        Result result = execution.search(query);
        result.hits().add(hit);
        return result;
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}
Also used : Hit(com.yahoo.search.result.Hit) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) XMLString(com.yahoo.prelude.hitfield.XMLString) Result(com.yahoo.search.Result)

Example 7 with Result

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

the class ClusterSearcher method searchMultipleDocumentTypes.

private Result searchMultipleDocumentTypes(Searcher searcher, Query query, Execution execution) {
    Set<String> docTypes = resolveDocumentTypes(query, execution.context().getIndexFacts());
    Result invalidRankProfile = checkValidRankProfiles(query, docTypes);
    if (invalidRankProfile != null) {
        return invalidRankProfile;
    }
    List<Query> queries = createQueries(query, docTypes);
    if (queries.size() == 1) {
        return searcher.search(queries.get(0), execution);
    } else {
        Result mergedResult = new Result(query.clone());
        for (Query q : queries) {
            Result result = searcher.search(q, execution);
            mergedResult.mergeWith(result);
            mergedResult.hits().addAll(result.hits().asUnorderedHits());
        }
        // Should we trim the merged result?
        if (query.getOffset() > 0 || query.getHits() < mergedResult.hits().size()) {
            if (mergedResult.getHitOrderer() != null) {
                // Make sure we have the necessary data for sorting
                searcher.fill(mergedResult, Execution.ATTRIBUTEPREFETCH, execution);
            }
            mergedResult.hits().trim(query.getOffset(), query.getHits());
        }
        return mergedResult;
    }
}
Also used : Query(com.yahoo.search.Query) Result(com.yahoo.search.Result)

Example 8 with Result

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

the class VespaBackEndSearcher method cacheLookupFirstPhase.

private Result cacheLookupFirstPhase(CacheKey key, QueryPacketData queryPacketData, Query query, int offset, int hits, String summaryClass) {
    PacketWrapper packetWrapper = cacheControl.lookup(key, query);
    if (packetWrapper == null)
        return null;
    // Check if the cache entry contains the requested hits
    List<DocumentInfo> documents = packetWrapper.getDocuments(offset, hits);
    if (documents == null)
        return null;
    if (query.getPresentation().getSummary() == null)
        query.getPresentation().setSummary(getDefaultDocsumClass());
    Result result = new Result(query);
    QueryResultPacket resultPacket = packetWrapper.getFirstResultPacket();
    addMetaInfo(query, queryPacketData, resultPacket, result, true);
    if (packetWrapper.getNumPackets() == 0)
        addUnfilledHits(result, documents, true, queryPacketData, key);
    else
        addCachedHits(result, packetWrapper, summaryClass, documents);
    return result;
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) DocumentInfo(com.yahoo.fs4.DocumentInfo) Result(com.yahoo.search.Result)

Example 9 with Result

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

the class DocumentSourceSearcher method addDefaultResults.

private void addDefaultResults() {
    Query q = new Query("?query=default");
    Result r = new Result(q);
    r.hits().add(new Hit("http://default-1.html"));
    r.hits().add(new Hit("http://default-2.html"));
    r.hits().add(new Hit("http://default-3.html"));
    r.hits().add(new Hit("http://default-4.html"));
    defaultFilledResult = r;
    addResultSet(q, r);
}
Also used : Hit(com.yahoo.search.result.Hit) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result)

Example 10 with Result

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

the class DocumentSourceSearcher method fill.

@Override
public void fill(com.yahoo.search.Result result, String summaryClass, Execution execution) {
    Result filledResult;
    if ("attributeprefetch".equals(summaryClass))
        filledResult = attributeFilledResults.get(getQueryKeyClone(result.getQuery()));
    else
        filledResult = completelyFilledResults.get(getQueryKeyClone(result.getQuery()));
    if (filledResult == null) {
        filledResult = defaultFilledResult;
    }
    fillHits(filledResult, result, summaryClass);
}
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