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