Switch from Godep to go vendoring

This commit is contained in:
Ken-Håvard Lieng 2016-03-01 01:51:26 +01:00
parent 6b37713bc0
commit cd317761c5
1504 changed files with 263076 additions and 34441 deletions

View file

@ -0,0 +1,104 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package main
import (
"bufio"
"flag"
"log"
"math/rand"
"os"
"github.com/blevesearch/bleve"
)
var indexPath = flag.String("index", "", "index path")
var batchSize = flag.Int("size", 1000, "size of a single batch to index")
func main() {
flag.Parse()
if *indexPath == "" {
log.Fatal("must specify index path")
}
// open the index
index, err := bleve.Open(*indexPath)
if err != nil {
log.Fatal(err)
}
defer func() {
cerr := index.Close()
if cerr != nil {
log.Fatalf("error closing index: %v", err)
}
}()
if flag.NArg() < 1 {
log.Fatal("must specify at least one path to index")
}
i := 0
batch := index.NewBatch()
for _, file := range flag.Args() {
file, err := os.Open(file)
defer func() {
cerr := file.Close()
if cerr != nil {
log.Fatalf("error closing file: %v", cerr)
}
}()
if err != nil {
log.Fatal(err)
}
log.Printf("Indexing: %s\n", file.Name())
r := bufio.NewReader(file)
for {
if i%*batchSize == 0 {
log.Printf("Indexing batch (%d docs)...\n", i)
err := index.Batch(batch)
if err != nil {
log.Fatal(err)
}
batch = index.NewBatch()
}
b, _ := r.ReadBytes('\n')
if len(b) == 0 {
break
}
docID := randomString(5)
err := batch.Index(docID, b)
if err != nil {
log.Fatal(err)
}
i++
}
err = index.Batch(batch)
if err != nil {
log.Fatal(err)
}
}
}
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func randomString(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}

View file

@ -0,0 +1,58 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package main
import (
"encoding/json"
"flag"
"io/ioutil"
"log"
"github.com/blevesearch/bleve"
)
var indexPath = flag.String("index", "", "index path")
var mappingFile = flag.String("mapping", "", "mapping file")
func main() {
flag.Parse()
if *indexPath == "" {
log.Fatal("must specify index path")
}
// create a new default mapping
mapping := bleve.NewIndexMapping()
if *mappingFile != "" {
mappingBytes, err := ioutil.ReadFile(*mappingFile)
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(mappingBytes, &mapping)
if err != nil {
log.Fatal(err)
}
}
// create the index
index, err := bleve.New(*indexPath, mapping)
if err != nil {
log.Fatal(err)
}
defer func() {
cerr := index.Close()
if cerr != nil {
log.Fatalf("error closing index: %v", err)
}
}()
log.Printf("Created bleve index at: %s", *indexPath)
}

View file

@ -0,0 +1,73 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"github.com/blevesearch/bleve"
"github.com/blevesearch/bleve/index/upside_down"
)
var indexPath = flag.String("index", "", "index path")
var fieldsOnly = flag.Bool("fields", false, "fields only")
var docID = flag.String("docID", "", "docID to dump")
var mappingOnly = flag.Bool("mapping", false, "print mapping")
func main() {
flag.Parse()
if *indexPath == "" {
log.Fatal("specify index to dump")
}
index, err := bleve.Open(*indexPath)
if err != nil {
log.Fatal(err)
}
defer func() {
cerr := index.Close()
if cerr != nil {
log.Fatalf("error closing index: %v", err)
}
}()
if *mappingOnly {
mapping := index.Mapping()
jsonBytes, err := json.MarshalIndent(mapping, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", jsonBytes)
return
}
var dumpChan chan interface{}
if *docID != "" {
dumpChan = index.DumpDoc(*docID)
} else if *fieldsOnly {
dumpChan = index.DumpFields()
} else {
dumpChan = index.DumpAll()
}
for rowOrErr := range dumpChan {
switch rowOrErr := rowOrErr.(type) {
case error:
log.Printf("error dumping: %v", rowOrErr)
case upside_down.UpsideDownCouchRow:
fmt.Printf("%v\n", rowOrErr)
fmt.Printf("Key: % -100x\nValue: % -100x\n\n", rowOrErr.Key(), rowOrErr.Value())
}
}
}

View file

@ -0,0 +1,115 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package main
import (
"flag"
"io/ioutil"
"log"
"os"
"path/filepath"
"github.com/blevesearch/bleve"
)
var indexPath = flag.String("index", "", "index path")
var keepExt = flag.Bool("keepExt", false, "keep extension in doc id")
var keepDir = flag.Bool("keepDir", false, "keep dir in doc id")
func main() {
flag.Parse()
if *indexPath == "" {
log.Fatal("must specify index path")
}
// open the index
index, err := bleve.Open(*indexPath)
if err != nil {
log.Fatal(err)
}
defer func() {
cerr := index.Close()
if cerr != nil {
log.Fatalf("error closing index: %v", err)
}
}()
if flag.NArg() < 1 {
log.Fatal("must specify at least one path to index")
}
for file := range handleArgs(flag.Args()) {
// index the files
docID := file.filename
if !*keepDir {
_, docID = filepath.Split(docID)
}
if !*keepExt {
ext := filepath.Ext(docID)
docID = docID[0 : len(docID)-len(ext)]
}
log.Printf("Indexing: %s", docID)
err = index.Index(docID, file.contents)
if err != nil {
log.Fatal(err)
}
}
}
type file struct {
filename string
contents []byte
}
func handleArgs(args []string) chan file {
rv := make(chan file)
go func() {
for _, arg := range args {
arg = filepath.Clean(arg)
handleArgRecursive(arg, rv)
}
close(rv)
}()
return rv
}
func handleArgRecursive(arg string, results chan file) {
stat, err := os.Stat(arg)
if err != nil {
log.Print(err)
return
}
if stat.IsDir() {
// open the directory
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,
}
}
}

View file

@ -0,0 +1,85 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime/pprof"
"strings"
"github.com/blevesearch/bleve"
)
var indexPath = flag.String("index", "", "index path")
var limit = flag.Int("limit", 10, "limit to first N results")
var skip = flag.Int("skip", 0, "skip the first N results")
var explain = flag.Bool("explain", false, "explain scores")
var includeHighlights = flag.Bool("highlight", true, "highlight matches")
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var repeat = flag.Int("repeat", 1, "repeat query n times")
func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
err = pprof.StartCPUProfile(f)
if err != nil {
log.Fatal(err)
}
defer pprof.StopCPUProfile()
}
if *indexPath == "" {
log.Fatal("Specify index to query")
}
if flag.NArg() < 1 {
log.Fatal("Specify search query")
}
// open index
index, err := bleve.Open(*indexPath)
if err != nil {
log.Fatal(err)
}
defer func() {
cerr := index.Close()
if cerr != nil {
log.Fatalf("error closing index: %v", err)
}
}()
for i := 0; i < *repeat; i++ {
// build a search with the provided parameters
queryString := strings.Join(flag.Args(), " ")
query := bleve.NewQueryStringQuery(queryString)
searchRequest := bleve.NewSearchRequestOptions(query, *limit, *skip, *explain)
// enable highlights if requested
if *includeHighlights {
searchRequest.Highlight = bleve.NewHighlightWithStyle("ansi")
}
// execute the search
searchResult, err := index.Search(searchRequest)
if err != nil {
log.Fatalf("search error: %v", err)
}
fmt.Println(searchResult)
}
}

View file

@ -0,0 +1,82 @@
// Copyright (c) 2014 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package main
import (
"fmt"
"sort"
_ "github.com/blevesearch/bleve"
"github.com/blevesearch/bleve/registry"
)
func main() {
fmt.Printf("Bleve Registry:\n")
printRegistry()
}
func printRegistry() {
types, instances := registry.CharFilterTypesAndInstances()
printType("Char Filter", types, instances)
types, instances = registry.TokenizerTypesAndInstances()
printType("Tokenizer", types, instances)
types, instances = registry.TokenMapTypesAndInstances()
printType("Token Map", types, instances)
types, instances = registry.TokenFilterTypesAndInstances()
printType("Token Filter", types, instances)
types, instances = registry.AnalyzerTypesAndInstances()
printType("Analyzer", types, instances)
types, instances = registry.DateTimeParserTypesAndInstances()
printType("Date Time Parser", types, instances)
types, instances = registry.KVStoreTypesAndInstances()
printType("KV Store", types, instances)
types, instances = registry.ByteArrayConverterTypesAndInstances()
printType("ByteArrayConverter", types, instances)
types, instances = registry.FragmentFormatterTypesAndInstances()
printType("Fragment Formatter", types, instances)
types, instances = registry.FragmenterTypesAndInstances()
printType("Fragmenter", types, instances)
types, instances = registry.HighlighterTypesAndInstances()
printType("Highlighter", types, instances)
}
func sortStrings(in []string) []string {
sortedStrings := make(sort.StringSlice, 0, len(in))
for _, str := range in {
sortedStrings = append(sortedStrings, str)
}
sortedStrings.Sort()
return sortedStrings
}
func printType(label string, types, instances []string) {
sortedTypes := sortStrings(types)
sortedInstances := sortStrings(instances)
fmt.Printf(label + " Types:\n")
for _, name := range sortedTypes {
fmt.Printf("\t%s\n", name)
}
fmt.Println()
fmt.Printf(label + " Instances:\n")
for _, name := range sortedInstances {
fmt.Printf("\t%s\n", name)
}
fmt.Println()
}