Documentation ¶
Overview ¶
Example ¶
type Test struct { Name string `find:"Name" index:"leve_string"` Age int `find:"Age"` } // Create a new index index := New() // Create a new document doc := Test{ Name: "Test", Age: 10, } // Index the document id := "1" err := index.Index(id, doc) if err != nil { fmt.Println(err) return } // Get the document docGet, err := index.Get(id) if err != nil { fmt.Println(err) return } fmt.Printf("%+v", docGet)
Output: {Name:Test Age:10}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache struct { }
TODO: Implement a cache that based upon the search query, generate an id based upon the search query and store the results in a map[string]any
type Document ¶
func NewDoc ¶
Example ¶
type Test struct { Name string `find:"Name"` Age int `find:"Age"` } // Create a new document doc := Test{ Name: "Test", Age: 10, } // Create a new document document, err := NewDoc(doc) if err != nil { fmt.Println(err) return } fmt.Println(document.Values)
Output: map[Age:{int 10 []} Name:{string Test [test]}]
func (*Document) GetFieldValue ¶
Example ¶
type Test struct { Name string `find:"name"` Age int `find:"age"` } // Create a new document doc := Test{ Name: "Test", Age: 10, } // Create a new document document, _ := NewDoc(doc) value, _ := document.GetFieldValue("name") fmt.Println(value) value, _ = document.GetFieldValue("age") fmt.Println(value)
Output: test true 10 true
type Index ¶
type Index struct { Documents map[string]*Document Filters []FilterFunc // Cache Cache bool CacheSize int // contains filtered or unexported fields }
func NewOptions ¶
NewOptions returns a new index with the given options
func (*Index) Search ¶
func (i *Index) Search(searchQuery SearchQuery) ([]any, error)
Search returns a array of documents
Example ¶
type Test struct { Name string `find:"Name"` Age int `find:"Age"` } // Create a new index index := New() // Create a new document doc := Test{ Name: "Billy is my friend", Age: 10, } // Index the document id := "1" err := index.Index(id, doc) if err != nil { fmt.Println(err) return } // Create a search query search := SearchQuery{ Fields: []SearchQueryField{ { Field: "Name", Type: "partial", Value: "friend", }, }, } // Search for the document results, err := index.Search(search) if err != nil { fmt.Println(err) return } fmt.Printf("%+v", results)
Output: [{Name:Billy is my friend Age:10}]
type SearchQuery ¶
type SearchQuery struct { Limit uint `json:"limit"` Skip uint `json:"skip"` Sort string `json:"sort"` // asc or desc SortBy string `json:"sort_by"` // Field to sort by Fields []SearchQueryField `json:"fields"` }
func JsontoSearchQueries ¶
func JsontoSearchQueries(jsonBytes []byte) (*SearchQuery, error)
func StringToSearchQuery ¶
func StringToSearchQuery(input string) (*SearchQuery, error)
Take full raw query string and parse it into a SearchQuery struct Field types are a flat structure of the field and type of field
func (*SearchQuery) Sanatize ¶
func (sq *SearchQuery) Sanatize()
func (*SearchQuery) Validate ¶
func (sq *SearchQuery) Validate() error
type SearchQueryField ¶
func (*SearchQueryField) Sanatize ¶
func (dq *SearchQueryField) Sanatize()
func (*SearchQueryField) Validate ¶
func (dq *SearchQueryField) Validate() error
Source Files ¶
Click to show internal directories.
Click to hide internal directories.