bugfixes more search results and dump restore options
This commit is contained in:
parent
f4fcf0d9a8
commit
3cd460318a
124 changed files with 3915 additions and 9579 deletions
76
dump.go
Normal file
76
dump.go
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/blevesearch/bleve"
|
||||
)
|
||||
|
||||
type DumpArticle struct {
|
||||
Title string `json:"title"`
|
||||
LinkTitle string `json:"link_title"`
|
||||
MD string `json:"md"`
|
||||
Created string `json:"created"`
|
||||
Updated string `json:"updated"`
|
||||
Public bool `json:"public"`
|
||||
}
|
||||
|
||||
func dumpWiki() error {
|
||||
index, err := bleve.OpenUsing(bleveStore, map[string]interface{}{"read_only": true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
engine = NewEngine(index)
|
||||
art, err := engine.Get(false, indexName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var arts []DumpArticle
|
||||
titles, err := engine.Dump()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, title := range titles {
|
||||
art, err = engine.Get(false, title)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, "dump:", art.Title)
|
||||
arts = append(arts, DumpArticle{
|
||||
Title: art.Title,
|
||||
LinkTitle: art.LinkTitle,
|
||||
MD: art.MD,
|
||||
Created: art.Created,
|
||||
Updated: art.Updated,
|
||||
Public: art.Public,
|
||||
})
|
||||
}
|
||||
return json.NewEncoder(os.Stdout).Encode(arts)
|
||||
}
|
||||
|
||||
func restoreWiki() (err error) {
|
||||
index, err := bleve.Open(bleveStore)
|
||||
if err != nil {
|
||||
mapping := bleve.NewIndexMapping()
|
||||
index, err = bleve.New(bleveStore, mapping)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
engine = NewEngine(index)
|
||||
var arts []DumpArticle
|
||||
err = json.NewDecoder(os.Stdin).Decode(&arts)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, art := range arts {
|
||||
fmt.Fprintln(os.Stderr, "restore:", art.Title)
|
||||
err = engine.Restore(art)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue