solr

package module
v1.0.27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2018 License: MIT Imports: 21 Imported by: 0

README

SendGrid Logo

travis Go Report Card GoDoc MIT licensed CLA assistant

go-solr

solr go client from Sendgrid

Usage

To start the client

solrzk := solr.NewSolrZK(...)
solrzk.Listen()
solrhttp := solr.NewSolrHttp(solrzk)
solrClient := solr.NewSolrHttpRetrier(solrhttp)

The Read and Update methods take a node list use the SolrLocator interface to return a node list

locator := solr.GetSolrLocator(solr.NewSolrZK(...))
type SolrLocator interface {
	GetLeaders(docID string) ([]string, error)
	GetReplicaUris() ([]string, error)
	GetReplicasFromRoute(route string) ([]string, error)
	GetLeadersAndReplicas(docID string) ([]string, error)
}

To make requests

solrClient.Select(locator.GetReplicasFromRoute("shard!"),solr.FilterQuery("myfield:test"),solr.Route("shardkey!"))

To make updates

solrClient.Update(locator.GetLeadersAndReplicas("{anydocidtoroute}"),collectionName,callsSolrJsonDocs, docsMap)

Tests on solr

  1. docker-compose up
  2. docker-compose run gotests bash
  3. go test
  4. go run ./cmd/solrRunner.go 1000

Tests with cluster of 3 solrs

  1. docker-compose -p cluster -f docker-compose.cluster.yml up
  2. docker-compose -p cluster run gotests bash
  3. go test
  4. go run ./cmd/solrRunner.go 1000

License

The MIT License (MIT)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = NewNotFoundError("Not found")

Functions

func Cert

func Cert(cert string) func(*solrHttp)

The path to tls certificate (optional)

func ClusterStateVersion

func ClusterStateVersion(version int, collection string) func(url.Values)

func Commit

func Commit(commit bool) func(url.Values)

func ConnectionTimeout added in v1.0.26

func ConnectionTimeout(seconds int) func(*solrHttp)

func Cursor

func Cursor(c string) func(url.Values)

func DefaultRows

func DefaultRows(rows uint32) func(*solrHttp)

DefaultRows sets number of rows for pagination in calls that don't pass a number of rows in

func DeleteStreamBody

func DeleteStreamBody(filter string) func(url.Values)

func FilterQuery

func FilterQuery(fq string) func(url.Values)

Helper funcs for setting the solr query params

func GetDocIdFromDoc

func GetDocIdFromDoc(m map[string]interface{}) string

func GetVersionFromDoc

func GetVersionFromDoc(m map[string]interface{}) int

func HTTPClient

func HTTPClient(cli HTTPer) func(*solrHttp)

HTTPClient sets the HTTPer

func Hash

func Hash(key CompositeKey) int32

func HttpLogger

func HttpLogger(logger Logger) func(*solrHttp)

func InsecureSkipVerify added in v1.0.15

func InsecureSkipVerify(insecureSkipVerify bool) func(*solrHttp)

func MinRF

func MinRF(minRf int) func(*solrHttp)

func NewNotFoundError

func NewNotFoundError(error string) error

func NewSolrBatchError

func NewSolrBatchError(err error) error

func NewSolrError

func NewSolrError(status int, message string) error

func NewSolrInternalError

func NewSolrInternalError(status int, message string) error

func NewSolrLeaderError

func NewSolrLeaderError(docID string) error

func NewSolrMapParseError

func NewSolrMapParseError(bucket string, userId int, m map[string]interface{}) error

func NewSolrParseError

func NewSolrParseError(status int, message string) error

func NewSolrRFError

func NewSolrRFError(rf, minRF int) error

func Password

func Password(password string) func(*solrHttp)

func PreferLocalShards added in v1.0.24

func PreferLocalShards(preferLocalShards bool) func(url.Values)

func Query

func Query(q string) func(url.Values)

func QueryRouter added in v1.0.25

func QueryRouter(router Router) func(*solrHttp)

func ReadTimeout added in v1.0.17

func ReadTimeout(seconds int) func(*solrHttp)

func Route

func Route(r string) func(url.Values)

func Rows

func Rows(rows uint32) func(url.Values)

func SleepTimeMS added in v1.0.12

func SleepTimeMS(sleepTimeMS int) func(*solrZkInstance)

func SolrZKLogger added in v1.0.18

func SolrZKLogger(logger Logger) func(s *solrZkInstance)

func Sort

func Sort(s string) func(url.Values)

func Start

func Start(start uint32) func(url.Values)

func UrlVals

func UrlVals(urlVals url.Values) func(url.Values)

func User

func User(user string) func(*solrHttp)

func WriteTimeout added in v1.0.17

func WriteTimeout(seconds int) func(*solrHttp)

Types

type Adds

type Adds map[string]int

type ClusterProps

type ClusterProps struct {
	UrlScheme string `json:"urlScheme"`
}

type ClusterState

type ClusterState struct {
	LiveNodes   []string
	Version     int
	Collections map[string]Collection
}

type Collection

type Collection struct {
	Shards            map[string]Shard `json:"shards"`
	ReplicationFactor string           `json:"replicationFactor"`
}

type CompositeKey

type CompositeKey struct {
	ShardKey string
	DocID    string
	Bits     uint
}

func NewCompositeKey

func NewCompositeKey(id string) (CompositeKey, error)

type DeleteRequest

type DeleteRequest struct {
	Delete []string `json:"delete"`
}

type HTTPer

type HTTPer interface {
	Do(*http.Request) (*http.Response, error)
}

type HashRange

type HashRange struct {
	Low  int32
	High int32
}

func ConvertToHashRange

func ConvertToHashRange(hashRange string) (HashRange, error)

type Logger

type Logger interface {
	Error(err error)
	Info(v ...interface{})
	Debug(v ...interface{})
	Printf(format string, v ...interface{})
}

type NotFoundError

type NotFoundError struct {
	// contains filtered or unexported fields
}

func (NotFoundError) Error

func (err NotFoundError) Error() string

type Replica

type Replica struct {
	Core     string `json:"core"`
	Leader   string `json:"leader"`
	BaseURL  string `json:"base_url"`
	NodeName string `json:"node_name"`
	State    string `json:"state"`
}

type Response

type Response struct {
	NumFound uint32                   `json:"numFound"`
	Start    int                      `json:"start"`
	Docs     []map[string]interface{} `json:"docs"`
}

type Router added in v1.0.25

type Router interface {
	GetUriFromList(urisIn []string) string
	AddSearchResult(t time.Duration, uri string, statusCode int, err error)
}

func NewAdaptiveRouter added in v1.0.25

func NewAdaptiveRouter(recency int) Router

func NewRoundRobinRouter added in v1.0.25

func NewRoundRobinRouter() Router

type Shard

type Shard struct {
	Name     string             `json:"-"`
	Range    string             `json:"range"`
	State    string             `json:"state"`
	Replicas map[string]Replica `json:"replicas"`
}

type SolrBatchError

type SolrBatchError struct {
	// contains filtered or unexported fields
}

type SolrError

type SolrError struct {
	// contains filtered or unexported fields
}

func (SolrError) Error

func (err SolrError) Error() string

type SolrHTTP

type SolrHTTP interface {
	Select(nodeUris []string, opts ...func(url.Values)) (SolrResponse, error)
	Update(nodeUris []string, singleDoc bool, doc interface{}, opts ...func(url.Values)) error
	Logger() Logger
}

func NewSolrHTTP

func NewSolrHTTP(useHTTPS bool, collection string, options ...func(*solrHttp)) (SolrHTTP, error)

func NewSolrHttpRetrier

func NewSolrHttpRetrier(solrHttp SolrHTTP, retries int, exponentialBackoff time.Duration) SolrHTTP

type SolrHealthcheckResponse

type SolrHealthcheckResponse struct {
	LiveNodes              []string `json:"live_nodes"`
	DownReplicas           []string `json:"down_replicas"`
	RecoveryFailedReplicas []string `json:"recovery_failed_replicas"`
}

type SolrHttpRetrier

type SolrHttpRetrier struct {
	// contains filtered or unexported fields
}

func (*SolrHttpRetrier) Logger

func (s *SolrHttpRetrier) Logger() Logger

func (*SolrHttpRetrier) Select added in v1.0.24

func (s *SolrHttpRetrier) Select(nodeUris []string, opts ...func(url.Values)) (SolrResponse, error)

func (*SolrHttpRetrier) Update

func (s *SolrHttpRetrier) Update(nodeUris []string, jsonDocs bool, doc interface{}, opts ...func(url.Values)) error

type SolrInternalError

type SolrInternalError struct {
	SolrError
}

type SolrLeaderError

type SolrLeaderError struct {
	SolrError
}

type SolrLocator added in v1.0.3

type SolrLocator interface {
	GetLeaders(docID string) ([]string, error)
	GetReplicaUris() ([]string, error)
	GetReplicasFromRoute(route string) ([]string, error)
	GetShardFromRoute(route string) (string, error)
	GetLeadersAndReplicas(docID string) ([]string, error)
}

type SolrLogger added in v1.0.20

type SolrLogger struct {
	*log.Logger
}

func (*SolrLogger) Debug added in v1.0.20

func (l *SolrLogger) Debug(v ...interface{})

func (*SolrLogger) Error added in v1.0.20

func (l *SolrLogger) Error(err error)

func (*SolrLogger) Info added in v1.0.20

func (l *SolrLogger) Info(v ...interface{})

func (*SolrLogger) Printf added in v1.0.20

func (l *SolrLogger) Printf(format string, v ...interface{})

type SolrMapParseError

type SolrMapParseError struct {
	// contains filtered or unexported fields
}

func (SolrMapParseError) Error

func (err SolrMapParseError) Error() string

type SolrMinRFError added in v1.0.20

type SolrMinRFError struct {
	SolrError
	MinRF int
}

type SolrParseError

type SolrParseError struct {
	SolrError
}

type SolrResponse

type SolrResponse struct {
	Status int `json:"status"`
	QTime  int `json:"qtime"`
	Params struct {
		Query  string `json:"q"`
		Indent string `json:"indent"`
		Wt     string `json:"wt"`
	} `json:"params"`
	Response       Response `json:"response"`
	NextCursorMark string   `json:"nextCursorMark"`
	Adds           Adds     `json:"adds"`
}

type SolrZK

type SolrZK interface {
	GetZookeepers() string
	GetClusterState() (ClusterState, error)
	GetClusterProps() (ClusterProps, error)
	Listen() error
	Listening() bool
	GetSolrLocator() SolrLocator
	UseHTTPS() (bool, error)
}

func NewSolrZK

func NewSolrZK(zookeepers string, zkRoot string, collectionName string, opts ...func(*solrZkInstance)) SolrZK

type UpdateResponse

type UpdateResponse struct {
	Response struct {
		Status int `json:"status"`
		QTime  int `json:"QTime"`
		RF     int `json:"rf"`
		MinRF  int `json:"min_rf"`
	} `json:"responseHeader"`
	Error struct {
		Metadata []string `json:"metadata"`
		Msg      string   `json:"msg"`
		Code     int      `json:"code"`
	}
}

type Zookeeper

type Zookeeper interface {
	IsConnected() bool
	Connect() error
	GetConnectionString() string
	Get(path string) ([]byte, int, error)
	Poll(path string, cb stateChanged)
	GetClusterState() (map[string]Collection, int, error)
	GetClusterStateW() (map[string]Collection, int, <-chan zk.Event, error)
	GetLiveNodes() ([]string, error)
	GetLiveNodesW() ([]string, <-chan zk.Event, error)
	GetLeaderElectW() (<-chan zk.Event, error)
	GetClusterProps() (ClusterProps, error)
	ZKLogger(l Logger)
}

func NewZookeeper

func NewZookeeper(connectionString string, zkRoot string, collection string) Zookeeper

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL