-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc_test.go
41 lines (35 loc) · 864 Bytes
/
doc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package bdodb_test
import (
"fmt"
"github.com/blevesearch/bleve"
"github.com/blevesearch/bleve/index/upsidedown"
"github.com/mkawserm/bdodb"
)
func ExampleBleveIndex() {
// create or open bleveIndex
index, err := bdodb.BleveIndex("/tmp/bdodb_example", bleve.NewIndexMapping(), upsidedown.Name, nil)
if err != nil {
panic(err)
}
message := struct {
Id string
Body string
}{
Id: "custom_id",
Body: "bleve indexing with badger using bdodb",
}
// index message data
if val, _ := index.Document(message.Id); val == nil {
if err := index.Index(message.Id, message); err != nil {
panic(err)
}
}
// search for some text
query := bleve.NewQueryStringQuery("bdodb")
search := bleve.NewSearchRequest(query)
if searchResults, err := index.Search(search); err == nil {
fmt.Println(searchResults)
} else {
fmt.Println(err)
}
}