summaryrefslogtreecommitdiff
path: root/system/db/search.go
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2017-04-06 10:49:49 -0700
committerSteve Manuel <nilslice@gmail.com>2017-04-06 10:49:49 -0700
commita7bdae0fb109f6fbe42afda6800338b76244a82c (patch)
tree21973f0e182232952121b2903714bce92e9bc73d /system/db/search.go
parent3206139e09dc6a3b332ff97ef4c58a4215330385 (diff)
add mapping for search indices per content type
Diffstat (limited to 'system/db/search.go')
-rw-r--r--system/db/search.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/system/db/search.go b/system/db/search.go
new file mode 100644
index 0000000..d5fc9f5
--- /dev/null
+++ b/system/db/search.go
@@ -0,0 +1,46 @@
+package db
+
+import (
+ "os"
+ "path/filepath"
+
+ "github.com/blevesearch/bleve"
+)
+
+// Search tracks all search indices to use throughout system
+var Search map[string]bleve.Index
+
+func init() {
+ Search = make(map[string]bleve.Index)
+}
+
+// MapIndex creates the mapping for a type and tracks the index to be used within
+// the system for adding/deleting/checking data
+func MapIndex(typeName string) error {
+ mapping := bleve.NewIndexMapping()
+ mapping.StoreDynamic = false
+ idxFile := typeName + ".index"
+ var idx bleve.Index
+
+ // check if index exists, use it or create new one
+ pwd, err := os.Getwd()
+ if err != nil {
+ return err
+ }
+ if _, err = os.Stat(filepath.Join(pwd, idxFile)); os.IsNotExist(err) {
+ idx, err = bleve.New(idxFile, mapping)
+ if err != nil {
+ return err
+ }
+ } else {
+ idx, err = bleve.Open(idxFile)
+ if err != nil {
+ return err
+ }
+ }
+
+ // add the type name to the index and track the index
+ Search[typeName] = idx
+
+ return nil
+}