-
Notifications
You must be signed in to change notification settings - Fork 45
/
collector.go
56 lines (44 loc) · 1.11 KB
/
collector.go
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
package search
import (
"context"
"sort"
bsearch "github.com/blevesearch/bleve/search"
search "github.com/streamingfast/search"
)
type trxResult struct {
id string
blockNum uint64
}
func collector(ctx context.Context, lowBlockNum, highBlockNum uint64, results bsearch.DocumentMatchCollection) (out []search.SearchMatch, err error) {
trxs := make(map[string][]uint16)
var trxList []*trxResult
for _, el := range results {
if err := ctx.Err(); err != nil {
return nil, err
}
blockNum, trxID, actionIdx, skip := explodeDocumentID(el.ID)
if skip {
continue
}
if blockNum < lowBlockNum || blockNum > highBlockNum {
continue
}
if _, found := trxs[trxID]; !found {
trxList = append(trxList, &trxResult{
id: trxID,
blockNum: blockNum,
})
}
trxs[trxID] = append(trxs[trxID], actionIdx)
}
for _, trx := range trxList {
actions := trxs[trx.id]
sort.Slice(actions, func(i, j int) bool { return actions[i] < actions[j] })
out = append(out, &SearchMatch{
TrxIDPrefix: trx.id,
ActionIndexes: actions,
BlockNumber: trx.blockNum,
})
}
return out, nil
}