Getting Started

The simplest way to get started with bleve is to use the standard go get operation:

  1. go get github.com/blevesearch/bleve/...

This will build a pure Go version of bleve and install the command-line utility.

Your first bleve program

Create a new package, edit main.go and paste:

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/blevesearch/bleve"
  5. )
  6. func main() {
  7. // open a new index
  8. mapping := bleve.NewIndexMapping()
  9. index, err := bleve.New("example.bleve", mapping)
  10. if err != nil {
  11. fmt.Println(err)
  12. return
  13. }
  14. data := struct {
  15. Name string
  16. }{
  17. Name: "text",
  18. }
  19. // index some data
  20. index.Index("id", data)
  21. // search for some text
  22. query := bleve.NewMatchQuery("text")
  23. search := bleve.NewSearchRequest(query)
  24. searchResults, err := index.Search(search)
  25. if err != nil {
  26. fmt.Println(err)
  27. return
  28. }
  29. fmt.Println(searchResults)
  30. }

This should compile, run, and return one search hit for the item added.