Search in sources :

Example 36 with Hit

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);
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 37 with Hit

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 &lt;query, result&gt; 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;
}
Also used : Hit(com.yahoo.search.result.Hit) Result(com.yahoo.search.Result)

Example 38 with Hit

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;
}
Also used : Hit(com.yahoo.search.result.Hit) Result(com.yahoo.search.Result)

Example 39 with Hit

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();
        }
    }
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) Entry(java.util.Map.Entry)

Example 40 with Hit

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;
}
Also used : GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) Hit(com.yahoo.search.result.Hit) HashMap(java.util.HashMap) Grouping(com.yahoo.searchlib.aggregation.Grouping) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit)

Aggregations

Hit (com.yahoo.search.result.Hit)127 Result (com.yahoo.search.Result)72 Query (com.yahoo.search.Query)52 FastHit (com.yahoo.prelude.fastsearch.FastHit)42 Test (org.junit.Test)41 Execution (com.yahoo.search.searchchain.Execution)25 HitGroup (com.yahoo.search.result.HitGroup)21 Searcher (com.yahoo.search.Searcher)17 JSONString (com.yahoo.prelude.hitfield.JSONString)13 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)12 ErrorHit (com.yahoo.search.result.ErrorHit)10 Relevance (com.yahoo.search.result.Relevance)10 HashMap (java.util.HashMap)9 DocumentSourceSearcher (com.yahoo.prelude.searcher.DocumentSourceSearcher)8 Group (com.yahoo.search.grouping.result.Group)8 ComponentId (com.yahoo.component.ComponentId)7 Chain (com.yahoo.component.chain.Chain)7 FS4Hit (com.yahoo.searchlib.aggregation.FS4Hit)6 VdsHit (com.yahoo.searchlib.aggregation.VdsHit)6 GroupList (com.yahoo.search.grouping.result.GroupList)5