Documentation ¶
Index ¶
- Constants
- func Router(service Service) func(chi.Router)
- type Aggregation
- type AggregationType
- type BoolFilter
- type Bucket
- type DateRangeBucket
- type DateRangeFilter
- type Filter
- type Hit
- type Indexable
- type NotFilter
- type NumericRangeFilter
- type Options
- type Result
- type Service
- type Term
- type TermsBucket
- type TermsFilter
Constants ¶
const ( TermsAggregation = "terms" ObjectsAggregation = "objects" DateRangeAggregation = "daterange" )
const DateLayout = "2006-01-02T15:04:05Z07:00"
DateLayout is the date layout used internally for date aggregations.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Aggregation ¶
type Aggregation struct { Type AggregationType `json:"type"` Field string `json:"field"` Filters []Filter `json:"filters"` }
func (Aggregation) CacheKey ¶
func (a Aggregation) CacheKey() string
CacheKey returns the same string for every identical aggregations. All aggregations resulting in the same bucket (given the same index) should return an equal cache key.
type AggregationType ¶
type AggregationType string
type BoolFilter ¶
func (*BoolFilter) CacheKey ¶
func (b *BoolFilter) CacheKey() string
type Bucket ¶
type Bucket interface {
BucketType() AggregationType
}
type DateRangeBucket ¶
func (DateRangeBucket) BucketType ¶
func (d DateRangeBucket) BucketType() AggregationType
type DateRangeFilter ¶
type DateRangeFilter struct { Field string `json:"field"` Min time.Time `json:"min"` Max time.Time `json:"max"` }
func (*DateRangeFilter) CacheKey ¶
func (d *DateRangeFilter) CacheKey() string
CacheKey returns the same string for all identical filters.
type Filter ¶
type Filter interface { CacheKey() string // contains filtered or unexported methods }
type Hit ¶
type Hit struct { // ID is the unique identifier of the stored entity. It might not match the // id of the entity in case it was indexed multiple times. ID string `json:"id"` // Type is the type of the document. Type string `json:"type"` // Raw contains the raw data of the document in the form of a json string. Raw string `json:"raw"` }
Hit is a single search hit.
type Indexable ¶
type Indexable interface { // Identifier returns an id which should uniquely identify the object for // its type. Identifier() string // Type returns the type of the object. Type() string // QueryText returns the string to index for a text search. QueryText() string // SearchFields returns a map of additional fields to be indexed. Those // fields can be used for filtering or aggregations. SearchFields() map[string]interface{} }
Indexable defines a document, that can be indexed. Any model, that implements this interface can be indexed and therefore is searchable. An indexable document can be uniquely identifyed by combining its identifier and type.
type NumericRangeFilter ¶
type NumericRangeFilter struct { Field string `json:"field"` Min *float64 `json:"min"` Max *float64 `json:"max"` }
func (*NumericRangeFilter) CacheKey ¶
func (n *NumericRangeFilter) CacheKey() string
CacheKey returns the same string for all identical filters.
type Options ¶
type Options struct { // Query is the search query used for a text search. Query string `json:"query"` // Sort is the field, that should be sorted by. // When left empty, the default sorting is used. Sort string `json:"sort"` // SortDescending defines the sort order. SortDescending bool `json:"sortAscending"` // Page is current page. Page int `json:"page"` // PageSize defines the number of hits returned per page. // // PageSize is infinite when set to 0. PageSize int `json:"pageSize"` // Filters is a list of filters, that reduce the search result. All filters // are combined with AND logic in addition with the search query. Filters []Filter `json:"filter"` // Aggregations is a map of aggregations, to perform aggregations on fields. // The provided map key can be used to identify the corresponding bucket in // the result. Aggregations map[string]Aggregation `json:"aggregations"` }
Options defines a set of optional search options.
type Result ¶
type Result struct { // Hits are the search hits for the current pagination. Hits []Hit `json:"hits"` // Total is the total number of search hits. // It is independet of the current pagination. Total uint64 `json:"total"` // Buckets is a set of aggregation buckets. // The map key corresponds to aggregation name. Buckets map[string]Bucket `json:"buckets"` }
Result contains a search result.
type Service ¶
type Service interface { // Index takes one or many indexable document and adds them to the search index. Index(docs ...Indexable) error // Delete deletes the document with the given type and id. // Note: both type and id have to be provided in order to uniquely identify // the document. Delete(docType, id string) error // Search performes a full text search on all indexed documents. // Performes a wildcard match for empty queries. // In addition to the search query a set of additional search options can be // provided. Search(ctx context.Context, opts *Options) (*Result, error) // LastModified returns the last time, the store was updated. This can be // used to invalidate a client side cache. LastModified() time.Time // Stops the search service. Stop() }
Service defines a search service.
-go:generate go run github.com/petergtz/pegomock/pegomock generate eintopf.info/service/search Service --output=../../internal/mock/search_service.go --package=mock --mock-name=SearchService
func NewService ¶
func NewService(indexPath string, searchTimeout time.Duration, resultCacheSize int, bucketCacheSize int, tz *time.Location) (Service, error)
NewService returns a new search service. Takes the path to the index directory. If the index already exits, the existing index is used. Otherwise a new one will be created.
type TermsBucket ¶
type TermsBucket []Term
func (TermsBucket) BucketType ¶
func (t TermsBucket) BucketType() AggregationType
type TermsFilter ¶
TermsFilter can be used to filter documents containing one of the provided terms in the field. If the field contains mutiple terms, only one must match.
func (*TermsFilter) CacheKey ¶
func (t *TermsFilter) CacheKey() string
CacheKey returns the same string for all identical filters.