Search in sources :

Example 66 with Hit

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

the class DocumentSourceSearcher method addResultSet.

/**
 * Adds a result which can be returned either as empty,
 * filled or attribute only filled later.
 * Summary fields starting by "a" are attributes, others are not.
 *
 * @return true when replacing an existing <query, result> pair.
 */
public boolean addResultSet(Query query, Result fullResult) {
    Result emptyResult = new Result(query.clone());
    Result attributeResult = new Result(query.clone());
    emptyResult.setTotalHitCount(fullResult.getTotalHitCount());
    attributeResult.setTotalHitCount(fullResult.getTotalHitCount());
    int counter = 0;
    for (Iterator i = fullResult.hits().deepIterator(); i.hasNext(); ) {
        Hit fullHit = (Hit) i.next();
        Hit emptyHit = fullHit.clone();
        emptyHit.clearFields();
        emptyHit.setFillable();
        emptyHit.setRelevance(fullHit.getRelevance());
        Hit attributeHit = fullHit.clone();
        removePropertiesNotStartingByA(attributeHit);
        attributeHit.setFillable();
        attributeHit.setRelevance(fullHit.getRelevance());
        for (Object propertyKeyObject : (Set) fullHit.fields().keySet()) {
            String propertyKey = propertyKeyObject.toString();
            if (propertyKey.startsWith("attribute"))
                attributeHit.setField(propertyKey, fullHit.getField(propertyKey));
        }
        if (fullHit.getField(Hit.SDDOCNAME_FIELD) != null)
            attributeHit.setField(Hit.SDDOCNAME_FIELD, fullHit.getField(Hit.SDDOCNAME_FIELD));
        // A simple summary lookup mechanism, similar to FastSearch's
        emptyHit.setField("summaryid", String.valueOf(counter));
        attributeHit.setField("summaryid", String.valueOf(counter));
        fullHit.setField("summaryid", String.valueOf(counter));
        counter++;
        emptyResult.hits().add(emptyHit);
        attributeResult.hits().add(attributeHit);
    }
    unFilledResults.put(getQueryKeyClone(query), emptyResult);
    attributeFilledResults.put(getQueryKeyClone(query), attributeResult);
    if (completelyFilledResults.put(getQueryKeyClone(query), fullResult.clone()) != null) {
        setEditionTimeStamp(System.currentTimeMillis());
        return true;
    }
    return false;
}
Also used : Hit(com.yahoo.search.result.Hit) Set(java.util.Set) Iterator(java.util.Iterator) Result(com.yahoo.search.Result)

Example 67 with Hit

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

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

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

the class QuerySnapshotSearcher method search.

public Result search(Query query, Execution execution) {
    Query q = query.clone();
    Result r = execution.search(query);
    Hit h = new Hit("meta:querysnapshot", new Relevance(Double.POSITIVE_INFINITY));
    h.setMeta(true);
    h.setField("query", q);
    r.hits().add(h);
    return r;
}
Also used : Relevance(com.yahoo.search.result.Relevance) Hit(com.yahoo.search.result.Hit) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result)

Example 70 with Hit

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

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