use of com.yahoo.search.Result in project vespa by vespa-engine.
the class SimpleSearcher method search.
public Result search(Query query, Execution execution) {
try {
BooleanParser.parseBoolean("true");
XMLString xmlString = new XMLString("<sampleXmlString/>");
Hit hit = new Hit("Hello world!");
hit.setField("json", new JSONObject().put("price", 42).toString());
Result result = execution.search(query);
result.hits().add(hit);
return result;
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class ClusterSearcher method searchMultipleDocumentTypes.
private Result searchMultipleDocumentTypes(Searcher searcher, Query query, Execution execution) {
Set<String> docTypes = resolveDocumentTypes(query, execution.context().getIndexFacts());
Result invalidRankProfile = checkValidRankProfiles(query, docTypes);
if (invalidRankProfile != null) {
return invalidRankProfile;
}
List<Query> queries = createQueries(query, docTypes);
if (queries.size() == 1) {
return searcher.search(queries.get(0), execution);
} else {
Result mergedResult = new Result(query.clone());
for (Query q : queries) {
Result result = searcher.search(q, execution);
mergedResult.mergeWith(result);
mergedResult.hits().addAll(result.hits().asUnorderedHits());
}
// Should we trim the merged result?
if (query.getOffset() > 0 || query.getHits() < mergedResult.hits().size()) {
if (mergedResult.getHitOrderer() != null) {
// Make sure we have the necessary data for sorting
searcher.fill(mergedResult, Execution.ATTRIBUTEPREFETCH, execution);
}
mergedResult.hits().trim(query.getOffset(), query.getHits());
}
return mergedResult;
}
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class VespaBackEndSearcher method cacheLookupFirstPhase.
private Result cacheLookupFirstPhase(CacheKey key, QueryPacketData queryPacketData, Query query, int offset, int hits, String summaryClass) {
PacketWrapper packetWrapper = cacheControl.lookup(key, query);
if (packetWrapper == null)
return null;
// Check if the cache entry contains the requested hits
List<DocumentInfo> documents = packetWrapper.getDocuments(offset, hits);
if (documents == null)
return null;
if (query.getPresentation().getSummary() == null)
query.getPresentation().setSummary(getDefaultDocsumClass());
Result result = new Result(query);
QueryResultPacket resultPacket = packetWrapper.getFirstResultPacket();
addMetaInfo(query, queryPacketData, resultPacket, result, true);
if (packetWrapper.getNumPackets() == 0)
addUnfilledHits(result, documents, true, queryPacketData, key);
else
addCachedHits(result, packetWrapper, summaryClass, documents);
return result;
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class DocumentSourceSearcher method addDefaultResults.
private void addDefaultResults() {
Query q = new Query("?query=default");
Result r = new Result(q);
r.hits().add(new Hit("http://default-1.html"));
r.hits().add(new Hit("http://default-2.html"));
r.hits().add(new Hit("http://default-3.html"));
r.hits().add(new Hit("http://default-4.html"));
defaultFilledResult = r;
addResultSet(q, r);
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class DocumentSourceSearcher method fill.
@Override
public void fill(com.yahoo.search.Result result, String summaryClass, Execution execution) {
Result filledResult;
if ("attributeprefetch".equals(summaryClass))
filledResult = attributeFilledResults.get(getQueryKeyClone(result.getQuery()));
else
filledResult = completelyFilledResults.get(getQueryKeyClone(result.getQuery()));
if (filledResult == null) {
filledResult = defaultFilledResult;
}
fillHits(filledResult, result, summaryClass);
}
Aggregations