summaryrefslogtreecommitdiff
path: root/system/db/content.go
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2017-04-06 12:27:12 -0700
committerSteve Manuel <nilslice@gmail.com>2017-04-06 12:27:12 -0700
commit38a6c611da7d5f4aa3a1d4fbb94ab5371b9cae5f (patch)
treee6341ddc2c2dd508217fa414de39c434b7c96c03 /system/db/content.go
parenta7bdae0fb109f6fbe42afda6800338b76244a82c (diff)
adding json values to search index on insert and update
Diffstat (limited to 'system/db/content.go')
-rw-r--r--system/db/content.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/system/db/content.go b/system/db/content.go
index 97ea9b4..cc3382f 100644
--- a/system/db/content.go
+++ b/system/db/content.go
@@ -121,6 +121,13 @@ func update(ns, id string, data url.Values, existingContent *[]byte) (int, error
return 0, err
}
+ // add data to search index
+ target := fmt.Sprintf("%s:%s", ns, id)
+ err = Search[ns].Index(target, j)
+ if err != nil {
+ return 0, err
+ }
+
return cid, nil
}
@@ -169,6 +176,8 @@ func insert(ns string, data url.Values) (int, error) {
specifier = "__" + spec[1]
}
+ var j []byte
+ var cid string
err := store.Update(func(tx *bolt.Tx) error {
b, err := tx.CreateBucketIfNotExists([]byte(ns + specifier))
if err != nil {
@@ -181,7 +190,7 @@ func insert(ns string, data url.Values) (int, error) {
if err != nil {
return err
}
- cid := strconv.FormatUint(id, 10)
+ cid = strconv.FormatUint(id, 10)
effectedID, err = strconv.Atoi(cid)
if err != nil {
return err
@@ -197,7 +206,7 @@ func insert(ns string, data url.Values) (int, error) {
data.Set("__specifier", specifier)
}
- j, err := postToJSON(ns, data)
+ j, err = postToJSON(ns, data)
if err != nil {
return err
}
@@ -238,6 +247,13 @@ func insert(ns string, data url.Values) (int, error) {
return 0, err
}
+ // add data to search index
+ target := fmt.Sprintf("%s:%s", ns, cid)
+ err = Search[ns].Index(target, j)
+ if err != nil {
+ return 0, err
+ }
+
return effectedID, nil
}