blob: 5f5f8266ab01987f9c0c90a9c71e4f6b7aef588d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.grouping.vespa;
import com.yahoo.prelude.fastsearch.DocsumDefinitionSet;
import com.yahoo.prelude.fastsearch.FastHit;
import com.yahoo.prelude.fastsearch.GroupingListHit;
import com.yahoo.search.Searcher;
import com.yahoo.search.result.Hit;
import com.yahoo.search.result.Relevance;
import com.yahoo.searchlib.aggregation.FS4Hit;
import com.yahoo.searchlib.aggregation.VdsHit;
/**
* Implementation of the {@link ResultBuilder.HitConverter} interface for {@link GroupingExecutor}.
*
* @author Simon Thoresen Hult
*/
class HitConverter implements ResultBuilder.HitConverter {
private final Searcher searcher;
/**
* Creates a new instance of this class.
*
* @param searcher The searcher that owns this converter.
*/
public HitConverter(Searcher searcher) {
this.searcher = searcher;
}
@Override
public com.yahoo.search.result.Hit toSearchHit(String summaryClass, com.yahoo.searchlib.aggregation.Hit hit) {
if (hit instanceof FS4Hit) {
return convertFs4Hit(summaryClass, (FS4Hit)hit);
} else if (hit instanceof VdsHit) {
return convertVdsHit(summaryClass, (VdsHit)hit);
} else {
throw new UnsupportedOperationException("Hit type '" + hit.getClass().getName() + "' not supported.");
}
}
private Hit convertFs4Hit(String summaryClass, FS4Hit groupHit) {
FastHit hit = new FastHit(groupHit.getGlobalId().getRawId(),
new Relevance(groupHit.getRank()),
groupHit.getPath(), groupHit.getDistributionKey());
hit.setFillable();
hit.setSearcherSpecificMetaData(searcher, summaryClass);
GroupingListHit hitContext = (GroupingListHit)groupHit.getContext();
if (hitContext == null)
throw new NullPointerException("Hit has no context.");
hit.setSource(hitContext.getSource());
hit.setQuery(hitContext.getQuery());
return hit;
}
private Hit convertVdsHit(String summaryClass, VdsHit grpHit) {
FastHit hit = new FastHit();
hit.setRelevance(grpHit.getRank());
if (grpHit.getSummary().getData().length > 0) {
GroupingListHit hitContext = (GroupingListHit)grpHit.getContext();
if (hitContext == null) {
throw new NullPointerException("Hit has no context.");
}
DocsumDefinitionSet defs = hitContext.getDocsumDefinitionSet();
defs.lazyDecode(summaryClass, grpHit.getSummary().getData(), hit);
hit.setField(Hit.SDDOCNAME_FIELD, hitContext.getSchema().name());
hit.setFilled(summaryClass);
hit.setFilled(hitContext.getQuery().getPresentation().getSummary());
hit.setQuery(hitContext.getQuery());
}
return hit;
}
}
|