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