solr

package module
v2.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 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

This section is empty.

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 CommitWithin

func CommitWithin(duration time.Duration) func(url.Values)

func ConnectionTimeout

func ConnectionTimeout(seconds int) func(*solrHttp)

func Cursor

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

func DebugTiming added in v2.0.8

func DebugTiming() 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

func InsecureSkipVerify(insecureSkipVerify bool) func(*solrHttp)

func MinRF

func MinRF(minRf int) func(*solrHttp)

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

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

func Query

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

func QueryRouter

func QueryRouter(router Router) func(*solrHttp)

func ReadTimeout

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

func SleepTimeMS(sleepTimeMS int) func(*solrZkInstance)

func SolrZKLogger

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 WithVersions

func WithVersions() func(url.Values)

func WriteTimeout

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 Debug added in v2.0.8

type Debug struct {
	Timing Timing `json:"timing"`
}

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 HttpError

type HttpError struct {
	Message string
	Status  int
}

HttpError - An Error due to a http response >= 400

func (HttpError) Error

func (err HttpError) Error() string

type Logger

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

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

type Router interface {
	GetUriFromList(urisIn []string) string
}

func NewRoundRobinRouter

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)) (UpdateResponse, 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

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)) (response UpdateResponse, err error)

type SolrInternalError

type SolrInternalError struct {
	SolrError
}

type SolrLeaderError

type SolrLeaderError struct {
	SolrError
}

type SolrLocator

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

type SolrLogger struct {
	*log.Logger
}

func (*SolrLogger) Debug

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

func (*SolrLogger) Error

func (l *SolrLogger) Error(err error)

func (*SolrLogger) Info

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

func (*SolrLogger) Printf

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

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"`
	Debug          *Debug   `json:"debug"`
	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 StageTiming added in v2.0.8

type StageTiming struct {
	Time float64 `json:"time"`
}

type Timing added in v2.0.8

type Timing struct {
	Time    float64     `json:"time"`
	Prepare StageTiming `json:"prepare"`
	Process StageTiming `json:"process"`
}

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"`

	// <adds> is a weird return value. It mixes ids with versions in a single slice, e.g.
	// ["id1",1233144,"id2",4122243], to get only the ids call AddedIDs afterwards
	Adds []interface{} `json:"adds"`

	Error struct {
		Metadata []string `json:"metadata"`
		Msg      string   `json:"msg"`
		Code     int      `json:"code"`
	}
}

func (UpdateResponse) AddedIDs

func (r UpdateResponse) AddedIDs() (ids map[string]int64, err error)

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