本文整理匯總了Golang中github.com/blevesearch/bleve.Open函數的典型用法代碼示例。如果您正苦於以下問題:Golang Open函數的具體用法?Golang Open怎麽用?Golang Open使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Open函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: search
func search(cfg *Config) error {
store, err := OpenStore(cfg.Store())
if err != nil {
return err
}
index, err := bleve.Open(cfg.Index())
if err != nil {
return err
}
defer index.Close()
q, err := makeSearchQuery(*searchQuery, nil)
if err != nil {
return err
}
rq := bleve.NewSearchRequest(q)
rq.Size = 100
ids := []string{}
for {
res, err := index.Search(rq)
if err != nil {
return err
}
for _, doc := range res.Hits {
ids = append(ids, doc.ID)
}
if len(res.Hits) < rq.Size {
break
}
rq.From += rq.Size
}
return printOffers(store, ids)
}
示例2: OpenBlevePIndexImpl
func OpenBlevePIndexImpl(indexType, path string,
restart func()) (cbgt.PIndexImpl, cbgt.Dest, error) {
buf, err := ioutil.ReadFile(path +
string(os.PathSeparator) + "PINDEX_BLEVE_META")
if err != nil {
return nil, nil, err
}
bleveParams := NewBleveParams()
err = json.Unmarshal(buf, bleveParams)
if err != nil {
return nil, nil, fmt.Errorf("bleve: parse params: %v", err)
}
// TODO: boltdb sometimes locks on Open(), so need to investigate,
// where perhaps there was a previous missing or race-y Close().
bindex, err := bleve.Open(path)
if err != nil {
return nil, nil, err
}
return bindex, &cbgt.DestForwarder{
DestProvider: NewBleveDest(path, bindex, restart),
}, nil
}
示例3: 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)
}
示例4: 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)
}
示例5: OpenIndex
func OpenIndex() {
index, err := bleve.Open(IndexDBDir)
LimeIndex = index
if err != nil {
fmt.Println(err)
return
}
}
示例6: Delete
func (be *BleveEngine) Delete() error {
index, err := bleve.Open(INDEX)
if err != nil {
return err
}
index.Close()
os.RemoveAll(INDEX)
return nil
}
示例7: main
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)
}
}
示例8: Search
func (be *BleveEngine) Search(query string) (interface{}, error) {
index, _ := bleve.Open(INDEX)
bleveQuery := bleve.NewQueryStringQuery(query)
searchRequest := bleve.NewSearchRequest(bleveQuery)
searchResults, err := index.Search(searchRequest)
if err != nil {
return nil, err
}
return searchResults, nil
}
示例9: 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}
}
示例10: 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
}
示例11: 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)
}
}
示例12: main
// START OMIT
func main() {
index, err := bleve.Open("people.bleve") // HLOPEN
if err != nil {
log.Fatal(err)
}
query := bleve.NewTermQuery("marty") // HLQUERY
request := bleve.NewSearchRequest(query) // HLREQ
result, err := index.Search(request) // HLSEARCH
if err != nil {
log.Fatal(err)
}
fmt.Println(result)
}
示例13: debugQueryFn
func debugQueryFn(cfg *Config) error {
index, err := bleve.Open(cfg.Index())
if err != nil {
return err
}
defer index.Close()
q, err := makeSearchQuery(*debugQueryQuery, nil)
if err != nil {
return err
}
s, err := query.DumpQuery(index.Mapping(), q)
fmt.Println(s)
return err
}
示例14: 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))
}
示例15: 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)
})
})
}