summaryrefslogtreecommitdiff
path: root/system/db/search.go
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2017-04-06 12:27:12 -0700
committerSteve Manuel <nilslice@gmail.com>2017-04-06 12:27:12 -0700
commit38a6c611da7d5f4aa3a1d4fbb94ab5371b9cae5f (patch)
treee6341ddc2c2dd508217fa414de39c434b7c96c03 /system/db/search.go
parenta7bdae0fb109f6fbe42afda6800338b76244a82c (diff)
adding json values to search index on insert and update
Diffstat (limited to 'system/db/search.go')
-rw-r--r--system/db/search.go25
1 files changed, 21 insertions, 4 deletions
diff --git a/system/db/search.go b/system/db/search.go
index d5fc9f5..8b642ff 100644
--- a/system/db/search.go
+++ b/system/db/search.go
@@ -5,11 +5,17 @@ import (
"path/filepath"
"github.com/blevesearch/bleve"
+ "github.com/blevesearch/bleve/mapping"
)
// Search tracks all search indices to use throughout system
var Search map[string]bleve.Index
+// Searchable ...
+type Searchable interface {
+ SearchMapping() *mapping.IndexMappingImpl
+}
+
func init() {
Search = make(map[string]bleve.Index)
}
@@ -17,9 +23,12 @@ func init() {
// 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 {
+ // TODO: type assert for Searchable, get configuration (which can be overridden)
+ // by Ponzu user if defines own SearchMapping()
+
mapping := bleve.NewIndexMapping()
mapping.StoreDynamic = false
- idxFile := typeName + ".index"
+ idxPath := typeName + ".index"
var idx bleve.Index
// check if index exists, use it or create new one
@@ -27,13 +36,21 @@ func MapIndex(typeName string) error {
if err != nil {
return err
}
- if _, err = os.Stat(filepath.Join(pwd, idxFile)); os.IsNotExist(err) {
- idx, err = bleve.New(idxFile, mapping)
+
+ searchPath := filepath.Join(pwd, "search")
+
+ err = os.MkdirAll(searchPath, os.ModeDir|os.ModePerm)
+ if err != nil {
+ return err
+ }
+
+ if _, err = os.Stat(filepath.Join(searchPath, idxPath)); os.IsNotExist(err) {
+ idx, err = bleve.New(idxPath, mapping)
if err != nil {
return err
}
} else {
- idx, err = bleve.Open(idxFile)
+ idx, err = bleve.Open(idxPath)
if err != nil {
return err
}