-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresult.go
More file actions
58 lines (47 loc) · 1.91 KB
/
result.go
File metadata and controls
58 lines (47 loc) · 1.91 KB
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
package result
import (
"time"
"github.com/pkg/errors"
)
// Result represents a Query Result which can be from either MathWebSearch, ElasticSearch or a combined TemaSearch Result
// too unmarshal
type Result struct {
Kind Kind `json:"kind"` // the kind of query this is a result to
Took *time.Duration `json:"took,omitempty"` // how long the overall query took
TookComponents map[string]*time.Duration `json:"stats,omitempty"` // how long each of the components took
Total int64 `json:"total"` // the total number of results
From int64 `json:"from"` // result number this page starts at
Size int64 `json:"size"` // number of results returned
Variables []*QueryVariable `json:"qvars,omitempty"` // the list of
HitIDs []int64 `json:"ids,omitempty"` // the ids of the hits
Hits []*Hit `json:"hits,omitempty"` // the current page of hits
}
// Kind represents the kind of result being returned
type Kind string
const (
// EmptyKind is a ressult in response to the empty query
EmptyKind Kind = ""
// MathWebSearchKind is a result in represonse to a MathWebSearch query
MathWebSearchKind Kind = "mwsd"
// ElasticDocumentKind is a result returned from the document query
ElasticDocumentKind Kind = "elastic-document"
// ElasticKind is a result returned from the document + highlight query
ElasticKind Kind = "elastic"
// TemaSearchKind is a result returned from a combined elastic + MathWebSearch Query
TemaSearchKind Kind = "tema"
)
// Normalize normalizes a result so that it can be used reproducibly in tests
func (res *Result) Normalize() {
res.Took = nil
res.TookComponents = nil
}
// PopulateSubsitutions populates all substiutions within all hits of this result
func (res *Result) PopulateSubsitutions() error {
for _, hit := range res.Hits {
if err := hit.PopulateSubsitutions(res); err != nil {
err = errors.Wrap(err, "hit.PopulateSubsitutions failed")
return err
}
}
return nil
}