/
update.go
70 lines (57 loc) · 1.66 KB
/
update.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package manticore
/*
EUpdateType is values for `vtype` of UpdateAttributes() call, which determines meaning of `values` param of this function.
UpdateInt
This is the default value. `values` hash holds documents IDs as keys and a plain arrays of new attribute values.
UpdateMva
Points that MVA attributes are being updated. In this case the `values` must be a hash with document IDs as keys
and array of arrays of int values (new MVA attribute values).
UpdateString
Points that string attributes are being updated. `values` must be a hash with document IDs as keys and array of strings as values.
UpdateJson
Works the same as `UpdateString`, but for JSON attribute updates.
*/
type EUpdateType uint32
const (
UpdateInt EUpdateType = iota
UpdateMva
UpdateString
UpdateJson
)
func buildUpdateRequest(index string, attrs []string, values map[DocID][]interface{},
vtype EUpdateType, ignorenonexistent bool) func(*apibuf) {
nattrs := len(attrs)
nvalues := len(values)
return func(buf *apibuf) {
buf.putString(index)
buf.putLen(nattrs)
buf.putBoolDword(ignorenonexistent)
for j := 0; j < nattrs; j++ {
buf.putString(attrs[j])
buf.putDword(uint32(vtype))
}
buf.putLen(nvalues)
for key, value := range values {
buf.putDocid(key)
switch vtype {
case UpdateInt:
for j := 0; j < nattrs; j++ {
buf.putInt(int32(value[j].(int)))
}
case UpdateMva:
for j := 0; j < nattrs; j++ {
foo := value[j].([]uint32)
buf.putLen(len(foo))
for k := 0; k<len(foo); k++ {
buf.putDword(foo[k])
}
}
case UpdateString:
case UpdateJson:
for j := 0; j < nattrs; j++ {
buf.putString(value[j].(string))
}
}
}
}
}