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.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
+}