Skip to content
Snippets Groups Projects
Commit 988eb8d5 authored by sand's avatar sand
Browse files

dump database

parent f5030ece
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,7 @@ var ( ...@@ -15,6 +15,7 @@ var (
dbPath = flag.String("db", "./db", "Path to the index") dbPath = flag.String("db", "./db", "Path to the index")
doSearch = flag.Bool("search", true, "Search for something (default)") doSearch = flag.Bool("search", true, "Search for something (default)")
doIndex = flag.Bool("index", false, "Index documents") doIndex = flag.Bool("index", false, "Index documents")
doDump = flag.Bool("dump", false, "Dump index database")
limit = flag.Int("limit", 20, "Limit number of search results") limit = flag.Int("limit", 20, "Limit number of search results")
noScores = flag.Bool("no-score", false, "Hide score in results") noScores = flag.Bool("no-score", false, "Hide score in results")
highlights = flag.Bool("highlights", false, "Show highlights from search results") highlights = flag.Bool("highlights", false, "Show highlights from search results")
...@@ -124,6 +125,8 @@ func main() { ...@@ -124,6 +125,8 @@ func main() {
if *doIndex { if *doIndex {
runIndex(index, flag.Args()) runIndex(index, flag.Args())
} else if *doDump {
index.Dump()
} else { } else {
runSearch(index, flag.Args()) runSearch(index, flag.Args())
} }
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/blevesearch/bleve" "github.com/blevesearch/bleve"
"github.com/blevesearch/bleve/index/upside_down"
"github.com/rainycape/cld2" "github.com/rainycape/cld2"
) )
...@@ -156,3 +157,15 @@ func (b *Index) Search(queryStr string, offset, limit int, highlights bool) (*bl ...@@ -156,3 +157,15 @@ func (b *Index) Search(queryStr string, offset, limit int, highlights bool) (*bl
func (b *Index) Close() { func (b *Index) Close() {
b.index.Close() b.index.Close()
} }
func (b *Index) Dump() {
for rowOrErr := range b.index.DumpAll() {
switch rowOrErr := rowOrErr.(type) {
case error:
fmt.Printf("error dumping: %v\n", rowOrErr)
case upside_down.UpsideDownCouchRow:
fmt.Printf("%v\n", rowOrErr)
fmt.Printf("Key: % -100x\nValue: % -100x\n\n", rowOrErr.Key(), rowOrErr.Value())
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment