domain

package
v3.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 7 Imported by: 20

Documentation

Index

Constants

View Source
const (
	// SortDirectionAscending general asc value
	SortDirectionAscending = "A"

	// SortDirectionDescending general desc value
	SortDirectionDescending = "D"

	// SortDirectionNone general not set value
	SortDirectionNone = ""
)
View Source
const (
	// SuggestionTypeProduct represents product suggestions
	SuggestionTypeProduct = "product"
	// SuggestionTypeCategory represents category suggestions
	SuggestionTypeCategory = "category"
)

Variables

View Source
var (
	// ErrNotFound error
	ErrNotFound = errors.New("search not found")
)

Functions

This section is empty.

Types

type Action added in v3.9.0

type Action struct {
	Type                 string
	Content              string
	AdditionalAttributes map[string]interface{}
}

Action might be considered on the frontend to be taken depending on search results

type Document

type Document interface{}

Document holds a search result document

type Facet

type Facet struct {
	Type     FacetType
	Name     string
	Label    string
	Items    []*FacetItem
	Position int
}

Facet provided by the search backend

type FacetCollection

type FacetCollection map[string]Facet

FacetCollection for all available facets

func (FacetCollection) Order

func (fc FacetCollection) Order() []string

Order a facet collection

type FacetItem

type FacetItem struct {
	Label    string
	Value    string
	Active   bool
	Selected bool

	// Tree Facet
	Items []*FacetItem

	// Range Facet
	Min, Max                 float64
	SelectedMin, SelectedMax float64

	Count int64
}

FacetItem contains information about a facet item

type FacetType

type FacetType string

FacetType for type facets

const (
	ListFacet  FacetType = "ListFacet"
	TreeFacet  FacetType = "TreeFacet"
	RangeFacet FacetType = "RangeFacet"
)

Facet types

type Filter

type Filter interface {
	// Value very generic method for filters - returning typical Parameter Name and its setted values
	Value() (string, []string)
}

Filter interface for search queries

func NewKeyValueFilters

func NewKeyValueFilters(params map[string][]string) []Filter

NewKeyValueFilters - Factory method that you can use to get a list of KeyValueFilter based from url.Values

type KeyValueFilter

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

KeyValueFilter allows simple k -> []values filtering

func NewKeyValueFilter

func NewKeyValueFilter(k string, v []string) *KeyValueFilter

NewKeyValueFilter factory

func (*KeyValueFilter) Key

func (f *KeyValueFilter) Key() string

Key of the current filter

func (*KeyValueFilter) KeyValues

func (f *KeyValueFilter) KeyValues() []string

KeyValues of the current filter

func (*KeyValueFilter) Value

func (f *KeyValueFilter) Value() (string, []string)

Value of the current filter

type Media added in v3.4.0

type Media struct {
	Type      string
	MimeType  string
	Usage     string
	Title     string
	Reference string
}

Media contains promotion media data

type PaginationPage

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

PaginationPage - if search supports pagination this filter tells which page to return

func NewPaginationPageFilter

func NewPaginationPageFilter(page int) *PaginationPage

NewPaginationPageFilter factory

func (*PaginationPage) GetPage

func (f *PaginationPage) GetPage() int

GetPage of the current filter

func (*PaginationPage) Value

func (f *PaginationPage) Value() (string, []string)

Value of the current filter

type PaginationPageSize

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

PaginationPageSize - if search supports setting the amount (limit) per page

func NewPaginationPageSizeFilter

func NewPaginationPageSizeFilter(page int) *PaginationPageSize

NewPaginationPageSizeFilter factory

func (*PaginationPageSize) GetPageSize

func (f *PaginationPageSize) GetPageSize() int

GetPageSize of the current filter

func (*PaginationPageSize) Value

func (f *PaginationPageSize) Value() (string, []string)

Value of the current filter

type Promotion added in v3.4.0

type Promotion struct {
	Title                string
	Content              string
	URL                  string
	Media                []Media
	AdditionalAttributes map[string]interface{}
}

Promotion result during search

type QueryFilter

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

QueryFilter - represents a query string, normally given by a user in the search result

func NewQueryFilter

func NewQueryFilter(query string) *QueryFilter

NewQueryFilter factory

func (*QueryFilter) Query

func (f *QueryFilter) Query() string

Query of the current filter

func (*QueryFilter) Value

func (f *QueryFilter) Value() (string, []string)

Value of the current filter

type RedirectError

type RedirectError struct {
	To string
}

RedirectError suggests to redirect

func (*RedirectError) Error

func (re *RedirectError) Error() string

type RequestQueryHook

type RequestQueryHook interface {
	Hook(ctx context.Context, path string, query *url.Values) error
}

RequestQueryHook can be used to enforce redirect errors

type Result

type Result struct {
	SearchMeta SearchMeta
	Hits       []Document
	Suggestion []Suggestion
	Facets     FacetCollection
	Promotions []Promotion
	Actions    []Action
}

Result defines a search result for one type

type SearchMeta

type SearchMeta struct {
	Query          string
	OriginalQuery  string
	Page           int
	NumPages       int
	NumResults     int
	SelectedFacets []Facet
	SortOptions    []SortOption
}

SearchMeta data

func (*SearchMeta) ValidatePageSize

func (sm *SearchMeta) ValidatePageSize(pageSize int) error

ValidatePageSize checks if the pageSize is logical for current result

type SearchService

type SearchService interface {
	// Types() []string
	Search(ctx context.Context, filter ...Filter) (results map[string]Result, err error)
	SearchFor(ctx context.Context, typ string, filter ...Filter) (result *Result, err error)
}

SearchService defines how to access search

type SortFilter

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

SortFilter - specifies the request to sort by some criteria(label) in a certain direction. Possible values for label and direction should be in SearchMeta.SortOption

func NewSortFilter

func NewSortFilter(label string, direction string) *SortFilter

NewSortFilter factory

func (*SortFilter) Descending added in v3.4.0

func (f *SortFilter) Descending() bool

Descending returns true if sort order is descending

func (*SortFilter) Direction

func (f *SortFilter) Direction() string

Direction of the current filter

func (*SortFilter) Field

func (f *SortFilter) Field() string

Field of the current filter

func (*SortFilter) Value

func (f *SortFilter) Value() (string, []string)

Value of the current filter

type SortOption

type SortOption struct {
	// Label that you normally want to show in the frontend (e.g. "Price")
	Label string
	// Field that you need to use in SearchRequest>SortFilter
	Field string
	// SelectedAsc true if sorting by this field is active
	SelectedAsc bool
	// SelectedDesc true if sorting by this field is active
	SelectedDesc bool
	// Asc - represents the field that is used to trigger ascending search.
	// Deprecated: use "Field" and "SelectedAsc" instead to set which field should be sortable
	Asc string
	// Desc - represents the field that is used to trigger descending search.
	// Deprecated: use "Field" and "SelectedDesc" instead to set which field should be sortable
	Desc string
}

SortOption defines how sorting is possible, and which of them are activated with both an asc and desc option

type Suggestion

type Suggestion struct {
	Type                 string
	Text                 string
	Highlight            string
	AdditionalAttributes map[string]string
}

Suggestion hint

Jump to

Keyboard shortcuts

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