Search in sources :

Example 76 with Hit

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

the class HTTPProviderSearcher method search.

@Override
public Result search(Query query, Execution execution, Connection connection) {
    // Create default meta hit for holding logging information
    Hit requestMeta = createRequestMeta();
    Result result = new Result(query);
    result.hits().add(requestMeta);
    query.trace("Created request information hit", false, 9);
    try {
        URI uri = getURI(query, requestMeta, connection);
        if (query.getTraceLevel() >= 1)
            query.trace("Fetching " + uri.toString(), false, 1);
        long requestStartTime = System.currentTimeMillis();
        HttpEntity entity = getEntity(uri, requestMeta, query);
        // Seems confusing to me.
        return entity == null ? statisticsBeforeInspection(result, requestMeta, null) : consumeEntity(entity, query, result, requestMeta, requestStartTime);
    } catch (MalformedURLException | URISyntaxException e) {
        result.hits().addError(createMalformedUrlError(query, e));
        return statisticsBeforeInspection(result, requestMeta, e);
    } catch (TimeoutException e) {
        result.hits().addError(ErrorMessage.createTimeout("No time left for HTTP traffic in " + this + " for " + query + ": " + e.getMessage()));
        return statisticsBeforeInspection(result, requestMeta, e);
    } catch (IOException e) {
        result.hits().addError(ErrorMessage.createBackendCommunicationError("Error when trying to connect to HTTP backend in " + this + " for " + query + ": " + Exceptions.toMessageString(e)));
        return statisticsBeforeInspection(result, requestMeta, e);
    }
}
Also used : Hit(com.yahoo.search.result.Hit) MalformedURLException(java.net.MalformedURLException) HttpEntity(org.apache.http.HttpEntity) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) Result(com.yahoo.search.Result)

Example 77 with Hit

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

the class ResultBuilder method endElement.

@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
    switch(location.peekFirst()) {
        case HITGROUP:
            if ("group".equals(qName)) {
                hitGroups.removeFirst();
                location.removeFirst();
            }
            break;
        case HIT:
            if (fieldLevel > 0) {
                endElementInHitField(qName);
            } else if ("hit".equals(qName)) {
                // assert(hitKeys.size() == hitValues.size());
                // We try to get either uri or documentID and use that as id
                Object docId = extractDocumentID();
                Hit newHit = new Hit(docId.toString());
                if (hitRelevance != null)
                    newHit.setRelevance(new Relevance(DoubleParser.parse(hitRelevance)));
                if (hitSource != null)
                    newHit.setSource(hitSource);
                if (hitType != null) {
                    for (String type : hitType.split(" ")) {
                        newHit.types().add(type);
                    }
                }
                for (Map.Entry<String, Object> field : hitFields.entrySet()) {
                    newHit.setField(field.getKey(), field.getValue());
                }
                hitGroups.peekFirst().add(newHit);
                location.removeFirst();
            }
            break;
        case ERRORDETAILS:
            if (fieldLevel == 1 && ERROR.equals(qName)) {
                ErrorMessage error = new ErrorMessage(Integer.valueOf(currentErrorCode), currentError, fieldContent.toString());
                hitGroups.peekFirst().addError(error);
                currentError = null;
                currentErrorCode = null;
                fieldContent = null;
                tagStack = null;
                fieldLevel = 0;
            } else if (fieldLevel > 0) {
                endElementInField(qName, ERROR);
            } else if ("errordetails".equals(qName)) {
                location.removeFirst();
            }
            break;
        case ROOT:
            if (ERROR.equals(qName)) {
                ErrorMessage error = new ErrorMessage(Integer.valueOf(currentErrorCode), fieldContent.toString());
                hitGroups.peekFirst().addError(error);
                currentErrorCode = null;
                fieldContent = null;
            }
            break;
        default:
            break;
    }
    ++offset;
}
Also used : Relevance(com.yahoo.search.result.Relevance) Hit(com.yahoo.search.result.Hit) XMLString(com.yahoo.prelude.hitfield.XMLString) ErrorMessage(com.yahoo.search.result.ErrorMessage)

Example 78 with Hit

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

the class UniqueGroupingSearcher method getAllHitsFromGroupingResult.

/**
 * Get all the hits returned by the grouping request. This might be more or less than the user requested.
 * This method handles the results from two different types of grouping expression, depending on whether
 * sorting was used for the query or not.
 *
 * @param resultGroups The result group of the dedup grouping request
 * @return A (correctly sorted) list of all the hits returned by the grouping expression.
 */
private static List<Hit> getAllHitsFromGroupingResult(GroupList resultGroups) {
    List<Hit> hits = new ArrayList<>(resultGroups.size());
    for (Hit groupHit : resultGroups) {
        Group group = (Group) groupHit;
        GroupList sorted = group.getGroupList(LABEL_GROUPS);
        if (sorted != null) {
            group = (Group) sorted.iterator().next();
        }
        for (Hit hit : group.getHitList(LABEL_HITS)) {
            hits.add(hit);
        }
    }
    return hits;
}
Also used : Group(com.yahoo.search.grouping.result.Group) Hit(com.yahoo.search.result.Hit) GroupList(com.yahoo.search.grouping.result.GroupList) ArrayList(java.util.ArrayList)

Example 79 with Hit

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

the class HTTPSearcher method createRequestMeta.

/**
 * Creates a meta hit dedicated to holding logging information. This hit has
 * the 'logging:[searcher's ID]' type.
 */
protected Hit createRequestMeta() {
    Hit requestMeta = new Hit("logging:" + getId().toString());
    requestMeta.setMeta(true);
    requestMeta.types().add("logging");
    return requestMeta;
}
Also used : Hit(com.yahoo.search.result.Hit)

Example 80 with Hit

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

the class NGramSearcher method recombineNGrams.

private void recombineNGrams(Iterator<Hit> hits, IndexFacts.Session session) {
    while (hits.hasNext()) {
        Hit hit = hits.next();
        if (hit.isMeta())
            continue;
        Object sddocname = hit.getField(Hit.SDDOCNAME_FIELD);
        if (sddocname == null)
            return;
        for (String fieldName : hit.fieldKeys()) {
            Index index = session.getIndex(fieldName, sddocname.toString());
            if (index.isNGram() && (index.getHighlightSummary() || index.getDynamicSummary())) {
                hit.setField(fieldName, recombineNGramsField(hit.getField(fieldName), index.getGramSize()));
            }
        }
    }
}
Also used : Hit(com.yahoo.search.result.Hit) Index(com.yahoo.prelude.Index) XMLString(com.yahoo.prelude.hitfield.XMLString) JSONString(com.yahoo.prelude.hitfield.JSONString)

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