Documentation ¶
Index ¶
- Constants
- Variables
- func GetCondType(name string) (int, error)
- type DeepCopy
- type FtFastConfig
- type FtFuzzyConfig
- type IndexDescription
- type Iterator
- func (it *Iterator) AggResults() []float64
- func (it *Iterator) AllowUnsafe(allow bool) *Iterator
- func (it *Iterator) Close()
- func (it *Iterator) Count() int
- func (it *Iterator) Error() error
- func (it *Iterator) FetchAll() (items []interface{}, err error)
- func (it *Iterator) FetchAllWithRank() (items []interface{}, ranks []int, err error)
- func (it *Iterator) FetchOne() (item interface{}, err error)
- func (it *Iterator) GetAggreatedValue(idx int) float64
- func (it *Iterator) HasRank() bool
- func (it *Iterator) JoinedObjects(field string) (objects []interface{}, err error)
- func (it *Iterator) Next() (hasNext bool)
- func (it *Iterator) Object() interface{}
- func (it *Iterator) Rank() int
- func (it *Iterator) TotalCount() int
- type JSONIterator
- type JoinHandler
- type Joinable
- type Logger
- type NamespaceDescription
- type NamespaceOptions
- type Query
- func (q *Query) Aggregate(index string, aggType int) *Query
- func (q *Query) CachedTotal(totalNames ...string) *Query
- func (q *Query) Debug(level int) *Query
- func (q *Query) Delete() (int, error)
- func (q *Query) Distinct(distinctIndex string) *Query
- func (q *Query) Exec() *Iterator
- func (q *Query) ExecToJson(jsonRoots ...string) *JSONIterator
- func (q *Query) Get() (item interface{}, found bool)
- func (q *Query) GetJson() (json []byte, found bool)
- func (q *Query) InnerJoin(q2 *Query, field string) *Query
- func (q *Query) Join(q2 *Query, field string) *Query
- func (q *Query) JoinHandler(field string, handler JoinHandler) *Query
- func (q *Query) LeftJoin(q2 *Query, field string) *Query
- func (q *Query) Limit(limitItems int) *Query
- func (q *Query) Match(index string, keys ...string) *Query
- func (q *Query) Merge(q2 *Query) *Query
- func (q *Query) MustExec() *Iterator
- func (q *Query) Not() *Query
- func (q *Query) Offset(startOffset int) *Query
- func (q *Query) On(index string, condition int, joinIndex string) *Query
- func (q *Query) Or() *Query
- func (q *Query) ReqTotal(totalNames ...string) *Query
- func (q *Query) Select(fields ...string) *Query
- func (q *Query) SetContext(ctx interface{}) *Query
- func (q *Query) Sort(sortIndex string, desc bool, values ...interface{}) *Query
- func (q *Query) Where(index string, condition int, keys interface{}) *Query
- func (q *Query) WhereBool(index string, condition int, keys ...bool) *Query
- func (q *Query) WhereDouble(index string, condition int, keys ...float64) *Query
- func (q *Query) WhereInt(index string, condition int, keys ...int) *Query
- func (q *Query) WhereInt64(index string, condition int, keys ...int64) *Query
- func (q *Query) WhereString(index string, condition int, keys ...string) *Query
- type Reindexer
- func (db *Reindexer) BeginTx(namespace string) (*Tx, error)
- func (db *Reindexer) CloneNamespace(src string, dst string) error
- func (db *Reindexer) CloseNamespace(namespace string) error
- func (db *Reindexer) ConfigureIndex(namespace, index string, config interface{}) error
- func (db *Reindexer) Delete(namespace string, item interface{}, precepts ...string) error
- func (db *Reindexer) DeleteNamespace(namespace string) error
- func (db *Reindexer) DescribeNamespace(namespace string) (*NamespaceDescription, error)
- func (db *Reindexer) DescribeNamespaces() ([]*NamespaceDescription, error)
- func (db *Reindexer) DropNamespace(namespace string) error
- func (db *Reindexer) EnableStorage(storagePath string) error
- func (db *Reindexer) ExecSQL(query string) *Iterator
- func (db *Reindexer) ExecSQLToJSON(query string) *JSONIterator
- func (db *Reindexer) GetStats() bindings.Stats
- func (db *Reindexer) GetUpdatedAt(namespace string) (*time.Time, error)
- func (db *Reindexer) Insert(namespace string, item interface{}, precepts ...string) (int, error)
- func (db *Reindexer) MustBeginTx(namespace string) *Tx
- func (db *Reindexer) NewNamespace(namespace string, opts *NamespaceOptions, s interface{}) error
- func (db *Reindexer) OpenNamespace(namespace string, opts *NamespaceOptions, s interface{}) (err error)
- func (db *Reindexer) Ping() error
- func (db *Reindexer) Query(namespace string) *Query
- func (db *Reindexer) QueryFrom(d dsl.DSL) (*Query, error)
- func (db *Reindexer) RenameNamespace(src string, dst string) error
- func (db *Reindexer) ResetStats()
- func (db *Reindexer) SetDefaultQueryDebug(namespace string, level int)
- func (db *Reindexer) SetLogger(log Logger)
- func (db *Reindexer) Update(namespace string, item interface{}, precepts ...string) (int, error)
- func (db *Reindexer) Upsert(namespace string, item interface{}, precepts ...string) error
- type Tx
- func (tx *Tx) Commit(updatedAt *time.Time) error
- func (tx *Tx) Delete(s interface{}) error
- func (tx *Tx) DeleteJSON(json []byte) error
- func (tx *Tx) Insert(s interface{}) (int, error)
- func (tx *Tx) MustCommit(updatedAt *time.Time)
- func (tx *Tx) Rollback() error
- func (tx *Tx) Update(s interface{}) (int, error)
- func (tx *Tx) Upsert(s interface{}) error
- func (tx *Tx) UpsertJSON(json []byte) error
Constants ¶
const ( CollateNone = bindings.CollateNone CollateASCII = bindings.CollateASCII CollateUTF8 = bindings.CollateUTF8 CollateNumeric = bindings.CollateNumeric IndexOptPK = bindings.IndexOptPK IndexOptArray = bindings.IndexOptArray IndexOptDense = bindings.IndexOptDense IndexOptAppendable = bindings.IndexOptAppendable )
const ( // Equal '=' EQ = bindings.EQ // Greater '>' GT = bindings.GT // Lower '<' LT = bindings.LT // Greater or equal '>=' (GT|EQ) GE = bindings.GE // Lower or equal '<' LE = bindings.LE // One of set 'IN []' SET = bindings.SET // All of set ALLSET = bindings.ALLSET // In range RANGE = bindings.RANGE // Any value ANY = bindings.ANY // Empty value (usualy zero len array) EMPTY = bindings.EMPTY )
Condition types
const ( // ERROR Log level ERROR = bindings.ERROR // WARNING Log level WARNING = bindings.WARNING // INFO Log level INFO = bindings.INFO // TRACE Log level TRACE = bindings.TRACE )
const ( AggAvg = bindings.AggAvg AggSum = bindings.AggSum )
Variables ¶
var ( ErrEmptyNamespace = errors.New("rq: empty namespace name") ErrEmptyFieldName = errors.New("rq: empty field name in filter") ErrCondType = errors.New("rq: cond type not found") ErrOpInvalid = errors.New("rq: op is invalid") ErrNoPK = errors.New("rq: No pk field in struct") ErrWrongType = errors.New("rq: Wrong type of item") ErrMustBePointer = errors.New("rq: Argument must be a pointer to element, not element") ErrMergeAndJoinInOneQuery = errors.New("rq: Can't be merge and join in one query") ErrNotFound = errors.New("rq: Not found") )
Functions ¶
func GetCondType ¶
Types ¶
type FtFastConfig ¶
type FtFastConfig struct { // boost of bm25 ranking. default value 1. Bm25Boost float64 `json:"bm25_boost"` // weight of bm25 rank in final rank. // 0: bm25 will not change final rank. // 1: bm25 will affect to final rank in 0 - 100% range Bm25Weight float64 `json:"bm25_weight"` // boost of search query term distance in found document. default vaule 1 DistanceBoost float64 `json:"distance_boost"` // weight of search query terms distance in found document in final rank. // 0: distance will not change final rank. // 1: distance will affect to final rank in 0 - 100% range DistanceWeight float64 `json:"distance_weight"` // boost of search query term length. default value 1 TermLenBoost float64 `json:"term_len_boost"` // weight of search query term length in final rank. // 0: term length will not change final rank. // 1: term length will affect to final rank in 0 - 100% range TermLenWeight float64 `json:"term_len_weight"` // Minimum rank of found documents MinRelevancy float64 `json:"min_relevancy"` // Maximum possible typos in word. // 0: typos is disabled, words with typos will not match // N: words with N possible typos will match // It is not recommended to set more than 1 possible typo: It will serously increase RAM usage, and decrease search speed MaxTyposInWord int `json:"max_typos_in_word"` // Maximum word length for building and matching variants with typos. Default value is 15 MaxTypoLen int `json:"max_typo_len"` // Maximum documents which will be processed in merge query results // Default value is 20000. Increasing this value may refine ranking // of queries with high frequency words MergeLimit int `json:"merge_limit"` // List of used stemmers Stemmers []string `json:"stemmers"` // Enable translit variants processing EnableTranslit bool `json:"enable_translit"` // Enable wrong keyboard layout variants processing EnableKbLayout bool `json:"enable_kb_layout"` // List of stop words. Words from this list will be ignored in documents and queries StopWords []string `json:"stop_words"` // Log level of full text search engine LogLevel int `json:"log_level"` }
FtFastConfig configurarion of FullText search index
func DefaultFtFastConfig ¶
func DefaultFtFastConfig() FtFastConfig
type FtFuzzyConfig ¶
type FtFuzzyConfig struct { // max proc geting from src reqest MaxSrcProc float64 `json:"max_src_proc"` // max proc geting from dst reqest //usualy maxDstProc = 100 -MaxSrcProc but it's not nessary MaxDstProc float64 `json:"max_dst_proc"` // increse proc when found pos that are near between source and dst string (0.0001-2) PosSourceBoost float64 `json:"pos_source_boost"` // Minim coof for pos that are neaer in src and dst (0.0001-2) PosSourceDistMin float64 `json:"pos_source_dist_min"` // increse proc when found pos that are near in source string (0.0001-2) PosSourceDistBoost float64 `json:"pos_source_dist_boost"` // increse proc when found pos that are near in dst string (0.0001-2) PosDstBoost float64 `json:"pos_dst_boost"` // decrese proc when found not full thregramm - only start and end (0.0001-2) StartDecreeseBoost float64 `json:"start_decreese_boost"` // base decrese proc when found not full thregramm - only start and end (0.0001-2) StartDefaultDecreese float64 `json:"start_default_decreese"` // Min relevance to show reqest MinOkProc float64 `json:"min_ok_proc"` // size of gramm (1-10)- for example //terminator BufferSize=3 __t _te ter erm rmi ... //terminator BufferSize=4 __te _ter term ermi rmin BufferSize int `json:"buffer_size"` // size of space in start and end of gramm (0-9) - for example //terminator SpaceSize=2 __t _te ter ... tor or_ r__ //terminator SpaceSize=1 _te ter ... tor or_ SpaceSize int `json:"space_size"` // Maximum documents which will be processed in merge query results // Default value is 20000. Increasing this value may refine ranking // of queries with high frequency words MergeLimit int `json:"merge_limit"` // List of used stemmers Stemmers []string `json:"stemmers"` // Enable translit variants processing EnableTranslit bool `json:"enable_translit"` // Enable wrong keyboard layout variants processing EnableKbLayout bool `json:"enable_kb_layout"` // List of stop words. Words from this list will be ignored in documents and queries StopWords []string `json:"stop_words"` // Log level of full text search engine LogLevel int `json:"log_level"` }
FtFuzzyConfig configurarion of FuzzyFullText search index
func DefaultFtFuzzyConfig ¶
func DefaultFtFuzzyConfig() FtFuzzyConfig
type IndexDescription ¶
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator presents query results
func (*Iterator) AggResults ¶
AggResults returns aggregation results (if present)
func (*Iterator) AllowUnsafe ¶
AllowUnsafe takes bool, that enable or disable unsafe behavior.
When AllowUnsafe is true and object cache is enabled resulting objects will not be copied for each query. That means possible race conditions. But it's good speedup, without overhead for copying.
By default reindexer guarantees that every object its safe to use in multithread.
func (*Iterator) Close ¶
func (it *Iterator) Close()
Close closes the iterator and freed CGO resources
func (*Iterator) FetchAll ¶
FetchAll returns all query results as slice []interface{} and closes the iterator.
func (*Iterator) FetchAllWithRank ¶
FetchAllWithRank returns resulting slice of objects and slice of objects ranks. Closes iterator after use.
func (*Iterator) FetchOne ¶
FetchOne returns first element and closes the iterator. When it's impossible (count is 0) err will be ErrNotFound.
func (*Iterator) GetAggreatedValue ¶
GetAggreatedValue - Return aggregation sum of field
func (*Iterator) JoinedObjects ¶
JoinedObjects returns objects slice, that result of join for the given field
func (*Iterator) Next ¶
Next moves iterator pointer to the next element. Returns bool, that indicates the availability of the next elements.
func (*Iterator) Object ¶
func (it *Iterator) Object() interface{}
Object returns current object. Will panic when pointer was not moved, Next() must be called before.
func (*Iterator) Rank ¶
Rank returns current object search rank. Will panic when pointer was not moved, Next() must be called before.
func (*Iterator) TotalCount ¶
TotalCount returns total count of objects (ignoring conditions of limit and offset)
type JSONIterator ¶
type JSONIterator struct {
// contains filtered or unexported fields
}
JSONIterator its iterator, but results presents as json documents
func (*JSONIterator) Count ¶
func (it *JSONIterator) Count() int
Count returns count if query results
func (*JSONIterator) Error ¶
func (it *JSONIterator) Error() error
Error returns query error if it's present.
func (*JSONIterator) FetchAll ¶
func (it *JSONIterator) FetchAll() (json []byte, err error)
FetchAll returns bytes slice it's JSON array with results
func (*JSONIterator) JSON ¶
func (it *JSONIterator) JSON() (json []byte)
JSON returns JSON bytes with current document
func (*JSONIterator) Next ¶
func (it *JSONIterator) Next() bool
Next moves iterator pointer to the next element. Returns bool, that indicates the availability of the next elements.
type JoinHandler ¶
JoinHandler it's function for handle join results. Returns bool, that indicates is values will be applied to structs.
type Joinable ¶
type Joinable interface {
Join(field string, subitems []interface{}, context interface{})
}
Interface for append joined items
type NamespaceDescription ¶
type NamespaceDescription struct { Name string `json:"name"` UpdatedUnixNano int64 `json:"updated_unix_nano"` Indices []IndexDescription `json:"indexes"` StorageEnabled bool `json:"storage_enabled"` StorageOK bool `json:"storage_ok"` StoragePath string `json:"storage_path,omitempty"` StorageError string `json:"storage_error,omitempty"` ItemsCount int `json:"items_count,omitempty"` }
type NamespaceOptions ¶
type NamespaceOptions struct {
// contains filtered or unexported fields
}
NamespaceOptions is options for namespace
func DefaultNamespaceOptions ¶
func DefaultNamespaceOptions() *NamespaceOptions
DefaultNamespaceOptions return defailt namespace options
func (*NamespaceOptions) DropOnFileFormatError ¶
func (opts *NamespaceOptions) DropOnFileFormatError() *NamespaceOptions
func (*NamespaceOptions) DropOnIndexesConflict ¶
func (opts *NamespaceOptions) DropOnIndexesConflict() *NamespaceOptions
func (*NamespaceOptions) NoStorage ¶
func (opts *NamespaceOptions) NoStorage() *NamespaceOptions
type Query ¶
type Query struct { Namespace string // contains filtered or unexported fields }
Query to DB object
func (*Query) CachedTotal ¶
CachedTotal Request cached total items calculation
func (*Query) Delete ¶
Delete will execute query, and delete items, matches query On sucess return number of deleted elements
func (*Query) ExecToJson ¶
func (q *Query) ExecToJson(jsonRoots ...string) *JSONIterator
ExecAsJson will execute query, and return iterator
func (*Query) InnerJoin ¶
InnerJoin joins 2 queries - items from 1-st query are expanded with data from joined query
func (*Query) JoinHandler ¶
func (q *Query) JoinHandler(field string, handler JoinHandler) *Query
JoinHandler sets handler for join results
func (*Query) LeftJoin ¶
LeftJoin joins 2 queries = - items from 1-st query are filtered and expanded with data from 2-nd query
func (*Query) SetContext ¶
SetContext set interface, which will be passed to Joined interface
func (*Query) WhereDouble ¶
WhereDouble - Add where condition to DB query with float args
func (*Query) WhereInt64 ¶
WhereInt64 - Add where condition to DB query with int64 args
type Reindexer ¶
type Reindexer struct {
// contains filtered or unexported fields
}
Reindexer The reindxer state struct
func NewReindex ¶
NewReindex Create new instanse of Reindexer DB Returns pointer to created instance
func (*Reindexer) CloneNamespace ¶
CloneNamespace - make a copy of namespace in DB. If dst namespace already exists, method will fail
func (*Reindexer) CloseNamespace ¶
CloseNamespace - close namespace, but keep storage
func (*Reindexer) ConfigureIndex ¶
ConfigureIndex - congigure index. config argument must be struct with index configuration
func (*Reindexer) Delete ¶
Delete - remove item from namespace Item must be the same type as item passed to NewNamespace, or []byte with json data
func (*Reindexer) DeleteNamespace ¶
DeleteNamespace [[deprecated]]
func (*Reindexer) DescribeNamespace ¶
func (db *Reindexer) DescribeNamespace(namespace string) (*NamespaceDescription, error)
DescribeNamespace makes a 'describe NAMESPACE' query to database. Return NamespaceDescription results, error
func (*Reindexer) DescribeNamespaces ¶
func (db *Reindexer) DescribeNamespaces() ([]*NamespaceDescription, error)
DescribeNamespaces makes a 'describe *' query to database. Return NamespaceDescription results, error
func (*Reindexer) DropNamespace ¶
DropNamespace - drop whole namespace from DB
func (*Reindexer) EnableStorage ¶
EnableStorage enables persistent storage of data [[deprecated]] storage path should be passed as DSN part to reindexer.NewReindex (""), e.g. reindexer.NewReindexer ("builtin:///tmp/reindex")
func (*Reindexer) ExecSQLToJSON ¶
func (db *Reindexer) ExecSQLToJSON(query string) *JSONIterator
func (*Reindexer) GetUpdatedAt ¶
GetUpdatedAt - get updated at time of namespace
func (*Reindexer) Insert ¶
Insert item to namespace. Item must be the same type as item passed to NewNamespace, or []byte with json data Return 0, if no item was inserted, 1 if item was inserted
func (*Reindexer) MustBeginTx ¶
MustBeginTx - start update transaction, panic on error
func (*Reindexer) NewNamespace ¶
func (db *Reindexer) NewNamespace(namespace string, opts *NamespaceOptions, s interface{}) error
NewNamespace [[depreacted]]
func (*Reindexer) OpenNamespace ¶
func (db *Reindexer) OpenNamespace(namespace string, opts *NamespaceOptions, s interface{}) (err error)
OpenNamespace Open or create new namespace and indexes based on passed struct. IndexDescription fields of struct are marked by `reindex:` tag
func (*Reindexer) RenameNamespace ¶
RenameNamespace - rename namespace in DB. If dst namespace already exists, it will be overwriten
func (*Reindexer) ResetStats ¶
func (db *Reindexer) ResetStats()
Reset local thread reindexer usage stats
func (*Reindexer) SetDefaultQueryDebug ¶
SetDefaultQueryDebug sets default debug level for queries to namespaces
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is Transaction object. When begin transaction creates clone of namespace and update clone On commit updated namespace clone will be atomicaly replace origin namespace Om rollback updated namespace clone will be removed There are only 1 active transaction on 1 namespace is possible
func (*Tx) DeleteJSON ¶
DeleteJSON - remove item by id from namespace
func (*Tx) MustCommit ¶
func (*Tx) UpsertJSON ¶
UpsertJSON (Insert or Update) item to index