summaryrefslogtreecommitdiff
path: root/system/db/content.go
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2017-04-07 20:36:07 -0700
committerSteve Manuel <nilslice@gmail.com>2017-04-07 20:36:07 -0700
commitafe92b2bcd3b8e914496006a414ad9b95dba3f0b (patch)
tree40aca87652d696db10d37eb19c4049528b8d7519 /system/db/content.go
parentba201f640c883d5ed2f3e1f68daff3a7ee4c8b9f (diff)
add initial implementation of api search handler with full-text search by type
Diffstat (limited to 'system/db/content.go')
-rw-r--r--system/db/content.go62
1 files changed, 43 insertions, 19 deletions
diff --git a/system/db/content.go b/system/db/content.go
index a29ef20..a16c267 100644
--- a/system/db/content.go
+++ b/system/db/content.go
@@ -10,10 +10,9 @@ import (
"strconv"
"strings"
- "github.com/ponzu-cms/ponzu/system/item"
-
"github.com/boltdb/bolt"
"github.com/gorilla/schema"
+ "github.com/ponzu-cms/ponzu/system/item"
uuid "github.com/satori/go.uuid"
)
@@ -121,11 +120,14 @@ func update(ns, id string, data url.Values, existingContent *[]byte) (int, error
return 0, err
}
- target := fmt.Sprintf("%s:%s", ns, id)
- err = UpdateSearchIndex(target, string(j))
- if err != nil {
- return 0, err
- }
+ go func() {
+ // update data in search index
+ target := fmt.Sprintf("%s:%s", ns, id)
+ err = UpdateSearchIndex(target, string(j))
+ if err != nil {
+ log.Println("[search] UpdateSearchIndex Error:", err)
+ }
+ }()
return cid, nil
}
@@ -246,11 +248,14 @@ func insert(ns string, data url.Values) (int, error) {
return 0, err
}
- target := fmt.Sprintf("%s:%s", ns, cid)
- err = UpdateSearchIndex(target, string(j))
- if err != nil {
- return 0, err
- }
+ go func() {
+ // add data to seach index
+ target := fmt.Sprintf("%s:%s", ns, cid)
+ err = UpdateSearchIndex(target, string(j))
+ if err != nil {
+ log.Println("[search] UpdateSearchIndex Error:", err)
+ }
+ }()
return effectedID, nil
}
@@ -311,14 +316,16 @@ func DeleteContent(target string) error {
return err
}
- // delete indexed data from search index
- if !strings.Contains(ns, "__") {
- target = fmt.Sprintf("%s:%s", ns, id)
- err = DeleteSearchIndex(target)
- if err != nil {
- return err
+ go func() {
+ // delete indexed data from search index
+ if !strings.Contains(ns, "__") {
+ target = fmt.Sprintf("%s:%s", ns, id)
+ err = DeleteSearchIndex(target)
+ if err != nil {
+ log.Println("[search] DeleteSearchIndex Error:", err)
+ }
}
- }
+ }()
// exception to typical "run in goroutine" pattern:
// we want to have an updated admin view as soon as this is deleted, so
@@ -357,6 +364,23 @@ func Content(target string) ([]byte, error) {
return val.Bytes(), nil
}
+// ContentMulti returns a set of content based on the the targets / identifiers
+// provided in Ponzu target string format: Type:ID
+// NOTE: All targets should be of the same type
+func ContentMulti(targets []string) ([][]byte, error) {
+ var contents [][]byte
+ for i := range targets {
+ b, err := Content(targets[i])
+ if err != nil {
+ return nil, err
+ }
+
+ contents = append(contents, b)
+ }
+
+ return contents, nil
+}
+
// ContentBySlug does a lookup in the content index to find the type and id of
// the requested content. Subsequently, issues the lookup in the type bucket and
// returns the the type and data at that ID or nil if nothing exists.