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