vanng822 / go-solr

Solr client in Go, core admin, add docs, update, delete, search and more
MIT License
69 stars 42 forks source link

Handle cancellations and graceful shutdowns using standard context.Context #57

Open alexu84 opened 3 years ago

alexu84 commented 3 years ago

Add support to pass standard context.Context to Search and other functions in order to handle cancellations and graceful shutdowns properly.

Sample use:

package main
import (
        "context"
    "github.com/vanng822/go-solr/solr"
    "fmt"
)

func main() {
  ctx := context.Background()

  si, _ := solr.NewSolrInterfaceWithCtx(ctx, "http://localhost:8983/solr", "collection1")

  query := solr.NewQuery()
  query.Q("*:*")

  s := si.SearchWithCtx(ctx, query)
  r, _ := s.Result(nil)

  fmt.Println(r.Results.Docs)
}