0
0

Merge branch 'simplebleveindex' of https://github.com/Shugyousha/bleve into Shugyousha-simplebleveindex

This commit is contained in:
Marty Schoch 2015-10-16 13:09:05 -04:00
commit 5c26f96606

View File

@ -20,9 +20,12 @@ import (
_ "github.com/blevesearch/bleve/config" _ "github.com/blevesearch/bleve/config"
) )
var indexPath = flag.String("index", "", "index path") var (
var keepExt = flag.Bool("keepExt", false, "keep extension in doc id") indexPath = flag.String("index", "", "index path")
var keepDir = flag.Bool("keepDir", false, "keep dir in doc id") keepExt = flag.Bool("keepExt", false, "keep extension in doc id")
keepDir = flag.Bool("keepDir", false, "keep dir in doc id")
rv chan file
)
func main() { func main() {
@ -72,12 +75,12 @@ type file struct {
} }
func handleArgs(args []string) chan file { func handleArgs(args []string) chan file {
rv := make(chan file) rv = make(chan file)
go func() { go func() {
for _, arg := range args { for _, arg := range args {
arg = filepath.Clean(arg) arg = filepath.Clean(arg)
handleArgRecursive(arg, rv) filepath.Walk(arg, getallfiles)
} }
close(rv) close(rv)
}() }()
@ -85,32 +88,23 @@ func handleArgs(args []string) chan file {
return rv return rv
} }
func handleArgRecursive(arg string, results chan file) { func getallfiles(path string, finfo os.FileInfo, err error) error {
stat, err := os.Stat(arg)
if err != nil { if err != nil {
log.Print(err) log.Print(err)
return return err
} }
if stat.IsDir() { if finfo.IsDir() {
// open the directory return nil
dirEntries, err := ioutil.ReadDir(arg)
if err != nil {
log.Fatal(err)
}
// walk the directory entries
for _, dirEntry := range dirEntries {
handleArgRecursive(arg+string(os.PathSeparator)+dirEntry.Name(), results)
}
} else {
bytes, err := ioutil.ReadFile(arg)
if err != nil {
log.Fatal(err)
}
results <- file{
filename: arg,
contents: bytes,
}
} }
bytes, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal(err)
}
rv <- file{
filename: filepath.Base(path),
contents: bytes,
}
return nil
} }