summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system/db/search.go16
-rw-r--r--system/item/item.go11
2 files changed, 24 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
diff --git a/system/item/item.go b/system/item/item.go
index 99d70a8..24ac003 100644
--- a/system/item/item.go
+++ b/system/item/item.go
@@ -7,6 +7,8 @@ import (
"strings"
"unicode"
+ "github.com/blevesearch/bleve"
+ "github.com/blevesearch/bleve/mapping"
uuid "github.com/satori/go.uuid"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
@@ -208,6 +210,15 @@ func (i Item) AfterReject(res http.ResponseWriter, req *http.Request) error {
return nil
}
+// SearchMapping returns a default implementation of a Bleve IndexMappingImpl
+// partially implements db.Searchable
+func SearchMapping() *mapping.IndexMappingImpl {
+ mapping := bleve.NewIndexMapping()
+ mapping.StoreDynamic = false
+
+ return mapping
+}
+
// Slug returns a URL friendly string from the title of a post item
func Slug(i Identifiable) (string, error) {
// get the name of the post item