forked from varia/go-sh-manymanuals
wip: more bleve exp energy
This commit is contained in:
parent
bf693add54
commit
299ff79397
14
exp/bleve.go
14
exp/bleve.go
@ -8,6 +8,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/blevesearch/bleve/v2"
|
"github.com/blevesearch/bleve/v2"
|
||||||
|
"github.com/blevesearch/bleve/v2/analysis/lang/en"
|
||||||
|
"github.com/blevesearch/bleve/v2/search/highlight/highlighter/ansi"
|
||||||
pdf "github.com/johbar/go-poppler"
|
pdf "github.com/johbar/go-poppler"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,8 +38,10 @@ func main() {
|
|||||||
// create or open a bleve index
|
// create or open a bleve index
|
||||||
var index bleve.Index
|
var index bleve.Index
|
||||||
var err error
|
var err error
|
||||||
mapping := bleve.NewIndexMapping()
|
idxMap := bleve.NewIndexMapping()
|
||||||
index, err = bleve.New("test.bleve", mapping)
|
idxMap.DefaultAnalyzer = en.AnalyzerName
|
||||||
|
|
||||||
|
index, err = bleve.New("test.bleve", idxMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
index, err = bleve.Open("test.bleve")
|
index, err = bleve.Open("test.bleve")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -86,8 +90,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// query for something! change the string to test other possibilities
|
// query for something! change the string to test other possibilities
|
||||||
query := bleve.NewMatchQuery("Enhanced-Page-Mode")
|
query := bleve.NewMatchQuery("slew rate")
|
||||||
|
|
||||||
search := bleve.NewSearchRequest(query)
|
search := bleve.NewSearchRequest(query)
|
||||||
|
search.Highlight = bleve.NewHighlightWithStyle(ansi.Name)
|
||||||
|
search.Size = 5
|
||||||
|
|
||||||
searchResults, err := index.Search(search)
|
searchResults, err := index.Search(search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user