forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.go
49 lines (39 loc) · 1.14 KB
/
index.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
package paths
import (
"strings"
"www.velocidex.com/golang/velociraptor/file_store/api"
)
const (
partition = 3
)
type IndexPathManager struct{}
func (self IndexPathManager) IndexTerm(term, entity string) api.DSPathSpec {
return CLIENT_INDEX_URN.AddUnsafeChild(splitTermToParts(term + entity)...).
AddUnsafeChild(entity)
}
// Returns a pathspec where walking the pathspec will return all the
// entities indexed under the same term.
func (self IndexPathManager) EnumerateTerms(term string) api.DSPathSpec {
return CLIENT_INDEX_URN.AddUnsafeChild(splitTermToParts(term)...)
}
func (self IndexPathManager) TermPartitions(term string) []string {
return splitTermToParts(term)
}
func NewIndexPathManager() *IndexPathManager {
return &IndexPathManager{}
}
func splitTermToParts(term string) []string {
// Lowercase the term so we can search case insensitive.
term = strings.ToLower(term)
// Partition the term into character groups
parts := []string{}
for i := 0; i < len(term); i += partition {
left := i
right := i + partition
if right > len(term) {
right = len(term)
}
parts = append(parts, term[left:right])
}
return parts
}