本文整理匯總了Golang中github.com/blevesearch/bleve.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: openIndex
func openIndex(path string) (bleve.Index, error) {
if _, err := os.Stat(path); os.IsNotExist(err) {
mapping := bleve.NewIndexMapping()
return bleve.New(path, mapping)
}
return bleve.Open(path)
}
示例2: main
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 index.Close()
log.Printf("Created bleve index at: %s", *indexPath)
}
示例3: main
func main() {
// Open an index if it already exists.
index, err := bleve.Open("example.bleve")
if err != nil {
mapping := bleve.NewIndexMapping()
index, err = bleve.New("example.bleve", mapping)
if err != nil {
fmt.Println(err)
return
}
}
data := struct {
Name string
}{
Name: "text",
}
// Index some data.
index.Index("id", data)
// Search for some text
query := bleve.NewMatchQuery("text")
search := bleve.NewSearchRequest(query)
searchResults, err := index.Search(search)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(searchResults)
}
示例4: main
func main() {
// open a new index
mapping := bleve.NewIndexMapping()
index, err := bleve.New("example.bleve", mapping)
if err != nil {
fmt.Println(err)
return
}
data := struct {
Name string
}{
Name: "text",
}
// index some data
index.Index("id", data)
// search for some text
query := bleve.NewMatchQuery("text")
search := bleve.NewSearchRequest(query)
searchResults, err := index.Search(search)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(searchResults)
}
示例5: NewBleveRecipeStore
func NewBleveRecipeStore(path string) RecipeStore {
idx, err := bleve.Open(path)
if err == bleve.ErrorIndexPathDoesNotExist {
mapping := bleve.NewIndexMapping()
idx, err = bleve.New(path, mapping)
}
if err != nil {
panic(fmt.Errorf("could not open/create bleve idx at %s: %v", path, err))
}
return &BleveRecipeStore{idx: idx}
}
示例6: Init
func Init(allDocs GetAllDocsFn) {
var err error
idx_path := path.Join(config.Current.DataDir, index_name)
index, err = bleve.Open(idx_path)
if err == bleve.ErrorIndexPathDoesNotExist {
log.Info("Creating new Index")
indexMapping := bleve.NewIndexMapping()
indexMapping.DefaultAnalyzer = config.Current.DefaultAnalyzer
entryMapping := bleve.NewDocumentMapping()
textField := bleve.NewTextFieldMapping()
entryMapping.AddFieldMappingsAt("Body", textField)
entryMapping.AddFieldMappingsAt("Title", textField)
tagField := bleve.NewTextFieldMapping()
tagField.Analyzer = tag_analyzer
entryMapping.AddFieldMappingsAt("Tags", tagField)
indexMapping.AddDocumentMapping("entry", entryMapping)
index, err = bleve.New(idx_path, indexMapping)
if err != nil {
log.Fatal(err)
}
// reindex existing documents
indexRebuildingLogged := false
for itm := range allDocs() {
if !indexRebuildingLogged {
indexRebuildingLogged = true
log.Info("Start rebuilding Search-Index")
}
index.Index(itm.Id(), itm.Content())
}
if indexRebuildingLogged {
log.Info("Finished rebuilding Search-Index")
}
} else if err == nil {
log.Info("Opening existing Index")
} else {
log.Fatal(err)
}
}
示例7: main
func main() {
mapping := bleve.NewIndexMapping()
index, err := bleve.New("people.bleve", mapping)
if err != nil {
log.Fatal(err)
}
person := Person{"Marty Schoch"}
err = index.Index("m1", person)
if err != nil {
log.Fatal(err)
}
fmt.Println("Indexed Document")
}
示例8: main
func main() {
mapping := bleve.NewIndexMapping() // HLMAPPING
index, err := bleve.New("people.bleve", mapping) // HLNEW
if err != nil {
log.Fatal(err)
}
person := Person{"Marty Schoch"} // HLINDEX
err = index.Index("m1", person) // HLINDEX
if err != nil {
log.Fatal(err)
}
fmt.Println("Indexed Document")
}
示例9: New
func New(path, language string) (*Index, error) {
index, err := bleve.Open(path)
if err == bleve.ErrorIndexPathDoesNotExist {
indexMapping := buildIndexMapping(language)
index, err = bleve.New(path, indexMapping)
if err != nil {
return nil, err
}
} else if err != nil {
return nil, err
}
return &Index{index: index}, nil
}
示例10: main
func main() {
flag.Parse()
// open the index
beerIndex, err := bleve.Open(*indexPath)
if err == bleve.ErrorIndexPathDoesNotExist {
log.Printf("Creating new index...")
// create a mapping
indexMapping, err := buildIndexMapping()
if err != nil {
log.Fatal(err)
}
beerIndex, err = bleve.New(*indexPath, indexMapping)
if err != nil {
log.Fatal(err)
}
// index data in the background
go func() {
err = indexBeer(beerIndex)
if err != nil {
log.Fatal(err)
}
}()
} else if err != nil {
log.Fatal(err)
} else {
log.Printf("Opening existing index...")
}
// create a router to serve static files
router := staticFileRouter()
// add the API
bleveHttp.RegisterIndexName("beer", beerIndex)
searchHandler := bleveHttp.NewSearchHandler("beer")
router.Handle("/api/search", searchHandler).Methods("POST")
listFieldsHandler := bleveHttp.NewListFieldsHandler("beer")
router.Handle("/api/fields", listFieldsHandler).Methods("GET")
debugHandler := bleveHttp.NewDebugDocumentHandler("beer")
router.Handle("/api/debug/{docID}", debugHandler).Methods("GET")
// start the HTTP server
http.Handle("/", router)
log.Printf("Listening on %v", *bindAddr)
log.Fatal(http.ListenAndServe(*bindAddr, nil))
}
示例11: TestBeerSearchBug87
// this test reproduces bug #87
// https://github.com/blevesearch/bleve/issues/87
// because of which, it will deadlock
func TestBeerSearchBug87(t *testing.T) {
defer os.RemoveAll("beer-search-test.bleve")
mapping, err := buildIndexMapping()
if err != nil {
t.Fatal(err)
}
index, err := bleve.New("beer-search-test.bleve", mapping)
if err != nil {
t.Fatal(err)
}
defer index.Close()
// start indexing documents in the background
go func() {
// open the directory
dirEntries, err := ioutil.ReadDir("data/")
if err != nil {
t.Fatal(err)
}
for _, dirEntry := range dirEntries {
filename := dirEntry.Name()
jsonBytes, err := ioutil.ReadFile("data/" + filename)
if err != nil {
t.Fatal(err)
}
ext := filepath.Ext(filename)
docId := filename[:(len(filename) - len(ext))]
index.Index(docId, jsonBytes)
}
}()
// give indexing a head start
time.Sleep(1 * time.Second)
// start querying
for i := 0; i < 1000; i++ {
time.Sleep(1 * time.Millisecond)
termQuery := bleve.NewTermQuery("shock").SetField("name")
termSearchRequest := bleve.NewSearchRequest(termQuery)
// termSearchRequest.AddFacet("styles", bleve.NewFacetRequest("style", 3))
termSearchRequest.Fields = []string{"abv"}
_, err := index.Search(termSearchRequest)
if err != nil {
t.Error(err)
}
}
}
示例12: openIndex
// Open or create a search index
// @return result.Result<bleve.Index, error>
func openIndex(repoPath string, ifSuccess func(*git.Repository, bleve.Index) result.Result) result.Result {
storage := filepath.Join(repoPath, gc.CommentStorageDir)
indexPath := filepath.Join(storage, indexFilePath)
return gg.WithRepository(repoPath, func(repo *git.Repository) result.Result {
os.Mkdir(storage, 0700)
success := func(index interface{}) result.Result {
return ifSuccess(repo, index.(bleve.Index))
}
return result.NewResult(bleve.Open(indexPath)).Analysis(success, func(err error) result.Result {
mapping := bleve.NewIndexMapping()
index := result.NewResult(bleve.New(indexPath, mapping))
return index.FlatMap(success)
})
})
}
示例13: initIndex
func initIndex(name string) error {
indexPath := *dataDir + string(os.PathSeparator) + name
if _, err := os.Stat(indexPath); os.IsNotExist(err) {
log.Printf("%s does not exist. Creating...", name)
index, err := bleve.New(indexPath, bleve.NewIndexMapping())
if err != nil {
return err
}
// close so we can open later
index.Close()
log.Printf("%s created.", name)
}
return nil
}
示例14: Index
func (be *BleveEngine) Index(document *Document) (int64, error) {
start := time.Now().UnixNano() / int64(time.Millisecond)
var index bleve.Index
mapping := bleve.NewIndexMapping()
index, err := bleve.New(INDEX, mapping)
if err != nil {
index, _ = bleve.Open(INDEX)
}
id := (*document).Id
data := (*document).Data
index.Index(id, data)
index.Close()
return time.Now().UnixNano()/int64(time.Millisecond) - start, nil
}
示例15: NewIndexer
// NewIndexer prepares a new Indexer given the necessary Parse App credentials.
func NewIndexer(webhookKey, masterKey, appID string) (*Indexer, error) {
path := "contents.bleve"
i, err := bleve.Open(path)
if err == bleve.ErrorIndexPathDoesNotExist {
im := bleve.NewIndexMapping()
i, err = bleve.New(path, im)
} else if err != nil {
return nil, err
}
return &Indexer{
index: i,
webhookKey: webhookKey,
masterKey: masterKey,
appID: appID,
status: &indexStatusList{},
}, nil
}