solr

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: MIT Imports: 12 Imported by: 13

README

Solr-Go

Github Actions Coverage Status Go Report Card GoDoc

A Solr client for Go.

Installation

$ go get github.com/stevenferrer/solr-go

Example

import (
    "github.com/stevenferrer/solr-go"
)

...

// Create a client
baseURL := "http://solr.example.com"
client := solr.NewJSONClient(baseURL)

// Create a query
query := solr.NewQuery(solr.NewDisMaxQueryParser().
        Query("'solr rocks'").BuildParser()).
    Queries(solr.M{
        "query_filters": []solr.M{
            {
                "#size_tag": solr.M{
                    "field": solr.M{
                        "f":     "size",
                        "query": "XL",
                    },
                },
            },
            {
                "#color_tag": solr.M{
                    "field": solr.M{
                        "f":     "color",
                        "query": "Red",
                    },
                },
            },
        },
    }).
    Facets(
        solr.NewTermsFacet("categories").
            Field("cat").Limit(10),
        solr.NewQueryFacet("high_popularity").
            Query("popularity:[8 TO 10]"),
    ).
    Params(solr.M{
        "spellcheck.q": "solr rocks",
    }).
    Sort("score").
    Offset(1).
    Limit(10).
    Filters("inStock:true").
    Fields("name", "price")

// Send the query
queryResponse, err := client.Query(context.Background(), "techproducts", query)

See integration test for a more complete example.

Supported APIs

Other features

  • Basic auth support - Interacting with a Solr server that uses the basic authentication plugin.

Projects using it

A (minor) word of caution

Keep in mind that this library is still evolving and will likely have some breaking changes until v1.0. We will try our best to keep the breaking changes minimal.

Supporting the project

You can support the project in the following ways:

  • Give it a star, it's free!
  • Write some tutorials
  • Use it your projects

Contributing

Please feel free to improve this project by opening an issue or by making a pull-request.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EscapeQueryChars added in v0.4.0

func EscapeQueryChars(s string) string

EscapeQueryChars escapes special characters in the given Solr query string that would normally be treated as part of Solr's query syntax. For a full list of special characters, see the Solr documentation here: https://solr.apache.org/guide/solr/9_7/query-guide/standard-query-parser.html#escaping-special-characters

Returns the query string with special characters escaped

Types

type Analyzer added in v0.3.1

type Analyzer struct {
	Tokenizer   *Tokenizer `json:"tokenizer"`
	Filters     []Filter   `json:"filters,omitempty"`
	CharFilters []Filter   `json:"charFilters,omitempty"`
}

Analyzer is an analyzer

type BaseResponse added in v0.3.1

type BaseResponse struct {
	Header *ResponseHeader `json:"responseHeader"`
	Error  *ResponseError  `json:"error,omitempty"`
}

BaseResponse is the base response

type ChildrenQueryParser added in v0.3.1

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

ChildrenQueryParser is a block-join children query parser

func NewChildrenQueryParser added in v0.3.1

func NewChildrenQueryParser() *ChildrenQueryParser

NewChildrenQueryParser returns a new ChildrenQueryParser

func (*ChildrenQueryParser) BuildParser added in v0.3.1

func (qp *ChildrenQueryParser) BuildParser() string

BuildParser builds the query parser

func (*ChildrenQueryParser) ExcludeTags added in v0.3.1

func (qp *ChildrenQueryParser) ExcludeTags(tags string) *ChildrenQueryParser

ExcludeTags sets the excludeTags param

func (*ChildrenQueryParser) Filters added in v0.3.1

func (qp *ChildrenQueryParser) Filters(filters string) *ChildrenQueryParser

Filters sets the filters param

func (*ChildrenQueryParser) Of added in v0.3.1

Of sets the block-mask 'of' param

func (*ChildrenQueryParser) Query added in v0.3.1

Query sets the query

type Client

type Client interface {

	// CreateCollection creates a new collection.
	//
	// Refer to https://solr.apache.org/guide/8_8/collection-management.html#create
	CreateCollection(context.Context, *CollectionParams) error
	// DeleteCollection deletes a collection.
	// Refer to https://solr.apache.org/guide/8_8/collection-management.html#delete
	DeleteCollection(context.Context, *CollectionParams) error

	// CreateCore creates a new core
	//
	// Refer to https://solr.apache.org/guide/8_8/coreadmin-api.html#coreadmin-create
	CreateCore(context.Context, *CreateCoreParams) error
	// CoreStatus returns the status of all running Solr cores, or status for only the named core.
	//
	// Refer to https://solr.apache.org/guide/8_8/coreadmin-api.html#coreadmin-status
	CoreStatus(context.Context, *CoreParams) (*CoreStatusResponse, error)
	// UnloadCore removes a core from Solr
	//
	// Refer to https://solr.apache.org/guide/8_8/coreadmin-api.html#coreadmin-unload
	UnloadCore(context.Context, *CoreParams) error

	// Query sends a query to the query API.
	//
	// Refer to https://solr.apache.org/guide/8_8/json-request-api.html
	Query(ctx context.Context, collection string, query *Query) (*QueryResponse, error)

	// Update can be used to add, update, or delete a document from the index.
	//
	// Refer to https://solr.apache.org/guide/8_8/uploading-data-with-index-handlers.html
	Update(ctx context.Context, collection string, ct MimeType, body io.Reader) (*UpdateResponse, error)
	// Commit commits the last update
	Commit(ctx context.Context, collection string) error

	// AddFields adds new field definitions to the schema.
	//
	// Refer to https://solr.apache.org/guide/8_8/schema-api.html#add-a-new-field
	AddFields(ctx context.Context, collection string, fields ...Field) error
	// DeleteFields removes field definitions from the schema.
	//
	// Refer to https://solr.apache.org/guide/8_8/schema-api.html#delete-a-field
	DeleteFields(ctx context.Context, collection string, fields ...Field) error
	// ReplaceFields replaces field definition from the schema.
	//
	// Refer to https://solr.apache.org/guide/8_8/schema-api.html#replace-a-field
	ReplaceFields(ctx context.Context, collection string, fields ...Field) error
	// AddDynamicFields adds new dynamic field rules to the schema.
	//
	// Refer to https://solr.apache.org/guide/8_8/schema-api.html#add-a-dynamic-field-rule
	AddDynamicFields(ctx context.Context, collection string, fields ...Field) error
	// DeleteDynamicFields removes dynamic field rules from the schema.
	//
	// Refer to https://solr.apache.org/guide/8_8/schema-api.html#delete-a-dynamic-field-rule
	DeleteDynamicFields(ctx context.Context, collection string, fields ...Field) error
	// ReplaceDynamicFields replaces dynamic field rules from the schema.
	//
	// Refer to https://solr.apache.org/guide/8_8/schema-api.html#replace-a-dynamic-field-rule
	ReplaceDynamicFields(ctx context.Context, collection string, fields ...Field) error
	// AddFieldTypes adds new field types to the schema.
	//
	// Refer to https://solr.apache.org/guide/8_8/schema-api.html#add-a-new-field-type
	AddFieldTypes(ctx context.Context, collection string, fieldTypes ...FieldType) error
	// DeleteFieldTypes removes field type definitions from the schema.
	//
	// Refer to https://solr.apache.org/guide/8_8/schema-api.html#delete-a-field-type
	DeleteFieldTypes(ctx context.Context, collection string, fieldTypes ...FieldType) error
	// ReplaceFieldTypes replaces field type defintions from the schema.
	//
	// Refer to https://solr.apache.org/guide/8_8/schema-api.html#replace-a-field-type
	ReplaceFieldTypes(ctx context.Context, collection string, fieldTypes ...FieldType) error
	// AddCopyFields adds new copy field rules to the schema.
	//
	// Refer to https://solr.apache.org/guide/8_8/schema-api.html#add-a-new-copy-field-rule
	AddCopyFields(ctx context.Context, collection string, copyFields ...CopyField) error
	// DeleteCopyFields deletes copy field rules from the schema.
	//
	// Refer to https://solr.apache.org/guide/8_8/schema-api.html#delete-a-copy-field-rule
	DeleteCopyFields(ctx context.Context, collection string, copyFields ...CopyField) error

	// SetProperties sets well known properties.
	//
	// Refer to https://solr.apache.org/guide/8_8/config-api.html#commands-for-common-properties
	SetProperties(ctx context.Context, collection string, properties ...CommonProperty) error
	// UnsetProperty removes a property set via SetProperties.
	//
	// Refer to https://solr.apache.org/guide/8_8/config-api.html#commands-for-common-properties
	UnsetProperty(ctx context.Context, collection string, property CommonProperty) error
	// AddComponents adds a component (request handler, search component, init params, etc.) to configoverlay.json.
	//
	// Refer to https://solr.apache.org/guide/8_8/config-api.html#commands-for-handlers-and-components
	AddComponents(ctx context.Context, collection string, component ...*Component) error
	// UpdateComponents overwrites existing settings from configoverlay.json.
	//
	// Refer to https://solr.apache.org/guide/8_8/config-api.html#commands-for-handlers-and-components
	UpdateComponents(ctx context.Context, collection string, component ...*Component) error
	// DeleteComponents removes settings from configoverlay.json
	//
	// Refer to https://solr.apache.org/guide/8_8/config-api.html#commands-for-handlers-and-components
	DeleteComponents(ctx context.Context, collection string, component ...*Component) error

	// Suggest queries the suggest endpoint.
	//
	// Refer to https://solr.apache.org/guide/8_8/suggester.html#get-suggestions-with-weights
	Suggest(ctx context.Context, collection string, params *SuggestParams) (*SuggestResponse, error)
}

Client is an interface for interacting with Solr APIs (Collections, Core Admin, Query, Update, Schema, Config and Suggester)

type CollectionParams added in v0.3.1

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

CollectionParams is the collection API param builder

func NewCollectionParams added in v0.3.1

func NewCollectionParams() *CollectionParams

NewCollectionParams returns a new CollectionParams

func (*CollectionParams) Async added in v0.3.1

func (c *CollectionParams) Async(requestID string) *CollectionParams

Async enable async request with a request ID to track this action

func (*CollectionParams) BuildParams added in v0.3.1

func (c *CollectionParams) BuildParams() string

BuildParams builds the parameters

func (*CollectionParams) Name added in v0.3.1

func (c *CollectionParams) Name(name string) *CollectionParams

Name sets the collection name

func (*CollectionParams) NumShards added in v0.3.1

func (c *CollectionParams) NumShards(ns int) *CollectionParams

NumShards sets the number of shards

func (*CollectionParams) ReplicationFactor added in v0.3.1

func (c *CollectionParams) ReplicationFactor(rf int) *CollectionParams

ReplicationFactor sets the replication factor

type CommonProperty added in v0.3.1

type CommonProperty struct {
	Name  string
	Value interface{}
}

CommonProperty is a common property

type Component added in v0.3.1

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

Component is a component

func NewComponent added in v0.3.1

func NewComponent(ct ComponentType) *Component

NewComponent returns a new Component

func (*Component) BuildComponent added in v0.3.1

func (c *Component) BuildComponent() M

BuildComponent builds the component config

func (*Component) Class added in v0.3.1

func (c *Component) Class(class string) *Component

Class sets the component class

func (*Component) Config added in v0.3.1

func (c *Component) Config(m M) *Component

Config sets the component config

func (*Component) Name added in v0.3.1

func (c *Component) Name(name string) *Component

Name sets the component name

type ComponentType added in v0.3.1

type ComponentType int

ComponentType is a component type

const (
	RequestHandler ComponentType = iota
	SearchComponent
	InitParams
	QueryResponseWriter
)

List of component types

func (ComponentType) String added in v0.3.1

func (ct ComponentType) String() string

type CopyField added in v0.3.1

type CopyField struct {
	Source   string `json:"source,omitempty"`
	Dest     string `json:"dest,omitempty"`
	MaxChars int    `json:"maxchars,omitempty"`
}

CopyField is a copy field

type CoreParams added in v0.3.1

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

CoreParams is the core admin API param builder

func NewCoreParams added in v0.3.1

func NewCoreParams(core string) *CoreParams

NewCoreParams returns a new CoreParams

func (*CoreParams) BuildParams added in v0.3.1

func (c *CoreParams) BuildParams() string

BuildParams builds the parameters

func (*CoreParams) DeleteDataDir added in v0.3.1

func (c *CoreParams) DeleteDataDir(deleteDataDir bool) *CoreParams

DeleteDataDir set to true to remove the data directory and all sub-directories. The default is false.

func (*CoreParams) DeleteIndex added in v0.3.1

func (c *CoreParams) DeleteIndex(deleteIndex bool) *CoreParams

DeleteIndex set to true to remove the index when unloading the core. The default is false.

func (*CoreParams) DeleteInstanceDir added in v0.3.1

func (c *CoreParams) DeleteInstanceDir(deleteInstanceDir bool) *CoreParams

DeleteInstanceDir set to true to remove everything related to the core, including the index directory, configuration files and other related files. The default is false.

type CoreStatus added in v0.3.1

type CoreStatus struct {
	Config      string     `json:"config"`
	DataDir     string     `json:"dataDir"`
	Index       *Index     `json:"index"`
	InstanceDir string     `json:"instanceDir"`
	Name        string     `json:"name"`
	Schema      string     `json:"schema"`
	StartTime   *time.Time `json:"startTime"`
	Uptime      int        `json:"uptime"`
}

CoreStatus is the core status

type CoreStatusResponse added in v0.3.1

type CoreStatusResponse struct {
	*BaseResponse
	InitFailures M                      `json:"initFailures"`
	Status       map[string]*CoreStatus `json:"status"`
}

CoreStatusResponse is the core status response

type CreateCoreParams added in v0.3.1

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

CreateCoreParams is the create core param build

func NewCreateCoreParams added in v0.3.1

func NewCreateCoreParams(name string) *CreateCoreParams

NewCreateCoreParams takes a core name and returns a new CreateCoreParams

func (*CreateCoreParams) BuildParams added in v0.3.1

func (c *CreateCoreParams) BuildParams() string

BuildParams builds the parameters

func (*CreateCoreParams) Config added in v0.3.1

func (c *CreateCoreParams) Config(config string) *CreateCoreParams

Config is the name of the config file (i.e., solrconfig.xml) relative to instanceDir.

func (*CreateCoreParams) ConfigSet added in v0.3.1

func (c *CreateCoreParams) ConfigSet(configSet string) *CreateCoreParams

ConfigSet is the name of the configset to use for this core.

func (*CreateCoreParams) DataDir added in v0.3.1

func (c *CreateCoreParams) DataDir(dataDir string) *CreateCoreParams

DataDir is the name of the data directory relative to instanceDir.

func (*CreateCoreParams) InstanceDir added in v0.3.1

func (c *CreateCoreParams) InstanceDir(instanceDir string) *CreateCoreParams

InstanceDir is the directory where files for this core should be stored.

func (*CreateCoreParams) Schema added in v0.3.1

func (c *CreateCoreParams) Schema(schema string) *CreateCoreParams

Schema is name of the schema file to use for the core.

type DefaultRequestSender added in v0.3.1

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

DefaultRequestSender is the default HTTP request sender

func NewDefaultRequestSender added in v0.3.1

func NewDefaultRequestSender() *DefaultRequestSender

NewDefaultRequestSender returns a new DefaultRequestSender

func (*DefaultRequestSender) SendRequest added in v0.3.1

func (rs *DefaultRequestSender) SendRequest(ctx context.Context, httpMethod,
	urlStr, contentType string, body io.Reader) (*http.Response, error)

SendRequest builds and sends the HTTP request

func (*DefaultRequestSender) WithBasicAuth added in v0.3.1

func (rs *DefaultRequestSender) WithBasicAuth(username, password string) *DefaultRequestSender

WithBasicAuth sets the basic auth credentials

func (*DefaultRequestSender) WithHTTPClient added in v0.3.1

func (rs *DefaultRequestSender) WithHTTPClient(httpClient *http.Client) *DefaultRequestSender

WithHTTPClient overrides the default HTTP client

type DisMaxQueryParser added in v0.3.1

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

DisMaxQueryParser is a dismax query parser

func NewDisMaxQueryParser added in v0.3.1

func NewDisMaxQueryParser() *DisMaxQueryParser

NewDisMaxQueryParser returns a new DisMaxQueryParser

func (*DisMaxQueryParser) Alt added in v0.3.1

Alt sets the q.alt param

func (*DisMaxQueryParser) Bf added in v0.3.1

Bf sets the boost function param

func (*DisMaxQueryParser) Bq added in v0.3.1

Bq sets the boost query param

func (*DisMaxQueryParser) BuildParser added in v0.3.1

func (qp *DisMaxQueryParser) BuildParser() string

BuildParser builds the query parser

func (*DisMaxQueryParser) Mm added in v0.3.1

Mm sets the minimum should match param

func (*DisMaxQueryParser) Pf added in v0.3.1

Pf sets the phrase field param

func (*DisMaxQueryParser) Ps added in v0.3.1

Ps sets the phrase slop param

func (*DisMaxQueryParser) Qf added in v0.3.1

Qf sets the qf param

func (*DisMaxQueryParser) Qs added in v0.3.1

Qs sets the query slop param

func (*DisMaxQueryParser) Query added in v0.3.1

func (qp *DisMaxQueryParser) Query(query string) *DisMaxQueryParser

Query sets the query

func (*DisMaxQueryParser) Tie added in v0.3.1

Tie sets the tie breaker param param

type Faceter added in v0.3.1

type Faceter interface {
	// BuildFacet builds the facet
	BuildFacet() M
	// Name returns the name of the facet
	Name() string
}

Faceter is an abstraction of a facet e.g. terms, query, stats, range, heatmap etc.

type Field added in v0.3.1

type Field struct {
	Name                 string `json:"name"`
	Type                 string `json:"type,omitempty"`
	DocValues            bool   `json:"docValues,omitempty"`
	Indexed              bool   `json:"indexed,omitempty"`
	Stored               bool   `json:"stored,omitempty"`
	MultiValued          bool   `json:"multiValued,omitempty"`
	Required             bool   `json:"required,omitempty"`
	UseDocValuesAsStored bool   `json:"useDocValuesAsStored,omitempty"`
}

Field is a field

type FieldType added in v0.3.1

type FieldType struct {
	Name                      string    `json:"name"`
	Class                     string    `json:"class,omitempty"`
	PositionIncrementGap      string    `json:"positionIncrementGap,omitempty"`
	AutoGeneratePhraseQueries string    `json:"autoGeneratePhraseQueries,omitempty"`
	SynonymQueryStyle         string    `json:"synonymQueryStyle,omitempty"`
	EnableGraphQueries        string    `json:"enableGraphQueries,omitempty"`
	DocValuesFormat           string    `json:"docValuesFormat,omitempty"`
	PostingsFormat            string    `json:"postingsFormat,omitempty"`
	Indexed                   bool      `json:"indexed,omitempty"`
	Stored                    bool      `json:"stored,omitempty"`
	DocValues                 bool      `json:"docValues,omitempty"`
	SortMissingFirst          bool      `json:"sortMissingFirst,omitempty"`
	SortMissingLast           bool      `json:"sortMissingLast,omitempty"`
	MultiValued               bool      `json:"multiValued,omitempty"`
	Uninvertible              bool      `json:"uninvertible,omitempty"`
	OmitNorms                 bool      `json:"omitNorms,omitempty"`
	OmitTermFreqAndPositions  bool      `json:"omitTermFreqAndPositions,omitempty"`
	OmitPositions             bool      `json:"omitPositions,omitempty"`
	TermVectors               bool      `json:"termVectors,omitempty"`
	TermPositions             bool      `json:"termPositions,omitempty"`
	TermOffsets               bool      `json:"termOffsets,omitempty"`
	TermPayloads              bool      `json:"termPayloads,omitempty"`
	Required                  bool      `json:"required,omitempty"`
	UseDocValuesAsStored      bool      `json:"useDocValuesAsStored,omitempty"`
	Large                     bool      `json:"large,omitempty"`
	MaxCharsForDocValues      string    `json:"maxCharsForDocValues,omitempty"`
	Geo                       string    `json:"geo,omitempty"`
	MaxDistErr                string    `json:"maxDistErr,omitempty"`
	DistErrPct                string    `json:"distErrPct,omitempty"`
	DistanceUnits             string    `json:"distanceUnits,omitempty"`
	SubFieldSuffix            string    `json:"subFieldSuffix,omitempty"`
	Dimension                 string    `json:"dimension,omitempty"`
	Analyzer                  *Analyzer `json:"analyzer,omitempty"`
	IndexAnalyzer             *Analyzer `json:"indexAnalyzer,omitempty"`
	QueryAnalyzer             *Analyzer `json:"queryAnalyzer,omitempty"`
}

FieldType is a field type

type Filter added in v0.3.1

type Filter struct {
	Class               string `json:"class"`
	Encoder             string `json:"encoder,omitempty"`
	Inject              string `json:"inject,omitempty"`
	Words               string `json:"words,omitempty"`
	IgnoreCase          string `json:"ignoreCase,omitempty"`
	Articles            string `json:"articles,omitempty"`
	Language            string `json:"language,omitempty"`
	Format              string `json:"format,omitempty"`
	Protected           string `json:"protected,omitempty"`
	Expand              string `json:"expand,omitempty"`
	Synonyms            string `json:"synonyms,omitempty"`
	CatenateNumbers     string `json:"catenateNumbers,omitempty"`
	GenerateNumberParts string `json:"generateNumberParts,omitempty"`
	SplitOnCaseChange   string `json:"splitOnCaseChange,omitempty"`
	GenerateWordParts   string `json:"generateWordParts,omitempty"`
	CatenateAll         string `json:"catenateAll,omitempty"`
	CatenateWords       string `json:"catenateWords,omitempty"`
	MaxPosQuestion      string `json:"maxPosQuestion,omitempty"`
	MaxFractionAsterisk string `json:"maxFractionAsterisk,omitempty"`
	MaxPosAsterisk      string `json:"maxPosAsterisk,omitempty"`
	WithOriginal        string `json:"withOriginal,omitempty"`
	StemDerivational    string `json:"stemDerivational,omitempty"`
	MinimumLength       string `json:"minimumLength,omitempty"`
	Dictionary          string `json:"dictionary,omitempty"`
	Tags                string `json:"tags,omitempty"`
	Replacement         string `json:"replacement,omitempty"`
	Pattern             string `json:"pattern,omitempty"`
	PreserveOriginal    string `json:"preserveOriginal,omitempty"`
	Replace             string `json:"replace,omitempty"`
	MinGramSize         int    `json:"minGramSize,omitempty"`
	MaxGramSize         int    `json:"maxGramSize,omitempty"`
}

Filter is a filter

type FiltersQueryParser added in v0.3.1

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

FiltersQueryParser is a filters query parser

func NewFiltersQueryParser added in v0.3.1

func NewFiltersQueryParser() *FiltersQueryParser

NewFiltersQueryParser returns a new FiltersQueryParser

func (*FiltersQueryParser) BuildParser added in v0.3.1

func (qp *FiltersQueryParser) BuildParser() string

BuildParser builds the query parser

func (*FiltersQueryParser) ExcludeTags added in v0.3.1

func (qp *FiltersQueryParser) ExcludeTags(tags string) *FiltersQueryParser

ExcludeTags sets the excludeTags param

func (*FiltersQueryParser) Param added in v0.3.1

func (qp *FiltersQueryParser) Param(param string) *FiltersQueryParser

Param sets the 'param' param

func (*FiltersQueryParser) Query added in v0.3.1

func (qp *FiltersQueryParser) Query(query string) *FiltersQueryParser

Query sets the query

type Index added in v0.3.1

type Index struct {
	Current                 bool   `json:"current"`
	DeletedDocs             int    `json:"deletedDocs"`
	Directory               string `json:"directory"`
	HasDeletions            bool   `json:"hasDeletions"`
	IndexHeapUsageBytes     int    `json:"indexHeapUsageBytes"`
	MaxDoc                  int    `json:"maxDoc"`
	NumDocs                 int    `json:"numDocs"`
	SegmentCount            int    `json:"segmentCount"`
	SegmentFile             string `json:"segmentFile"`
	SegmentsFileSizeInBytes int    `json:"segmentsFileSizeInBytes"`
	Size                    string `json:"size"`
	UserData                M      `json:"userData"`
	Version                 int
}

Index is the index details from core status

type JSONClient added in v0.3.1

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

JSONClient is a client for interacting with Solr via JSON API

func NewJSONClient added in v0.3.1

func NewJSONClient(baseURL string) *JSONClient

NewJSONClient returns a new JSONClient

func (*JSONClient) AddComponents added in v0.3.1

func (c *JSONClient) AddComponents(ctx context.Context, collection string, components ...*Component) error

AddComponents adds a component (request handler, search component, init params, etc.) to configoverlay.json.

Refer to https://solr.apache.org/guide/8_8/config-api.html#commands-for-handlers-and-components

func (*JSONClient) AddCopyFields added in v0.3.1

func (c *JSONClient) AddCopyFields(ctx context.Context, collection string, copyFields ...CopyField) error

AddCopyFields adds new copy field rules to the schema.

Refer to https://solr.apache.org/guide/8_8/schema-api.html#add-a-new-copy-field-rule

func (*JSONClient) AddDynamicFields added in v0.3.1

func (c *JSONClient) AddDynamicFields(ctx context.Context, collection string, fields ...Field) error

AddDynamicFields adds new dynamic field rules to the schema.

Refer to https://solr.apache.org/guide/8_8/schema-api.html#add-a-dynamic-field-rule

func (*JSONClient) AddFieldTypes added in v0.3.1

func (c *JSONClient) AddFieldTypes(ctx context.Context, collection string, fieldTypes ...FieldType) error

AddFieldTypes adds new field types to the schema.

Refer to https://solr.apache.org/guide/8_8/schema-api.html#add-a-new-field-type

func (*JSONClient) AddFields added in v0.3.1

func (c *JSONClient) AddFields(ctx context.Context, collection string, fields ...Field) error

AddFields adds new field definitions to the schema.

Refer to https://solr.apache.org/guide/8_8/schema-api.html#add-a-new-field

func (*JSONClient) Commit added in v0.3.1

func (c *JSONClient) Commit(ctx context.Context, collection string) error

Commit commits the last update.

func (*JSONClient) CoreStatus added in v0.3.1

func (c *JSONClient) CoreStatus(ctx context.Context, params *CoreParams) (*CoreStatusResponse, error)

CoreStatus returns the status of all running Solr cores, or status for only the named core.

Refer to https://solr.apache.org/guide/8_8/coreadmin-api.html#coreadmin-status

func (*JSONClient) CreateCollection added in v0.3.1

func (c *JSONClient) CreateCollection(ctx context.Context, params *CollectionParams) error

CreateCollection creates a new collection.

Refer to https://solr.apache.org/guide/8_8/collection-management.html#create

func (*JSONClient) CreateCore added in v0.3.1

func (c *JSONClient) CreateCore(ctx context.Context, params *CreateCoreParams) error

CreateCore creates a new core

Refer to https://solr.apache.org/guide/8_8/coreadmin-api.html#coreadmin-create

func (*JSONClient) DeleteCollection added in v0.3.1

func (c *JSONClient) DeleteCollection(ctx context.Context, params *CollectionParams) error

DeleteCollection deletes a collection.

Refer to https://solr.apache.org/guide/8_8/collection-management.html#delete

func (*JSONClient) DeleteComponents added in v0.3.1

func (c *JSONClient) DeleteComponents(ctx context.Context, collection string, components ...*Component) error

DeleteComponents removes settings from configoverlay.json

Refer to https://solr.apache.org/guide/8_8/config-api.html#commands-for-handlers-and-components

func (*JSONClient) DeleteCopyFields added in v0.3.1

func (c *JSONClient) DeleteCopyFields(ctx context.Context, collection string, copyFields ...CopyField) error

DeleteCopyFields deletes copy field rules from the schema.

Refer to https://solr.apache.org/guide/8_8/schema-api.html#delete-a-copy-field-rule

func (*JSONClient) DeleteDynamicFields added in v0.3.1

func (c *JSONClient) DeleteDynamicFields(ctx context.Context, collection string, fields ...Field) error

DeleteDynamicFields removes dynamic field rules from the schema.

Refer to https://solr.apache.org/guide/8_8/schema-api.html#delete-a-dynamic-field-rule

func (*JSONClient) DeleteFieldTypes added in v0.3.1

func (c *JSONClient) DeleteFieldTypes(ctx context.Context, collection string, fieldTypes ...FieldType) error

DeleteFieldTypes removes field type definitions from the schema.

Refer to https://solr.apache.org/guide/8_8/schema-api.html#delete-a-field-type

func (*JSONClient) DeleteFields added in v0.3.1

func (c *JSONClient) DeleteFields(ctx context.Context, collection string, fields ...Field) error

DeleteFields removes field definitions from the schema.

Refer to https://solr.apache.org/guide/8_8/schema-api.html#delete-a-field

func (*JSONClient) Query added in v0.3.1

func (c *JSONClient) Query(ctx context.Context, collection string, query *Query) (*QueryResponse, error)

Query sends a query request to query API.

Refer to https://solr.apache.org/guide/8_8/json-request-api.html

func (*JSONClient) ReplaceDynamicFields added in v0.3.1

func (c *JSONClient) ReplaceDynamicFields(ctx context.Context, collection string, fields ...Field) error

ReplaceDynamicFields replaces dynamic field rules from the schema.

Refer to https://solr.apache.org/guide/8_8/schema-api.html#replace-a-dynamic-field-rule

func (*JSONClient) ReplaceFieldTypes added in v0.3.1

func (c *JSONClient) ReplaceFieldTypes(ctx context.Context, collection string, fieldTypes ...FieldType) error

ReplaceFieldTypes replaces field type defintions from the schema.

Refer to https://solr.apache.org/guide/8_8/schema-api.html#replace-a-field-type

func (*JSONClient) ReplaceFields added in v0.3.1

func (c *JSONClient) ReplaceFields(ctx context.Context, collection string, fields ...Field) error

ReplaceFields replaces field definition from the schema.

Refer to https://solr.apache.org/guide/8_8/schema-api.html#replace-a-field

func (*JSONClient) SetProperties added in v0.3.1

func (c *JSONClient) SetProperties(ctx context.Context, collection string, properties ...CommonProperty) error

SetProperties sets well known properties.

Refer to https://solr.apache.org/guide/8_8/config-api.html#commands-for-common-properties

func (*JSONClient) Suggest added in v0.3.1

func (c *JSONClient) Suggest(ctx context.Context, collection string, params *SuggestParams) (*SuggestResponse, error)

Suggest queries the suggest endpoint.

Refer to https://solr.apache.org/guide/8_8/suggester.html#get-suggestions-with-weights

func (*JSONClient) UnloadCore added in v0.3.1

func (c *JSONClient) UnloadCore(ctx context.Context, params *CoreParams) error

UnloadCore removes a core from Solr

Refer to https://solr.apache.org/guide/8_8/coreadmin-api.html#coreadmin-unload

func (*JSONClient) UnsetProperty added in v0.3.1

func (c *JSONClient) UnsetProperty(ctx context.Context, collection string, property CommonProperty) error

UnsetProperty removes a property set via set-properties.

Refer to https://solr.apache.org/guide/8_8/config-api.html#commands-for-common-properties

func (*JSONClient) Update added in v0.3.1

func (c *JSONClient) Update(ctx context.Context, collection string, mimeType MimeType, body io.Reader) (*UpdateResponse, error)

Update can be used to add, update, or delete a document from the index.

Refer to https://solr.apache.org/guide/8_8/uploading-data-with-index-handlers.html

func (*JSONClient) UpdateComponents added in v0.3.1

func (c *JSONClient) UpdateComponents(ctx context.Context, collection string, components ...*Component) error

UpdateComponents overwrites existing settings from configoverlay.json.

Refer to https://solr.apache.org/guide/8_8/config-api.html#commands-for-handlers-and-components

func (*JSONClient) WithRequestSender added in v0.3.1

func (c *JSONClient) WithRequestSender(reqSender RequestSender) *JSONClient

WithRequestSender overrides the default request sender

type M added in v0.3.1

type M map[string]interface{}

M is an alias for map of interface

type MimeType added in v0.3.1

type MimeType int

MimeType is a mime-type

const (
	JSON MimeType = iota
	XML
	CSV
)

List of mime-types

func (MimeType) String added in v0.3.1

func (mt MimeType) String() string

String implements Stringer

type ParentQueryParser added in v0.3.1

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

ParentQueryParser is a block-join parent query parser

func NewParentQueryParser added in v0.3.1

func NewParentQueryParser() *ParentQueryParser

NewParentQueryParser returns a new ParentQueryParser

func (*ParentQueryParser) BuildParser added in v0.3.1

func (qp *ParentQueryParser) BuildParser() string

BuildParser builds the query parser

func (*ParentQueryParser) ExcludeTags added in v0.3.1

func (qp *ParentQueryParser) ExcludeTags(tags string) *ParentQueryParser

ExcludeTags sets the excludeTags param

func (*ParentQueryParser) Filters added in v0.3.1

func (qp *ParentQueryParser) Filters(filters string) *ParentQueryParser

Filters sets the filters param

func (*ParentQueryParser) Query added in v0.3.1

func (qp *ParentQueryParser) Query(query string) *ParentQueryParser

Query sets the query

func (*ParentQueryParser) Score added in v0.3.1

func (qp *ParentQueryParser) Score(score string) *ParentQueryParser

Score sets the score param

func (*ParentQueryParser) Tag added in v0.3.1

Tag sets the tag param

func (*ParentQueryParser) Which added in v0.3.1

func (qp *ParentQueryParser) Which(which string) *ParentQueryParser

Which sets the which param

type Query added in v0.3.1

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

Query is a query

func NewQuery added in v0.3.1

func NewQuery(query string) *Query

NewQuery accepts the main query built from the various query parsers and returns the Query object.

func (*Query) BuildQuery added in v0.3.1

func (q *Query) BuildQuery() M

BuildQuery builds the query

func (*Query) Facets added in v0.3.1

func (q *Query) Facets(facets ...Faceter) *Query

Facets sets the facet query

func (*Query) Fields added in v0.3.1

func (q *Query) Fields(fields ...string) *Query

Fields sets the fields param

func (*Query) Filters added in v0.3.1

func (q *Query) Filters(filters ...string) *Query

Filters sets the filter param

func (*Query) Limit added in v0.3.1

func (q *Query) Limit(limit int) *Query

Limit sets the limit param

func (*Query) Offset added in v0.3.1

func (q *Query) Offset(offset int) *Query

Offset sets the offset param

func (*Query) Params added in v0.4.0

func (q *Query) Params(params M) *Query

Params sets the params param

func (*Query) Queries added in v0.3.1

func (q *Query) Queries(queries M) *Query

Queries sets the additional queries

func (*Query) Sort added in v0.3.1

func (q *Query) Sort(sort string) *Query

Sort sets the sort param

type QueryFacet added in v0.3.1

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

QueryFacet is query facet

func NewQueryFacet added in v0.3.1

func NewQueryFacet(name string) *QueryFacet

NewQueryFacet retunrs a new QueryFacet

func (*QueryFacet) AddFacet added in v0.3.1

func (f *QueryFacet) AddFacet(facet Faceter) *QueryFacet

AddFacet adds a nested facet

func (*QueryFacet) AddToFacet added in v0.3.1

func (f *QueryFacet) AddToFacet(key string, value interface{}) *QueryFacet

AddToFacet adds a key-value pair to the facet map

func (*QueryFacet) BuildFacet added in v0.3.1

func (f *QueryFacet) BuildFacet() M

BuildFacet builds the facet

func (*QueryFacet) Name added in v0.3.1

func (f *QueryFacet) Name() string

Name returns the facet name

func (*QueryFacet) Query added in v0.3.1

func (f *QueryFacet) Query(q string) *QueryFacet

Query sets the q param

type QueryParser added in v0.3.1

type QueryParser interface {
	// BuildParser builds the query from the specified parameters
	BuildParser() string
}

QueryParser is an abstraction of a query parser e.g. standard (lucene), dismax, edismax, boost, block join etc.

type QueryResponse added in v0.3.1

type QueryResponse struct {
	*BaseResponse
	Response QueryResponseBody `json:"response,omitempty"`
	Facets   M                 `json:"facets,omitempty"`
}

QueryResponse is a query response

type QueryResponseBody added in v0.3.1

type QueryResponseBody struct {
	NumFound  int     `json:"numFound,omitempty"`
	Start     int     `json:"start,omitempty"`
	MaxScore  float64 `json:"maxScore,omitempty"`
	Documents []M     `json:"docs,omitempty"`
}

QueryResponseBody is the query response body

type RequestSender added in v0.3.1

type RequestSender interface {
	SendRequest(ctx context.Context, method, urlStr,
		contentType string, body io.Reader) (*http.Response, error)
}

RequestSender is an HTTP request sender

type ResponseError added in v0.3.1

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

ResponseError is a response error

func (ResponseError) Error added in v0.3.1

func (e ResponseError) Error() string

type ResponseHeader added in v0.3.1

type ResponseHeader struct {
	ZKConnected bool `json:"zkConnected"`
	Status      int  `json:"status"`
	QTime       int  `json:"QTime"`
}

ResponseHeader is a response header

type Schema added in v0.3.1

type Schema struct {
	Name       string      `json:"name"`
	Version    float64     `json:"version"`
	UniqueKey  string      `json:"uniqueKey"`
	FieldTypes []FieldType `json:"fieldTypes,omitempty"`
	Fields     []Field     `json:"fields,omitempty"`
	CopyFields []CopyField `json:"copyFields"`
}

Schema is a schema

type StandardQueryParser added in v0.3.1

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

StandardQueryParser is a standard query parser (lucene)

func NewStandardQueryParser added in v0.3.1

func NewStandardQueryParser() *StandardQueryParser

NewStandardQueryParser returns a new StandardQueryParser

func (*StandardQueryParser) BuildParser added in v0.3.1

func (qp *StandardQueryParser) BuildParser() string

BuildParser builds the query parser

func (*StandardQueryParser) Df added in v0.3.1

Df sets the default field

func (*StandardQueryParser) Op added in v0.3.1

Op sets the default operator

func (*StandardQueryParser) Query added in v0.3.1

Query sets the query

func (*StandardQueryParser) Sow added in v0.3.1

Sow enables split-white-space

func (*StandardQueryParser) Tag added in v0.3.1

Tag sets the tag param

type SuggestBody added in v0.3.1

type SuggestBody map[string]SuggestTerm

SuggestBody is the suggest body

type SuggestParams added in v0.3.1

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

SuggestParams is the suggester API param builder

func NewSuggesterParams added in v0.3.1

func NewSuggesterParams(endpoint string) *SuggestParams

NewSuggesterParams returns a new SuggesterParams

func (*SuggestParams) Build added in v0.3.1

func (sp *SuggestParams) Build() *SuggestParams

Build sets the build param to true

func (*SuggestParams) BuildAll added in v0.3.1

func (sp *SuggestParams) BuildAll() *SuggestParams

BuildAll sets the build-all param to true

func (*SuggestParams) BuildParams added in v0.3.1

func (sp *SuggestParams) BuildParams() string

BuildParams builds the suggester params

func (*SuggestParams) Cfq added in v0.3.1

func (sp *SuggestParams) Cfq(cfq string) *SuggestParams

Cfq sets the context filter query param

func (*SuggestParams) Count added in v0.3.1

func (sp *SuggestParams) Count(count int) *SuggestParams

Count sets the count param

func (*SuggestParams) Dictionaries added in v0.3.1

func (sp *SuggestParams) Dictionaries(dicts ...string) *SuggestParams

Dictionaries sets the dictionaries param

func (*SuggestParams) Query added in v0.3.1

func (sp *SuggestParams) Query(query string) *SuggestParams

Query sets the query param

func (*SuggestParams) Reload added in v0.3.1

func (sp *SuggestParams) Reload() *SuggestParams

Reload sets the reload param to true

func (*SuggestParams) ReloadAll added in v0.3.1

func (sp *SuggestParams) ReloadAll() *SuggestParams

ReloadAll sets the reload-all param to true

type SuggestResponse added in v0.3.1

type SuggestResponse struct {
	*BaseResponse
	Command string       `json:"command,omitempty"`
	Suggest *SuggestBody `json:"suggest,omitempty"`
}

SuggestResponse is the suggester response

type SuggestTerm added in v0.3.1

type SuggestTerm map[string]SuggestTermBody

SuggestTerm is suggest term

type SuggestTermBody added in v0.3.1

type SuggestTermBody struct {
	NumFound    int          `json:"numFound,omitempty"`
	Suggestions []Suggestion `json:"suggestions,omitempty"`
}

SuggestTermBody is the suggest term body

type Suggestion added in v0.3.1

type Suggestion struct {
	Term    string `json:"term"`
	Weight  int    `json:"weight"`
	Payload string `json:"payload,omitempty"`
}

Suggestion is a term suggestion

type TermsFacet added in v0.3.1

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

TermsFacet is a terms facet

func NewTermsFacet added in v0.3.1

func NewTermsFacet(name string) *TermsFacet

NewTermsFacet returns a new TermsFacet

func (*TermsFacet) AddFacets added in v0.3.1

func (f *TermsFacet) AddFacets(facets ...Faceter) *TermsFacet

AddFacets adds nested facets

func (*TermsFacet) AddToDomain added in v0.3.1

func (f *TermsFacet) AddToDomain(key string, value interface{}) *TermsFacet

AddToDomain adds a key-value pair to the domain map

func (*TermsFacet) AddToFacet added in v0.3.1

func (f *TermsFacet) AddToFacet(key string, value interface{}) *TermsFacet

AddToFacet adds a key-value pair to the facet map

func (*TermsFacet) BuildFacet added in v0.3.1

func (f *TermsFacet) BuildFacet() M

BuildFacet builds the facet

func (*TermsFacet) Field added in v0.3.1

func (f *TermsFacet) Field(field string) *TermsFacet

Field sets the field param

func (*TermsFacet) Limit added in v0.3.1

func (f *TermsFacet) Limit(limit int) *TermsFacet

Limit sets the limit param

func (*TermsFacet) MinCount added in v0.3.1

func (f *TermsFacet) MinCount(minCount int) *TermsFacet

MinCount sets the mincount param

func (*TermsFacet) Name added in v0.3.1

func (f *TermsFacet) Name() string

Name returns the name of the facet

func (*TermsFacet) Offset added in v0.3.1

func (f *TermsFacet) Offset(offset int) *TermsFacet

Offset sets the offset param

func (*TermsFacet) Sort added in v0.3.1

func (f *TermsFacet) Sort(sort string) *TermsFacet

Sort sets the sort param

type Tokenizer added in v0.3.1

type Tokenizer struct {
	Class                 string `json:"class"`
	Delimeter             string `json:"delimiter,omitempty"`
	OutputUnknownUnigrams string `json:"outputUnknownUnigrams,omitempty"`
	DecompoundMode        string `json:"decompoundMode,omitempty"`
	Mode                  string `json:"mode,omitempty"`
}

Tokenizer is a tokenizer

type UpdateResponse added in v0.3.1

type UpdateResponse struct {
	*BaseResponse
}

UpdateResponse is an update response

Jump to

Keyboard shortcuts

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