querytranslate

package
v0.0.0-...-154c46d Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EXCEPTION_KEYS_IN_QUERY = []string{"size", "from", "aggs", "_source", "sort", "query"}

EXCEPTION_KEYS_IN_QUERY represents the keys which will not get copied while combining the queries using `react` prop

View Source
var RESERVED_KEYS_IN_RESPONSE = []string{"settings", "error"}

Functions

func FromLoggerContext

func FromLoggerContext(ctx context.Context) (*time.Time, error)

FromContext retrieves the rs api request stored against the querytranslate.loggerCtxKey from the context.

func NewContext

func NewContext(ctx context.Context, rsQuery RSQuery) context.Context

NewContext returns a new context with the given request body.

func NewLoggerContext

func NewLoggerContext(ctx context.Context) context.Context

NewContext returns a new context with the given request time.

Types

type DataField

type DataField struct {
	Field  string  `json:"field"`
	Weight float64 `json:"weight,omitempty"`
}

func NormalizedDataFields

func NormalizedDataFields(dataField interface{}, fieldWeights []float64) []DataField

The `dataField` property can be of following types - string - `DataField` struct with `field` and `weight` keys - Array of strings - Array of `DataField` struct - Array of strings and `DataField` struct

The following method normalizes the dataField input into a array of strings It also supports the fieldWeights in old format

func ParseDataFieldToString

func ParseDataFieldToString(dataFieldAsMap map[string]interface{}) *DataField

To construct the data field string with field weight from `DataField` struct

type FunctionObject

type FunctionObject struct {
	// works with Saturation
	Pivot *float64 `json:"pivot,omitempty"`
	// Pivot and Exponent work with Sigmoid
	Exponent *float64 `json:"exponent,omitempty"`
	// works with Logarithm
	ScalingFactor *float64 `json:"scaling_factor,omitempty"`
}

type GeoBoundingBox

type GeoBoundingBox struct {
	TopLeft     string
	BottomRight string
}

type GeoValue

type GeoValue struct {
	Distance    *int
	Unit        *string
	Location    *string
	BoundingBox *GeoBoundingBox
}

type Query

type Query struct {
	ID                  *string                  `json:"id,omitempty"` // component id
	Type                QueryType                `json:"type,omitempty"`
	React               *map[string]interface{}  `json:"react,omitempty"`
	QueryFormat         *QueryFormat             `json:"queryFormat,omitempty"`
	DataField           interface{}              `json:"dataField,omitempty"`
	CategoryField       *string                  `json:"categoryField,omitempty"`
	CategoryValue       *interface{}             `json:"categoryValue,omitempty"`
	FieldWeights        []float64                `json:"fieldWeights,omitempty"`
	NestedField         *string                  `json:"nestedField,omitempty"`
	From                *int                     `json:"from,omitempty"`
	Size                *int                     `json:"size,omitempty"`
	AggregationSize     *int                     `json:"aggregationSize,omitempty"`
	SortBy              *SortBy                  `json:"sortBy,omitempty"`
	Value               *interface{}             `json:"value,omitempty"` // either string or Array of string
	AggregationField    *string                  `json:"aggregationField,omitempty"`
	After               *map[string]interface{}  `json:"after,omitempty"`
	IncludeNullValues   *bool                    `json:"includeNullValues,omitempty"`
	IncludeFields       *[]string                `json:"includeFields,omitempty"`
	ExcludeFields       *[]string                `json:"excludeFields,omitempty"`
	Fuzziness           interface{}              `json:"fuzziness,omitempty"` // string or int
	SearchOperators     *bool                    `json:"searchOperators,omitempty"`
	Highlight           *bool                    `json:"highlight,omitempty"`
	HighlightField      []string                 `json:"highlightField,omitempty"`
	CustomHighlight     *map[string]interface{}  `json:"customHighlight,omitempty"`
	Interval            *int                     `json:"interval,omitempty"`
	Aggregations        *[]string                `json:"aggregations,omitempty"`
	MissingLabel        string                   `json:"missingLabel,omitempty"`
	ShowMissing         bool                     `json:"showMissing,omitempty"`
	DefaultQuery        *map[string]interface{}  `json:"defaultQuery,omitempty"`
	CustomQuery         *map[string]interface{}  `json:"customQuery,omitempty"`
	Execute             *bool                    `json:"execute,omitempty"`
	EnableSynonyms      *bool                    `json:"enableSynonyms,omitempty"`
	SelectAllLabel      *string                  `json:"selectAllLabel,omitempty"`
	Pagination          *bool                    `json:"pagination,omitempty"`
	QueryString         *bool                    `json:"queryString,omitempty"`
	RankFeature         *map[string]RankFunction `json:"rankFeature,omitempty"`
	DistinctField       *string                  `json:"distinctField,omitempty"`
	DistinctFieldConfig *map[string]interface{}  `json:"distinctFieldConfig,omitempty"`
	Index               *string                  `json:"index,omitempty"`
}

Query represents the query object

type QueryEnvs

type QueryEnvs struct {
	Query       *string
	TermFilters []TermFilter
}

QueryEnvs represents the extracted values from RSQuery

func ExtractEnvsFromRequest

func ExtractEnvsFromRequest(req RSQuery) QueryEnvs

ExtractEnvsFromRequest returns the extracted values from RS request

type QueryFormat

type QueryFormat int
const (
	Or QueryFormat = iota
	And
)

func (QueryFormat) MarshalJSON

func (o QueryFormat) MarshalJSON() ([]byte, error)

MarshalJSON is the implementation of the Marshaler interface for marshaling QueryFormat type.

func (QueryFormat) String

func (o QueryFormat) String() string

String is the implementation of Stringer interface that returns the string representation of QueryFormat type.

func (*QueryFormat) UnmarshalJSON

func (o *QueryFormat) UnmarshalJSON(bytes []byte) error

UnmarshalJSON is the implementation of the Unmarshaler interface for unmarshaling QueryFormat type.

type QueryTranslate

type QueryTranslate struct{}

QueryTranslate plugin deals with managing query translation.

func Instance

func Instance() *QueryTranslate

Instance returns the singleton instance of the plugin. Instance should be the only way (both within or outside the package) to fetch the instance of the plugin, in order to avoid stateless duplicates.

func (*QueryTranslate) ESMiddleware

func (r *QueryTranslate) ESMiddleware() []middleware.Middleware

func (*QueryTranslate) InitFunc

func (r *QueryTranslate) InitFunc(mw []middleware.Middleware) error

InitFunc initializes the dao, i.e. elasticsearch client, and should be executed only once in the lifetime of the plugin.

func (*QueryTranslate) Name

func (r *QueryTranslate) Name() string

Name returns the name of the plugin: querytranslate

func (*QueryTranslate) Routes

func (r *QueryTranslate) Routes() []plugins.Route

Routes returns an empty slices since the plugin solely acts as a middleware.

type QueryType

type QueryType int
const (
	Search QueryType = iota
	Term
	Range
	Geo
)

func (QueryType) MarshalJSON

func (o QueryType) MarshalJSON() ([]byte, error)

MarshalJSON is the implementation of the Marshaler interface for marshaling QueryType type.

func (QueryType) String

func (o QueryType) String() string

String is the implementation of Stringer interface that returns the string representation of QueryType type.

func (*QueryType) UnmarshalJSON

func (o *QueryType) UnmarshalJSON(bytes []byte) error

UnmarshalJSON is the implementation of the Unmarshaler interface for unmarshaling QueryType type.

type RSQuery

type RSQuery struct {
	Query    []Query   `json:"query,omitempty"`
	Settings *Settings `json:"settings,omitempty"`
}

RSQuery represents the request body

func FromContext

func FromContext(ctx context.Context) (*RSQuery, error)

FromContext retrieves the rs ap request stored against the querytranslate.ctxKey from the context.

type RangeValue

type RangeValue struct {
	Start *interface{}
	End   *interface{}
	Boost *float64
}

RangeValue represents the struct of range value

type RankFunction

type RankFunction struct {
	Saturation *FunctionObject `json:"saturation,omitempty"`
	Logarithm  *FunctionObject `json:"log,omitempty"`
	Sigmoid    *FunctionObject `json:"sigmoid,omitempty"`
	Boost      *float64        `json:"boost,omitempty"`
}

type Settings

type Settings struct {
	RecordAnalytics  *bool                   `json:"recordAnalytics,omitempty"`
	UserID           *string                 `json:"userId,omitempty"`
	CustomEvents     *map[string]interface{} `json:"customEvents,omitempty"`
	EnableQueryRules *bool                   `json:"enableQueryRules,omitempty"`
	UseCache         *bool                   `json:"useCache,omitempty"`
}

Settings represents the search settings

type SortBy

type SortBy int
const (
	Asc SortBy = iota
	Desc
	Count
)

func (SortBy) MarshalJSON

func (o SortBy) MarshalJSON() ([]byte, error)

MarshalJSON is the implementation of the Marshaler interface for marshaling SortBy type.

func (SortBy) String

func (o SortBy) String() string

String is the implementation of Stringer interface that returns the string representation of SortBy type.

func (*SortBy) UnmarshalJSON

func (o *SortBy) UnmarshalJSON(bytes []byte) error

UnmarshalJSON is the implementation of the Unmarshaler interface for unmarshaling SortBy type.

type TermFilter

type TermFilter struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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