summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2017-04-13 13:29:18 -0700
committerSteve Manuel <nilslice@gmail.com>2017-04-13 13:29:18 -0700
commitade7c2d69c9884c493fbc2f66f6a7405c0f4f96b (patch)
tree39d5fb68b9e959b55ec3a0dbde05375f8e4ef962
parentfe9938cc4ce7885533bf751de5b2eb65a962e99c (diff)
moving search into own package and renaming funcs throughout
-rw-r--r--system/api/search.go5
-rw-r--r--system/db/content.go13
-rw-r--r--system/db/init.go3
-rw-r--r--system/item/item.go4
-rw-r--r--system/search/search.go (renamed from system/db/search.go)32
5 files changed, 30 insertions, 27 deletions
diff --git a/system/api/search.go b/system/api/search.go
index c743d9f..9c7f0ae 100644
--- a/system/api/search.go
+++ b/system/api/search.go
@@ -8,6 +8,7 @@ import (
"github.com/ponzu-cms/ponzu/system/db"
"github.com/ponzu-cms/ponzu/system/item"
+ "github.com/ponzu-cms/ponzu/system/search"
)
func searchContentHandler(res http.ResponseWriter, req *http.Request) {
@@ -42,8 +43,8 @@ func searchContentHandler(res http.ResponseWriter, req *http.Request) {
}
// execute search for query provided, if no index for type send 404
- matches, err := db.SearchType(t, q)
- if err == db.ErrNoSearchIndex {
+ matches, err := search.TypeQuery(t, q)
+ if err == search.ErrNoIndex {
res.WriteHeader(http.StatusNotFound)
return
}
diff --git a/system/db/content.go b/system/db/content.go
index fbdd8dd..b3e2642 100644
--- a/system/db/content.go
+++ b/system/db/content.go
@@ -12,6 +12,7 @@ import (
"time"
"github.com/ponzu-cms/ponzu/system/item"
+ "github.com/ponzu-cms/ponzu/system/search"
"github.com/boltdb/bolt"
"github.com/gorilla/schema"
@@ -125,9 +126,9 @@ func update(ns, id string, data url.Values, existingContent *[]byte) (int, error
go func() {
// update data in search index
target := fmt.Sprintf("%s:%s", ns, id)
- err = UpdateSearchIndex(target, j)
+ err = search.UpdateIndex(target, j)
if err != nil {
- log.Println("[search] UpdateSearchIndex Error:", err)
+ log.Println("[search] UpdateIndex Error:", err)
}
}()
@@ -253,9 +254,9 @@ func insert(ns string, data url.Values) (int, error) {
go func() {
// add data to seach index
target := fmt.Sprintf("%s:%s", ns, cid)
- err = UpdateSearchIndex(target, j)
+ err = search.UpdateIndex(target, j)
if err != nil {
- log.Println("[search] UpdateSearchIndex Error:", err)
+ log.Println("[search] UpdateIndex Error:", err)
}
}()
@@ -322,9 +323,9 @@ func DeleteContent(target string) error {
// delete indexed data from search index
if !strings.Contains(ns, "__") {
target = fmt.Sprintf("%s:%s", ns, id)
- err = DeleteSearchIndex(target)
+ err = search.DeleteIndex(target)
if err != nil {
- log.Println("[search] DeleteSearchIndex Error:", err)
+ log.Println("[search] DeleteIndex Error:", err)
}
}
}()
diff --git a/system/db/init.go b/system/db/init.go
index 4e9c3cf..3fc35f5 100644
--- a/system/db/init.go
+++ b/system/db/init.go
@@ -4,6 +4,7 @@ import (
"log"
"github.com/ponzu-cms/ponzu/system/item"
+ "github.com/ponzu-cms/ponzu/system/search"
"github.com/boltdb/bolt"
"github.com/nilslice/jwt"
@@ -80,7 +81,7 @@ func Init() {
go func() {
for t := range item.Types {
- err := MapSearchIndex(t)
+ err := search.MapIndex(t)
if err != nil {
log.Fatalln(err)
return
diff --git a/system/item/item.go b/system/item/item.go
index 8f392ca..227cd26 100644
--- a/system/item/item.go
+++ b/system/item/item.go
@@ -211,7 +211,7 @@ func (i Item) AfterReject(res http.ResponseWriter, req *http.Request) error {
}
// SearchMapping returns a default implementation of a Bleve IndexMappingImpl
-// partially implements db.Searchable
+// partially implements search.Searchable
func (i Item) SearchMapping() (*mapping.IndexMappingImpl, error) {
mapping := bleve.NewIndexMapping()
mapping.StoreDynamic = false
@@ -220,7 +220,7 @@ func (i Item) SearchMapping() (*mapping.IndexMappingImpl, error) {
}
// IndexContent determines if a type should be indexed for searching
-// partially implements db.Searchable
+// partially implements search.Searchable
func (i Item) IndexContent() bool {
return false
}
diff --git a/system/db/search.go b/system/search/search.go
index b3d5fa1..6d538ed 100644
--- a/system/db/search.go
+++ b/system/search/search.go
@@ -1,4 +1,4 @@
-package db
+package search
import (
"errors"
@@ -19,8 +19,8 @@ var (
// Search tracks all search indices to use throughout system
Search map[string]bleve.Index
- // ErrNoSearchIndex is for failed checks for an index in Search map
- ErrNoSearchIndex = errors.New("No search index found for type provided")
+ // ErrNoIndex is for failed checks for an index in Search map
+ ErrNoIndex = errors.New("No search index found for type provided")
)
// Searchable ...
@@ -33,18 +33,18 @@ func init() {
Search = make(map[string]bleve.Index)
}
-// MapSearchIndex creates the mapping for a type and tracks the index to be used within
+// MapIndex creates the mapping for a type and tracks the index to be used within
// the system for adding/deleting/checking data
-func MapSearchIndex(typeName string) error {
+func MapIndex(typeName string) error {
// type assert for Searchable, get configuration (which can be overridden)
// by Ponzu user if defines own SearchMapping()
it, ok := item.Types[typeName]
if !ok {
- return fmt.Errorf("[search] MapSearchIndex Error: Failed to MapIndex for %s, type doesn't exist", typeName)
+ return fmt.Errorf("[search] MapIndex Error: Failed to MapIndex for %s, type doesn't exist", typeName)
}
s, ok := it().(Searchable)
if !ok {
- return fmt.Errorf("[search] MapSearchIndex Error: Item type %s doesn't implement db.Searchable", typeName)
+ return fmt.Errorf("[search] MapIndex Error: Item type %s doesn't implement search.Searchable", typeName)
}
// skip setting or using index for types that shouldn't be indexed
@@ -93,9 +93,9 @@ func MapSearchIndex(typeName string) error {
return nil
}
-// UpdateSearchIndex sets data into a content type's search index at the given
+// UpdateIndex sets data into a content type's search index at the given
// identifier
-func UpdateSearchIndex(id string, data interface{}) error {
+func UpdateIndex(id string, data interface{}) error {
// check if there is a search index to work with
target := strings.Split(id, ":")
ns := target[0]
@@ -105,7 +105,7 @@ func UpdateSearchIndex(id string, data interface{}) error {
// 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)
+ return fmt.Errorf("[search] UpdateIndex Error: type '%s' doesn't exist", ns)
}
p := it()
@@ -121,9 +121,9 @@ func UpdateSearchIndex(id string, data interface{}) error {
return nil
}
-// DeleteSearchIndex removes data from a content type's search index at the
+// DeleteIndex removes data from a content type's search index at the
// given identifier
-func DeleteSearchIndex(id string) error {
+func DeleteIndex(id string) error {
// check if there is a search index to work with
target := strings.Split(id, ":")
ns := target[0]
@@ -137,13 +137,13 @@ func DeleteSearchIndex(id string) error {
return nil
}
-// SearchType conducts a search and returns a set of Ponzu "targets", Type:ID pairs,
+// TypeQuery conducts a search and returns a set of Ponzu "targets", Type:ID pairs,
// and an error. If there is no search index for the typeName (Type) provided,
-// db.ErrNoSearchIndex will be returned as the error
-func SearchType(typeName, query string) ([]string, error) {
+// db.ErrNoIndex will be returned as the error
+func TypeQuery(typeName, query string) ([]string, error) {
idx, ok := Search[typeName]
if !ok {
- return nil, ErrNoSearchIndex
+ return nil, ErrNoIndex
}
q := bleve.NewQueryStringQuery(query)