solr

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: MIT Imports: 12 Imported by: 0

README

Solr Lib

A simple solr client lib.

Create a solr instance:


inst, err := NewCloud("http://localhost:8983", time.Duration(20*time.Second), time.Duration(20*time.Second), 100, 100, params, &solr.DefaultDocumentParser{}, &solr.DefaultDocumentWriter{})
if err != nil {
		panic(err)
	}
	

Create a collection:

err := inst.Create("CollectionName")
if err != nil {
		panic(err)
	}

Send documents to solr server:

params := make(map[string]string)
payload := `[{
	"id": 1,
	"metric": "solr_metric"
}]`
err = inst.UpdateDocument("CollectionName", params, payload)
if err != nil {
	panic(err)
}

Search documents:

searchParams := &solr.SearchParams{
	Q:      "*:*",
	Rows:   10,
}
inst.Search(searchParams, "CollectionName")

Delete collection:

inst.Delete("CollectionName")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudParams

type CloudParams struct {
	CollectionConfigName string
	NumShards            int
	MaxShardsPerNode     int
	ReplicationFactor    int
	AdvancedOptions      map[string]string
}

CloudParams - parameters for creating collection

type DefaultDocumentParser

type DefaultDocumentParser struct {
}

DefaultDocumentParser - Default parser

func (*DefaultDocumentParser) Parse

func (p *DefaultDocumentParser) Parse(raw []byte) (interface{}, error)

Parse - parses a document and return a default struct

type DefaultDocumentWriter

type DefaultDocumentWriter struct {
}

DefaultDocumentWriter - default update document writer

func (*DefaultDocumentWriter) Writer

func (u *DefaultDocumentWriter) Writer(payload interface{}) ([]byte, error)

Writer - default document writer

type DeleteResponse

type DeleteResponse struct {
	ResponseHeader struct {
		Status int `json:"status"`
		QTime  int `json:"QTime"`
	} `json:"responseHeader"`
}

DeleteResponse - response delete

type DocumentParser

type DocumentParser interface {

	// Parse - parses the pure document input from JSON
	Parse(documents []byte) (interface{}, error)
}

DocumentParser - a generic document parser

type DocumentRaw

type DocumentRaw map[string]interface{}

DocumentRaw - Just as it comes from Solr

type DocumentWriter

type DocumentWriter interface {

	// Writer - writes a document
	Writer(payload interface{}) ([]byte, error)
}

DocumentWriter - a generic document writer

type FacetField

type FacetField struct {
	Name string
	List []FacetValue
}

FacetField - struct for facets

type FacetValue

type FacetValue struct {
	Name  string
	Value int64
}

FacetValue - struct for facets name and value

type Instance

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

Instance The main class to instance solr

func NewCloud

func NewCloud(coreURL string, httpGeTimeout, httpPosTimeout time.Duration, httpGetmaxConn, httpPotmaxConn int, cloudParams *CloudParams, documentParser DocumentParser, documentWriter DocumentWriter) (*Instance, error)

NewCloud - create new cloud instance

func NewCore

func NewCore(coreURL string, httpGeTimeout, httpPosTimeout time.Duration, httpGetmaxConn, httpPotmaxConn int, coreConfig *SettingsSolrCore, documentParser DocumentParser, documentWriter DocumentWriter) *Instance

NewCore Create a new instance core Solr

func (*Instance) Create

func (s *Instance) Create(instanceName string) error

Create - create cores/collections

func (*Instance) Decode

func (s *Instance) Decode(raw []byte, facet bool) (*Response, error)

Decode - decode a raw byte from solr instance and return a formated response

func (*Instance) Delete

func (s *Instance) Delete(instanceName string) error

Delete - delete a core/collection

func (*Instance) List

func (s *Instance) List() ([]string, error)

List - List cores/collections

func (*Instance) Search

func (s *Instance) Search(params *SearchParams, instanceName string) (*Response, error)

Search A basic search in solr

func (*Instance) UpdateDocument

func (s *Instance) UpdateDocument(instanceName string, postParams map[string]string, payload interface{}) error

UpdateDocument - post json on solr, if the postParams is passed it will be adding in the request. For deleting items you can use the post function using the json format: https://lucene.apache.org/solr/guide/6_6/uploading-data-with-index-handlers.html#UploadingDatawithIndexHandlers-SendingJSONUpdateCommands

type Response

type Response struct {
	Status   int64        `json:"status,omitempty"`
	QTime    int64        `json:"Qtime,omitempty"`
	NumFound int64        `json:"numFound,omitempty"`
	Docs     interface{}  `json:"Docs,omitempty"`
	Facets   []FacetField `json:"Facets,omitempty"`
}

Response - response data from solr instance

type SearchParams

type SearchParams struct {
	Q                 string
	FL                string
	FilterQueries     []string
	BlockJoinFaceting bool
	Sort              string
	Facets            map[string]string
	Rows              int
	Start             int
}

SearchParams - Params for solr queries

type SettingsSolrCore

type SettingsSolrCore struct {
	CoreName    string //CoreName - The name of the new core. Same as "name" on the <core> element.
	InstanceDir string //InstanceDir - The directory where files for this SolrCore should be stored. Same as instanceDir on the <core> element.
	Config      string //Config - Name of the config file (i.e., solrconfig.xml) relative to instanceDir
	Schema      string //Schema - Name of the schema file to use for the core.
	DataDir     string //DataDir - Name of the data directory relative to instanceDir
}

SettingsSolrCore - Configurations for create a new solr core for more information visit https://lucene.apache.org/solr/guide/6_6/coreadmin-api.html

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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