use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class GetSearcherTestCase method testQueryPassThroughAndGetUnknownBackendHit.
@Test
public void testQueryPassThroughAndGetUnknownBackendHit() throws Exception {
DocumentSessionFactory factory = new DocumentSessionFactory(docType);
GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
HitGroup hits = new HitGroup("mock");
hits.add(new Hit("blernsball"));
Chain<Searcher> searchChain = new Chain<>(searcher, new MockBackend(hits));
Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?flarn=blern&id=userdoc:kittens:9:aaa"));
assertEquals(0, factory.messages.size());
assertNotNull(result.hits().getErrorHit());
assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"searcher\" code=\"18\" message=\"Internal server error.: " + "A backend searcher to com.yahoo.storage.searcher.GetSearcher returned a " + "hit that was not an instance of com.yahoo.storage.searcher.DocumentHit. " + "Only DocumentHit instances are supported in the backend hit result set " + "when doing queries that contain document identifier sets recognised by the " + "Get Searcher.\"/>\n" + "</errors>\n" + "</result>\n", result);
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class DocumentSourceSearcher method addResult.
/**
* Adds a result which can be searched for and filled.
* Summary fields starting by "a" are attributes, others are not.
*
* @return true when replacing an existing <query, result> pair.
*/
public boolean addResult(Query query, Result fullResult) {
Result emptyResult = new Result(query.clone());
emptyResult.setTotalHitCount(fullResult.getTotalHitCount());
for (Hit fullHit : fullResult.hits().asList()) {
Hit emptyHit = fullHit.clone();
emptyHit.clearFields();
emptyHit.setFillable();
emptyHit.setRelevance(fullHit.getRelevance());
emptyResult.hits().add(emptyHit);
}
unFilledResults.put(getQueryKeyClone(query), emptyResult);
if (completelyFilledResults.put(getQueryKeyClone(query), fullResult.clone()) != null) {
// TODO: throw exception if the key exists from before, change the method to void
return true;
}
return false;
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class ExampleSearcher method search.
@Override
public Result search(Query query, Execution execution) {
Result result = execution.search(query);
result.hits().add(new Hit("example", 1.0, "examplesearcher"));
return result;
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class FieldFilter method filter.
private void filter(Result result) {
Set<String> requestedFields;
if (result.getQuery().properties().getBoolean(FIELD_FILTER_DISABLE))
return;
if (result.getQuery().getPresentation().getSummaryFields().isEmpty())
return;
requestedFields = result.getQuery().getPresentation().getSummaryFields();
for (Iterator<Hit> i = result.hits().unorderedDeepIterator(); i.hasNext(); ) {
Hit h = i.next();
if (h.isMeta())
continue;
for (Iterator<Entry<String, Object>> fields = h.fieldIterator(); fields.hasNext(); ) {
Entry<String, Object> field = fields.next();
if (!requestedFields.contains(field.getKey()))
fields.remove();
}
}
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class GroupingExecutor method mergeGroupingResults.
/**
* Merges the grouping content of the given result object. The first grouping hit found by iterating over the result
* content is kept, and all consecutive matching hits are merged into this.
*
* @param result The result to traverse.
* @return A map of merged grouping objects.
*/
private Map<Integer, Grouping> mergeGroupingResults(Result result) {
Map<Integer, Grouping> ret = new HashMap<>();
for (Iterator<Hit> i = result.hits().unorderedIterator(); i.hasNext(); ) {
Hit hit = i.next();
if (hit instanceof GroupingListHit) {
ContextInjector injector = new ContextInjector(hit);
for (Grouping grp : ((GroupingListHit) hit).getGroupingList()) {
grp.select(injector, injector);
Grouping old = ret.get(grp.getId());
if (old != null) {
old.merge(grp);
} else {
ret.put(grp.getId(), grp);
}
}
i.remove();
}
}
for (Grouping grouping : ret.values()) {
grouping.postMerge();
}
return ret;
}
Aggregations