nocache

package
v0.7.17 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WFTGetValueFromMap

func WFTGetValueFromMap(value any) string

Get the full-text value from a map

Types

type FullText

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

FullText is a struct that represents a full text search cache. It has the following fields: - mutex (*sync.RWMutex): a pointer to a read-write mutex used to synchronize access to the cache - storage (map[string]any): a map where the keys are words and the values are arrays of integers representing the indices of the data items that contain the word - words ([]string): a slice of strings representing all the unique words in the cache - data ([]map[string]any): a slice of maps representing the data items in the cache, where the keys are the names of the fields and the values are the field values

func InitWithJson

func InitWithJson(file string, minWordLength int) (*FullText, error)

Initialize the full-text cache with the provided json file. This function is thread safe.

func InitWithMapSlice

func InitWithMapSlice(data []map[string]any, minWordLength int) (*FullText, error)

Initialize the full-text cache with the provided data. This function is thread safe.

func (*FullText) Search

func (ft *FullText) Search(sp SearchParams) ([]map[string]any, error)

Search searches for all occurrences of the given query string in the FullText object's data. The search is done by splitting the query into separate words and looking for each of them in the data. The search result is limited to the specified number of entries. Parameters:

  • sp (SearchParams): A SearchParams struct containing the search parameters.

Returns:

  • []map[string]any: A slice of maps where each map represents a data record that matches the given query. The keys of the map correspond to the column names of the data that were searched and returned in the result.
  • error: An error if the query or limit is invalid.

func (*FullText) SearchOneWord

func (ft *FullText) SearchOneWord(sp SearchParams) ([]map[string]any, error)

SearchOneWord searches for a single query within the data using a full-text search approach. The search result is limited to the specified number of entries, and can optionally be filtered to only include exact matches. Parameters:

  • query (string): The search query to use. This string will be searched for as a single word in any value associated with any key in each entry of the data.
  • limit (int): The maximum number of search results to return. If the number of matching results exceeds this limit, the excess results will be ignored.
  • strict (bool): If true, only exact matches will be returned. If false, partial matches will also be returned.

Returns:

  • []map[string]any: An array of maps representing the search results. Each map contains key-value pairs from the entry in the data that matched the search query. If no results are found, an empty array is returned.
  • error: An error object. If no error occurs, this will be nil.

Note: The search is case-insensitive.

func (*FullText) SearchValues

func (ft *FullText) SearchValues(sp SearchParams) ([]map[string]any, error)

SearchValues searches for all occurrences of the given query string in the FullText object's data. The search is done by splitting the query into separate words and looking for each of them in the data. The search result is limited to the specified number of entries, and can optionally be filtered to only include keys that match a given schema. Parameters:

  • sp (SearchParams): A SearchParams struct containing the search parameters.

Returns:

  • []map[string]any: An array of maps representing the search results. Each map contains key-value pairs from the entry in the data that matched the search query. If no results are found, an empty array is returned.
  • error: An error object. If no error occurs, this will be nil.

Note: The search is case-insensitive.

func (*FullText) SearchWithKey

func (ft *FullText) SearchWithKey(query string, key string, limit int) ([]map[string]any, error)

SearchWithKey searches for all records containing the given query in the specified key column with a limit of results to return. The search result is limited to the specified number of entries. Parameters:

  • query (string): The search query to use. This string will be searched for as a substring in the data value associated with the given key.
  • key (string): The name of the key in the data whose data value should be searched.
  • limit (int): The maximum number of search results to return. If the number of matching results exceeds this limit, the excess results will be ignored.

Returns:

  • []map[string]any: A slice of maps where each map represents a data record that matches the given query. The keys of the map correspond to the column names of the data that were searched and returned in the result.
  • error: An error if the query, key or limit is invalid.

type SearchParams

type SearchParams struct {
	// The search query
	Query string
	// The limit of search results to return
	Limit int
	// A boolean to indicate whether the search should be strict or not
	Strict bool
	// A map containing the schema to search for
	Schema map[string]bool
	// Key to search in
	Key string
}

SearchParams is a struct that contains the search parameters for the Cache search methods.

Directories

Path Synopsis
examples
router
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

Jump to

Keyboard shortcuts

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