search

package
v0.0.0-...-560f09a Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	Attribute string
	Operator  Operator
	Value     interface{}
	Values    []interface{}
}

Filter

	 Structures the filtering logic and API format in a programmatic
	 interface so that filtering can be performed by developers
	 unfamiliar with the meilisearch API.

			 Usage Notes:
              - Attribute: attribute of the documents to filter on
              - Operator:  comparison operator used to compare the Attribute and Value
              - Value:     value that will be compared to the Attribute via the Operator (not used for OperatorIn and OperatorNotIn)
              - Values:    values that will be compared to the Attribute when using the Operators OperatorIn and OperatorNotIn (ignored otherwise)

func (*Filter) String

func (f *Filter) String() string

String

Formats the Filter into a string filter
supported by the meilisearch search engine

type FilterCondition

type FilterCondition struct {
	Filters []Filter
	And     bool
	Not     bool
}

FilterCondition

 Groups multiple filters together with a logical AND/OR
 FilterConditions default to OR unless the attribute `And` is set true

 Usage Notes:
   - Filters are interpreted in sequential order of index as if written left (index 0) to right (index > 0)
   - And: converts the logical join of all filters in the condition from a logical OR to a logical AND
   - Not: inverts the logical meaning of the total filter condition

 Ex 1:
     field1 > 10
         FilterCondition{
				Filters: []Filter{
					{
						Value:     "10",
						Attribute: "field1",
						Operator:  OperatorGreaterThan,
					},
				},
			}

 Ex 2:
     NOT (field1 > 10 && field2 == 'testGreater')
         FilterCondition{
               Filters: []Filter{
                   {
                       Value:     "10",
                       Attribute: "field1",
                       Operator:  OperatorGreaterThan,
                   },
                   {
                       Value:     "testGreater",
                       Attribute: "field2",
                       Operator:  OperatorEquals,
                   },
               },
               And: true,
               Not: true,
         }

func (*FilterCondition) String

func (fc *FilterCondition) String() string

String

Formats the FilterCondition into a string filter
supported by the meilisearch search engine

type FilterGroup

type FilterGroup struct {
	Filters []FilterCondition
	And     bool
	Not     bool
}

FilterGroup

		Merges multiple filters together allowing for more complex filtering
		operations. The internal structure is a 2D slice of Filters that
		can be used to perform the logical merge of multiple filter sets

	 Usage Notes:
	   - Conditions are interpreted in sequential order of index as if written left (index 0) to right (index > 0)
	   - And: converts the logical join of all filters conditions in the group from a logical OR to a logical AND
	   - Not: inverts the logical meaning of the total filter group

	 Ex 1:
	     field1 > 10
	     	FilterGroup{
			        Filters: []FilterCondition{
				        {
					        Filters: []Filter{
						        {
							        Value:     "10",
							        Attribute: "field1",
							        Operator:  OperatorGreaterThan,
						        },
					        },
				        },
	             }
	         }

		Ex 2:
	     NOT ((field1 > 10 && field2 == 'testGreater') || NOT (field1 < 10 && field2 == 'testLess'))

	     	FilterGroup{
			        Filters: []FilterCondition{
				        {
					        Filters: []Filter{
						        {
							        Value:     "10",
							        Attribute: "field1",
							        Operator:  OperatorGreaterThan,
						        },
						        {
							        Value:     "testGreater",
							        Attribute: "field2",
							        Operator:  OperatorEquals,
						        },
					        },
					        And: true,
				        },
				        {
					        Filters: []Filter{
						        {
							        Value:     "10",
							        Attribute: "field1",
							        Operator:  OperatorLessThan,
						        },
						        {
							        Value:     "testLess",
							        Attribute: "field2",
							        Operator:  OperatorEquals,
						        },
					        },
					        And: true,
	                     Not: true,
				        },
			        },
			        And: false,
                 Not: true,
		        }

func (*FilterGroup) String

func (fg *FilterGroup) String() string

String

Formats the FilterGroup into a string filter
supported by the meilisearch search engine

type MeiliSearchEngine

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

MeiliSearchEngine

Struct for interacting with the Meilisearch Search Engine
for the GIGO codebase

func CreateMeiliSearchEngine

func CreateMeiliSearchEngine(config config.MeiliConfig) (*MeiliSearchEngine, error)

CreateMeiliSearchEngine

Create a new MeiliSearchEngine and initializes the configured indexes

func (*MeiliSearchEngine) AddDocuments

func (e *MeiliSearchEngine) AddDocuments(index string, documents ...interface{}) error

AddDocuments

 Adds a set of documents to the configured index

 Args:
	    - index (string): Index that documents will be added to
	    - documents (variable interface{}): Documents that will be inserted into the index - all structs passed to
                                         this function should have json serializer decorators

func (*MeiliSearchEngine) DeleteDocuments

func (e *MeiliSearchEngine) DeleteDocuments(index string, ids ...interface{}) error

DeleteDocuments

Deletes a set of documents from the configured index

Args:
      - index (string): Index that documents will be deleted from
      - ids (interface{}): Ids of documents that will be deleted from the index

func (*MeiliSearchEngine) Search

func (e *MeiliSearchEngine) Search(index string, req *Request) (*Result, error)

Search

	Searches the configured index in meilisearch using the configured
 parameters from Request

 Args:
     index (string): The name of the index to search
     req (*Request): Configuration for the search operation

 Returns:
     (*Result): Result of the search operation

func (*MeiliSearchEngine) UpdateDocuments

func (e *MeiliSearchEngine) UpdateDocuments(index string, documents ...interface{}) error

UpdateDocuments

Updates a set of documents in the configured index

Args:
      - index (string): Index that documents will be updated in
      - documents (variable interface{}): Documents that will be updated in the index - all structs passed to
                                          this function should have json serializer decorators

type Operator

type Operator string

Operator

Performs a comparison between two values
const (
	OperatorEquals              Operator = "="
	OperatorNotEquals           Operator = "!="
	OperatorGreaterThan         Operator = ">"
	OperatorLessThan            Operator = "<"
	OperatorGreaterThanOrEquals Operator = ">="
	OperatorLessThanOrEquals    Operator = "<="
	OperatorIn                  Operator = "IN"
	OperatorNotIn               Operator = "NOT IN"
	OperatorExists              Operator = "EXISTS"
	OperatorDoesNotExist        Operator = "NOT EXISTS"
)

type Request

type Request struct {
	Query  string
	Filter *FilterGroup
	Sort   *SortGroup
	Facets []string
	Offset int
	Limit  int
}

Request

	Struct used to format the string based filter, sort and facet
	functionality of meilisearch into a programmatic API that does
	not require understanding of the meilisearch API

 Usage Notes:
     - Query:   query that will be search
     - Filter:  filter that will be applied to the query results
     - Sort:    sort that will be applied to the query+filter results
     - Facet:   facets are the fields that you would like a distribution breakdown for the results for
                the search (see https://docs.meilisearch.com/learn/advanced/filtering_and_faceted_search.html#filtering-with-georadius)
     - Offset:  amount of documents to skip before returning any results
     - Limit:   max amount of results that can be returned after the offset

type Result

type Result struct {
	*meilisearch.SearchResponse
	ResultBuffer []byte
	CursorIndex  int
	HitsBuffer   []byte
	TotalResults int
}

Result

Struct used to wrap the meilisearch.SearchResponse
This struct includes convenience functions is Scan
and Next. This enables an interaction with the search
response that is more similar to a SQL database but
preserves all underlying data and functionality

func (*Result) Next

func (r *Result) Next() (bool, error)

Next

Mimics the sql.Rows.Next function which loads the next
result into the first position of cursor so that the
result can be scanned via the Scan function.

func (*Result) Scan

func (r *Result) Scan(dst interface{}) error

Scan

Mimics the sql.Rows.Scan function which scans the
current buffered result into the passed interface.
Unlike the sql.Rows.Next function, this function does
not scan into individual parameters but instead scans
into entire structs. If an arbitrary set of values need
to be scanned tou can use a map[string]interface{} or
define a struct locally for the scan operation.

Args:
    dst (interface{}): pointer to the struct that the result will be scanned into

type Sort

type Sort struct {
	Attribute string
	Desc      bool
}

Sort

Structures the sorting logic and API format in a programmatic
interface so that sorting can be performed by developers
unfamiliar with the meilisearch API.

func (*Sort) String

func (s *Sort) String() string

String

Formats the Sort into a string sort
supported by the meilisearch search engine

type SortGroup

type SortGroup struct {
	Sorts []Sort
}

SortGroup

			Merges multiple sorts together allowing for more complex sorting
			operations. Sort ordering is prioritized in order of their position
         in the Sorts slice. Lower indices correlate to a higher priority.

func (*SortGroup) Format

func (sg *SortGroup) Format() []string

Format

Formats the sort group into a slice of strings compatible
with the meilisearch search engine API

Jump to

Keyboard shortcuts

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