summaryrefslogtreecommitdiff
path: root/system/db/search.go
diff options
context:
space:
mode:
Diffstat (limited to 'system/db/search.go')
-rw-r--r--system/db/search.go23
1 files changed, 20 insertions, 3 deletions
diff --git a/system/db/search.go b/system/db/search.go
index 3e7a9d6..b3d5fa1 100644
--- a/system/db/search.go
+++ b/system/db/search.go
@@ -9,6 +9,8 @@ import (
"github.com/ponzu-cms/ponzu/system/item"
+ "encoding/json"
+
"github.com/blevesearch/bleve"
"github.com/blevesearch/bleve/mapping"
)
@@ -24,6 +26,7 @@ var (
// Searchable ...
type Searchable interface {
SearchMapping() (*mapping.IndexMappingImpl, error)
+ IndexContent() bool
}
func init() {
@@ -44,10 +47,12 @@ func MapSearchIndex(typeName string) error {
return fmt.Errorf("[search] MapSearchIndex Error: Item type %s doesn't implement db.Searchable", typeName)
}
- mapping, err := s.SearchMapping()
- if err == item.ErrNoSearchMapping {
+ // skip setting or using index for types that shouldn't be indexed
+ if !s.IndexContent() {
return nil
}
+
+ mapping, err := s.SearchMapping()
if err != nil {
return err
}
@@ -97,8 +102,20 @@ func UpdateSearchIndex(id string, data interface{}) error {
idx, ok := Search[ns]
if ok {
+ // unmarshal json to struct, error if not registered
+ it, ok := item.Types[ns]
+ if !ok {
+ return fmt.Errorf("[search] UpdateSearchIndex Error: type '%s' doesn't exist", ns)
+ }
+
+ p := it()
+ err := json.Unmarshal(data.([]byte), &p)
+ if err != nil {
+ return err
+ }
+
// add data to search index
- return idx.Index(id, data)
+ return idx.Index(id, p)
}
return nil