Search in sources :

Example 26 with FastHit

use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.

the class FieldCollapsingSearcher method collapse.

/**
 * Collapse logic. Preserves only maxHitsPerField hits
 * for each unique value of the collapsing parameter.
 */
private void collapse(Result result, Map<String, Integer> knownCollapses, Result resultSource, String collapseField, int collapseSize) {
    for (Iterator<Hit> it = resultSource.hits().iterator(); it.hasNext(); ) {
        Hit unknownHit = it.next();
        if (!(unknownHit instanceof FastHit)) {
            result.hits().add(unknownHit);
            continue;
        }
        FastHit hit = (FastHit) unknownHit;
        Object peek = hit.getField(collapseField);
        String collapseId = peek != null ? peek.toString() : null;
        if (collapseId == null) {
            result.hits().add(hit);
            continue;
        }
        if (knownCollapses.containsKey(collapseId)) {
            int numHitsThisField = knownCollapses.get(collapseId).intValue();
            if (numHitsThisField < collapseSize) {
                result.hits().add(hit);
                ++numHitsThisField;
                knownCollapses.put(collapseId, new Integer(numHitsThisField));
            }
        } else {
            knownCollapses.put(collapseId, new Integer(1));
            result.hits().add(hit);
        }
    }
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) FastHit(com.yahoo.prelude.fastsearch.FastHit)

Example 27 with FastHit

use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.

the class JSONDebugSearcher method search.

public Result search(com.yahoo.search.Query query, Execution execution) {
    Result r = execution.search(query);
    String propertyName = query.properties().getString(PROPERTYNAME);
    if (propertyName != null) {
        execution.fill(r);
        for (Iterator<Hit> i = r.hits().deepIterator(); i.hasNext(); ) {
            Hit h = i.next();
            if (h instanceof FastHit) {
                FastHit hit = (FastHit) h;
                Object o = hit.getField(propertyName);
                if (o instanceof JSONString) {
                    JSONString j = (JSONString) o;
                    r.getQuery().trace(JSON_FIELD + j.getContent(), false, 5);
                }
                if (o instanceof StructuredData) {
                    StructuredData d = (StructuredData) o;
                    r.getQuery().trace(STRUCT_FIELD + d.toJson(), false, 5);
                }
                if (o instanceof FeatureData) {
                    FeatureData d = (FeatureData) o;
                    r.getQuery().trace(FEATURE_FIELD + d.toJson(), false, 5);
                }
            }
        }
    }
    return r;
}
Also used : Hit(com.yahoo.search.result.Hit) FastHit(com.yahoo.prelude.fastsearch.FastHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) StructuredData(com.yahoo.search.result.StructuredData) FeatureData(com.yahoo.search.result.FeatureData) JSONString(com.yahoo.prelude.hitfield.JSONString) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result)

Example 28 with FastHit

use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.

the class QuotingSearcher method search.

public Result search(Query query, Execution execution) {
    Result result = execution.search(query);
    execution.fill(result);
    QuoteTable translations = getQuoteTable();
    if (translations == null || translations.isEmpty()) {
        return result;
    }
    for (Iterator<Hit> i = result.hits().deepIterator(); i.hasNext(); ) {
        Hit h = i.next();
        if (h instanceof FastHit) {
            quoteProperties((FastHit) h, translations);
        }
    }
    return result;
}
Also used : Hit(com.yahoo.search.result.Hit) FastHit(com.yahoo.prelude.fastsearch.FastHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) Result(com.yahoo.search.Result)

Example 29 with FastHit

use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.

the class HitConverter method convertFs4Hit.

private Hit convertFs4Hit(String summaryClass, FS4Hit groupHit) {
    FastHit hit = new FastHit();
    hit.setRelevance(groupHit.getRank());
    hit.setGlobalId(groupHit.getGlobalId());
    hit.setPartId(groupHit.getPath(), 0);
    hit.setDistributionKey(groupHit.getDistributionKey());
    hit.setFillable();
    hit.setSearcherSpecificMetaData(searcher, summaryClass);
    Hit ctxHit = (Hit) groupHit.getContext();
    if (ctxHit == null) {
        throw new NullPointerException("Hit has no context.");
    }
    hit.setSource(ctxHit.getSource());
    hit.setSourceNumber(ctxHit.getSourceNumber());
    hit.setQuery(ctxHit.getQuery());
    if (ctxHit instanceof GroupingListHit) {
        // in a live system the ctxHit can only by GroupingListHit, but because the code used Hit prior to version
        // 5.10 we need to check to avoid breaking existing unit tests -- both internally and with customers
        QueryPacketData queryPacketData = ((GroupingListHit) ctxHit).getQueryPacketData();
        if (queryPacketData != null) {
            hit.setQueryPacketData(queryPacketData);
        }
    }
    return hit;
}
Also used : FS4Hit(com.yahoo.searchlib.aggregation.FS4Hit) Hit(com.yahoo.search.result.Hit) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) VdsHit(com.yahoo.searchlib.aggregation.VdsHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) QueryPacketData(com.yahoo.fs4.QueryPacketData) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit)

Example 30 with FastHit

use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.

the class Dispatcher method toSlime.

private static Slime toSlime(String rankProfile, String summaryClass, String docType, SessionId sessionId, List<FastHit> hits) {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    if (summaryClass != null) {
        root.setString("class", summaryClass);
    }
    if (sessionId != null) {
        root.setData("sessionid", sessionId.asUtf8String().getBytes());
    }
    if (docType != null) {
        root.setString("doctype", docType);
    }
    if (rankProfile != null) {
        root.setString("ranking", rankProfile);
    }
    Cursor gids = root.setArray("gids");
    for (FastHit hit : hits) {
        gids.addData(hit.getGlobalId().getRawId());
    }
    return slime;
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Aggregations

FastHit (com.yahoo.prelude.fastsearch.FastHit)51 Result (com.yahoo.search.Result)21 Query (com.yahoo.search.Query)20 Test (org.junit.Test)20 Hit (com.yahoo.search.result.Hit)19 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)9 Relevance (com.yahoo.search.result.Relevance)8 Searcher (com.yahoo.search.Searcher)7 DocumentSourceSearcher (com.yahoo.prelude.searcher.DocumentSourceSearcher)6 Execution (com.yahoo.search.searchchain.Execution)5 FS4Hit (com.yahoo.searchlib.aggregation.FS4Hit)5 VdsHit (com.yahoo.searchlib.aggregation.VdsHit)5 JSONString (com.yahoo.prelude.hitfield.JSONString)4 QuotingSearcher (com.yahoo.prelude.searcher.QuotingSearcher)4 Utf8String (com.yahoo.text.Utf8String)4 HashMap (java.util.HashMap)4 ByteWriter (com.yahoo.io.ByteWriter)3 DocsumDefinitionSet (com.yahoo.prelude.fastsearch.DocsumDefinitionSet)3 Coverage (com.yahoo.search.result.Coverage)3 HitGroup (com.yahoo.search.result.HitGroup)3