bugfixes and updated go.mod
This commit is contained in:
parent
9424084a36
commit
6e317eb08b
300 changed files with 53136 additions and 9719 deletions
|
|
@ -7,11 +7,16 @@ import (
|
|||
"git.giftfish.de/ston1th/godrop/v2"
|
||||
"git.giftfish.de/ston1th/gowiki/pkg/core"
|
||||
"github.com/blevesearch/bleve"
|
||||
"github.com/blevesearch/bleve/mapping"
|
||||
"html/template"
|
||||
"os"
|
||||
)
|
||||
|
||||
const maxSearchResult = 101
|
||||
const (
|
||||
maxSearchResult = 101
|
||||
|
||||
docType = "page"
|
||||
)
|
||||
|
||||
type indexPage struct {
|
||||
Title string `json:"title"`
|
||||
|
|
@ -19,6 +24,10 @@ type indexPage struct {
|
|||
Search string `json:"search"`
|
||||
}
|
||||
|
||||
func (*indexPage) Type() string {
|
||||
return docType
|
||||
}
|
||||
|
||||
type Index struct {
|
||||
i bleve.Index
|
||||
}
|
||||
|
|
@ -30,8 +39,22 @@ func NewIndex(path string) (i *Index, err error) {
|
|||
return
|
||||
}
|
||||
if _, err = os.Stat(path); os.IsNotExist(err) {
|
||||
mapping := bleve.NewIndexMapping()
|
||||
bi, err = bleve.New(path, mapping)
|
||||
err = os.Mkdir(path, 0700)
|
||||
if err != nil {
|
||||
err = errors.New("index: " + err.Error())
|
||||
return
|
||||
}
|
||||
err = godrop.Unveil(path, "rwc")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var m *mapping.IndexMappingImpl
|
||||
m, err = createMapping()
|
||||
if err != nil {
|
||||
err = errors.New("mapping: " + err.Error())
|
||||
return
|
||||
}
|
||||
bi, err = bleve.New(path, m)
|
||||
if err != nil {
|
||||
err = errors.New("index: " + err.Error())
|
||||
return
|
||||
|
|
@ -59,7 +82,7 @@ func (i *Index) Add(title, storeTitle, search string) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
return i.i.Index(storeTitle, indexPage{title, storeTitle, search})
|
||||
return i.i.Index(storeTitle, &indexPage{title, storeTitle, search})
|
||||
}
|
||||
|
||||
func (i *Index) Delete(storeTitle string) error {
|
||||
|
|
@ -67,7 +90,7 @@ func (i *Index) Delete(storeTitle string) error {
|
|||
}
|
||||
|
||||
func (i *Index) Search(search string) (results []core.Result, err error) {
|
||||
req := bleve.NewSearchRequest(bleve.NewQueryStringQuery("title:" + search + " search:" + search))
|
||||
req := bleve.NewSearchRequest(bleve.NewQueryStringQuery(search))
|
||||
req.Highlight = bleve.NewHighlightWithStyle("html")
|
||||
req.Size = maxSearchResult
|
||||
res, err := i.i.Search(req)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue