diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-04-06 12:55:18 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2017-04-06 12:55:18 -0700 |
commit | 338d354222a60fdd4c5e9c9493932f684bae6827 (patch) | |
tree | ad615d4fd2c5cfa1696344994507d99abcf57bda /system/db | |
parent | f7a1c1afd6a0bf5708530c31da55035322f37ff4 (diff) |
adding default implementation of db.Searchable
Diffstat (limited to 'system/db')
-rw-r--r-- | system/db/search.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/system/db/search.go b/system/db/search.go index 2474e19..743a904 100644 --- a/system/db/search.go +++ b/system/db/search.go @@ -1,11 +1,13 @@ package db import ( + "fmt" "os" "path/filepath" "github.com/blevesearch/bleve" "github.com/blevesearch/bleve/mapping" + "github.com/ponzu-cms/ponzu/system/item" ) // Search tracks all search indices to use throughout system @@ -23,11 +25,19 @@ 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) + // 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("Failed to MapIndex for %s, type doesn't exist", typeName) + } + s, ok := it().(Searchable) + if !ok { + return fmt.Errorf("Item type %s doesn't implement db.Searchable", typeName) + } + + mapping := s.SearchMapping() - mapping := bleve.NewIndexMapping() - mapping.StoreDynamic = false idxName := typeName + ".index" var idx bleve.Index |