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);
}
}
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;
}
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;
}
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;
}
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()));
}
}
}
}
Aggregations