Search in sources :

Example 61 with Hit

use of com.yahoo.search.result.Hit 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 62 with Hit

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

the class FastSearcher method getPacketKeys.

/**
 * Returns an array of the hits contained in this result
 *
 * @param filled true to return all hits, false to return only unfilled hits
 * @return array of docids, empty array if no hits
 */
private DocsumPacketKey[] getPacketKeys(Result result, String summaryClass, boolean filled) {
    DocsumPacketKey[] packetKeys = new DocsumPacketKey[result.getHitCount()];
    int x = 0;
    for (Iterator<com.yahoo.search.result.Hit> i = hitIterator(result); i.hasNext(); ) {
        com.yahoo.search.result.Hit hit = i.next();
        if (hit instanceof FastHit) {
            FastHit fastHit = (FastHit) hit;
            if (filled || !fastHit.isFilled(summaryClass)) {
                packetKeys[x] = new DocsumPacketKey(fastHit.getGlobalId(), fastHit.getPartId(), summaryClass);
                x++;
            }
        }
    }
    if (x < packetKeys.length) {
        DocsumPacketKey[] tmp = new DocsumPacketKey[x];
        System.arraycopy(packetKeys, 0, tmp, 0, x);
        return tmp;
    } else {
        return packetKeys;
    }
}
Also used : Hit(com.yahoo.search.result.Hit) Hit(com.yahoo.search.result.Hit)

Example 63 with Hit

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

the class VespaBackEndSearcher method fillHits.

/**
 * Fills the hits.
 *
 * @return the number of hits that we did not return data for, and an optional error message.
 *         when things are working normally we return 0.
 */
protected FillHitsResult fillHits(Result result, Packet[] packets, String summaryClass) throws IOException {
    int skippedHits = 0;
    String lastError = null;
    int packetIndex = 0;
    for (Iterator<Hit> i = hitIterator(result); i.hasNext(); ) {
        Hit hit = i.next();
        if (hit instanceof FastHit && !hit.isFilled(summaryClass)) {
            FastHit fastHit = (FastHit) hit;
            ensureInstanceOf(DocsumPacket.class, packets[packetIndex], getName());
            DocsumPacket docsum = (DocsumPacket) packets[packetIndex];
            packetIndex++;
            FillHitResult fr = fillHit(fastHit, docsum, summaryClass);
            if (!fr.ok) {
                skippedHits++;
            }
            if (fr.error != null) {
                result.hits().addError(ErrorMessage.createTimeout(fr.error));
                skippedHits++;
                lastError = fr.error;
            }
        }
    }
    result.hits().setSorted(false);
    return new FillHitsResult(skippedHits, lastError);
}
Also used : ErrorHit(com.yahoo.search.result.ErrorHit) Hit(com.yahoo.search.result.Hit) DocsumPacket(com.yahoo.fs4.DocsumPacket)

Example 64 with Hit

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

the class VespaBackEndSearcher method partitionHits.

private List<Result> partitionHits(Result result, String summaryClass) {
    List<Result> parts = new ArrayList<>();
    TinyIdentitySet<Query> queryMap = new TinyIdentitySet<>(4);
    for (Iterator<Hit> i = hitIterator(result); i.hasNext(); ) {
        Hit hit = i.next();
        if (hit instanceof FastHit) {
            FastHit fastHit = (FastHit) hit;
            if (!fastHit.isFilled(summaryClass)) {
                Query q = fastHit.getQuery();
                if (q == null) {
                    // fallback for untagged hits
                    q = result.hits().getQuery();
                }
                int idx = queryMap.indexOf(q);
                if (idx < 0) {
                    idx = queryMap.size();
                    Result r = new Result(q);
                    parts.add(r);
                    queryMap.add(q);
                }
                parts.get(idx).hits().add(fastHit);
            }
        }
    }
    return parts;
}
Also used : ErrorHit(com.yahoo.search.result.ErrorHit) Hit(com.yahoo.search.result.Hit) Query(com.yahoo.search.Query) ArrayList(java.util.ArrayList) TinyIdentitySet(com.yahoo.collections.TinyIdentitySet) Result(com.yahoo.search.Result)

Example 65 with Hit

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

the class DocumentSourceSearcher method fillHits.

private void fillHits(Result source, Result target, String summaryClass) {
    for (Iterator hitsToFill = target.hits().deepIterator(); hitsToFill.hasNext(); ) {
        Hit hitToFill = (Hit) hitsToFill.next();
        String summaryId = (String) hitToFill.getField("summaryid");
        // Can not fill this
        if (summaryId == null)
            continue;
        Hit filledHit = lookupBySummaryId(source, summaryId);
        if (filledHit == null)
            throw new RuntimeException("Can't fill hit with summaryid '" + summaryId + "', not present");
        for (Iterator props = filledHit.fieldIterator(); props.hasNext(); ) {
            Map.Entry propertyEntry = (Map.Entry) props.next();
            hitToFill.setField(propertyEntry.getKey().toString(), propertyEntry.getValue());
        }
        hitToFill.setFilled(summaryClass);
    }
    target.analyzeHits();
}
Also used : Hit(com.yahoo.search.result.Hit) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Hit (com.yahoo.search.result.Hit)127 Result (com.yahoo.search.Result)72 Query (com.yahoo.search.Query)52 FastHit (com.yahoo.prelude.fastsearch.FastHit)42 Test (org.junit.Test)41 Execution (com.yahoo.search.searchchain.Execution)25 HitGroup (com.yahoo.search.result.HitGroup)21 Searcher (com.yahoo.search.Searcher)17 JSONString (com.yahoo.prelude.hitfield.JSONString)13 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)12 ErrorHit (com.yahoo.search.result.ErrorHit)10 Relevance (com.yahoo.search.result.Relevance)10 HashMap (java.util.HashMap)9 DocumentSourceSearcher (com.yahoo.prelude.searcher.DocumentSourceSearcher)8 Group (com.yahoo.search.grouping.result.Group)8 ComponentId (com.yahoo.component.ComponentId)7 Chain (com.yahoo.component.chain.Chain)7 FS4Hit (com.yahoo.searchlib.aggregation.FS4Hit)6 VdsHit (com.yahoo.searchlib.aggregation.VdsHit)6 GroupList (com.yahoo.search.grouping.result.GroupList)5