mostly finished db pages
This commit is contained in:
parent
c5d41b0965
commit
38f7c31517
10 changed files with 278 additions and 125 deletions
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright (C) 2017 Marius Schellenberger
|
||||
|
||||
package main
|
||||
package index
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/blevesearch/bleve/document"
|
||||
)
|
||||
|
||||
type IndexPage struct {
|
||||
type indexPage struct {
|
||||
Title string `json:"title"`
|
||||
Search string `json:"search"`
|
||||
}
|
||||
|
|
@ -50,29 +50,19 @@ func NewIndex(path string) (i *Index, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func NewDumpIndex(path string) (i *Index, err error) {
|
||||
bi, err := bleve.OpenUsing(path, map[string]interface{}{"read_only": true})
|
||||
if err != nil {
|
||||
err = indexErr(err)
|
||||
return
|
||||
}
|
||||
i = &Index{index: bi}
|
||||
return
|
||||
}
|
||||
|
||||
func (i *Index) Close() error {
|
||||
return i.i.Close()
|
||||
}
|
||||
|
||||
func (i *Index) Add(ip IndexPage) error {
|
||||
doc, _ := i.i.Document(ip.Title)
|
||||
func (i *Index) Add(title, search string) error {
|
||||
doc, _ := i.i.Document(title)
|
||||
if doc != nil {
|
||||
err := i.Delete(ip.Title)
|
||||
err := i.Delete(title)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return i.i.Index(ip.Title, ip)
|
||||
return i.i.Index(title, indexPage{title, search})
|
||||
}
|
||||
|
||||
func (i *Index) Delete(title string) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue