Documentation ¶
Index ¶
- Constants
- Variables
- func WhiteSpaceTokenizer(text string) []string
- type BoolScalar
- type Collection
- type CollectionType
- type Document
- type DocumentWalker
- type FieldIndexer
- type Float64Scalar
- type Index
- type IndexOption
- type Key
- type Query
- type QueryPart
- type QueryPath
- type QueryPathComparable
- type Reference
- type ReferenceFunc
- type ReferenceScanFn
- type Scalar
- func JSONLDValueCollector(collection *collection, document Document, queryPath QueryPath) ([]Scalar, error)
- func JSONPathValueCollector(_ *collection, document Document, queryPath QueryPath) ([]Scalar, error)
- func MustParseScalar(value interface{}) Scalar
- func ParseScalar(value interface{}) (Scalar, error)
- func ToLower(scalar Scalar) Scalar
- type Store
- type StoreOption
- type StringScalar
- type Tokenizer
- type Transform
Constants ¶
const KeyDelimiter = 0x10
Variables ¶
var ErrInvalidJSON = errors.New("invalid json")
ErrInvalidJSON is returned when invalid JSON is parsed
var ErrInvalidQuery = errors.New("invalid query type")
ErrInvalidQuery is returned when a collection is queried with the wrong type
var ErrInvalidValue = errors.New("invalid value")
ErrInvalidValue is returned when an invalid value is parsed
var ErrNoIndex = errors.New("no index found")
ErrNoIndex is returned when no index is found to query against
var ErrNoQuery = errors.New("no query given")
ErrNoQuery is returned when an empty query is given
Functions ¶
func WhiteSpaceTokenizer ¶
WhiteSpaceTokenizer tokenizes the string based on the /\S/g regex
Types ¶
type BoolScalar ¶
type BoolScalar bool
func (BoolScalar) Bytes ¶
func (bs BoolScalar) Bytes() []byte
type Collection ¶
type Collection interface { // AddIndex to this collection. It doesn't matter if the index already exists. // If you want to override an index (by path) drop it first. AddIndex(index ...Index) error // DropIndex by path DropIndex(name string) error // NewIndex creates a new index from the context of this collection // If multiple field indexers are given, a compound index is created. NewIndex(name string, parts ...FieldIndexer) Index // Add a set of documents to this collection Add(jsonSet []Document) error // Get returns the data for the given key or nil if not found Get(ref Reference) (Document, error) // Delete a document Delete(doc Document) error // Find queries the collection for documents // returns ErrNoIndex when no suitable index can be found // returns context errors when the context has been cancelled or deadline has exceeded. // passing ctx prevents adding too many records to the result set. Find(ctx context.Context, query Query) ([]Document, error) // Reference uses the configured reference function to generate a reference of the function Reference(doc Document) Reference // Iterate over documents that match the given query Iterate(query Query, walker DocumentWalker) error // IndexIterate is used for iterating over indexed values. The query keys must match exactly with all the FieldIndexer.Name() of an index // returns ErrNoIndex when no suitable index can be found IndexIterate(query Query, fn ReferenceScanFn) error // ValuesAtPath returns a slice with the values found by the configured valueCollector ValuesAtPath(document Document, queryPath QueryPath) ([]Scalar, error) // DocumentCount returns the number of indexed documents DocumentCount() (int, error) }
Collection defines a logical collection of documents and indices within a store.
type CollectionType ¶
type CollectionType int
CollectionType defines if a Collection is a JSON collection or JSONLD collection.
const ( // JSONCollection defines a collection uses JSON search paths to index documents JSONCollection CollectionType = iota // JSONLDCollection defines a collection uses JSON-LD IRI search paths to index documents JSONLDCollection )
type DocumentWalker ¶
DocumentWalker defines a function that is used as a callback for matching documents. The key will be the document Reference (hash) and the value will be the raw document bytes
type FieldIndexer ¶
type FieldIndexer interface { QueryPathComparable // Tokenize may split up Keys and search terms. For example split a sentence into words. Tokenize(value Scalar) []Scalar // Transform is a function that alters the value to be indexed as well as any search criteria. // For example LowerCase is a Transform function that transforms the value to lower case. Transform(value Scalar) Scalar }
FieldIndexer is the public interface that defines functions for a field index instruction. A FieldIndexer is used when a document is indexed.
func NewFieldIndexer ¶
func NewFieldIndexer(jsonPath QueryPath, options ...IndexOption) FieldIndexer
NewFieldIndexer creates a new fieldIndexer
type Float64Scalar ¶
type Float64Scalar float64
func (Float64Scalar) Bytes ¶
func (fs Float64Scalar) Bytes() []byte
type Index ¶
type Index interface { // Name returns the path of this index Name() string // Add indexes the document. It uses a sub-bucket of the given bucket. // It will only be indexed if the complete index matches. Add(bucket *bbolt.Bucket, ref Reference, doc Document) error // Delete document from the index Delete(bucket *bbolt.Bucket, ref Reference, doc Document) error // IsMatch determines if this index can be used for the given query. The higher the return value, the more likely it is useful. // return values lie between 0.0 and 1.0, where 1.0 is the most useful. IsMatch(query Query) float64 // Iterate over the key/value pairs given a query. Entries that match the query are passed to the iteratorFn. // it will not filter out double values Iterate(bucket *bbolt.Bucket, query Query, fn iteratorFn) error // BucketName returns the bucket path for this index BucketName() []byte // QueryPartsOutsideIndex selects the queryParts that are not covered by the index. QueryPartsOutsideIndex(query Query) []QueryPart // Depth returns the number of indexed fields Depth() int // Keys returns the scalars found in the document at the location specified by the FieldIndexer Keys(fi FieldIndexer, document Document) ([]Scalar, error) }
Index describes an index. An index is based on a json path and has a path. The path is used for storage but also as identifier in search options.
type IndexOption ¶
type IndexOption func(fieldIndexer *fieldIndexer)
IndexOption is the option function for adding options to a FieldIndexer
func TokenizerOption ¶
func TokenizerOption(tokenizer Tokenizer) IndexOption
TokenizerOption is the option for a FieldIndexer to split a value to be indexed into multiple parts. Each part is then indexed separately.
func TransformerOption ¶
func TransformerOption(transformer Transform) IndexOption
TransformerOption is the option for a FieldIndexer to apply transformation before indexing the value. The transformation is also applied to a query value that matches the indexed field.
type Key ¶
type Key []byte
Key is used as DB key type
func ComposeKey ¶
ComposeKey creates a new key from two keys
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query represents a query with multiple arguments
type QueryPart ¶
type QueryPart interface { QueryPathComparable // Seek returns the key for cursor.Seek Seek() Scalar // Condition returns true if given key falls within this condition. // The optional transform fn is applied to this query part before evaluation is done. Condition(key Key, transform Transform) bool }
func NotNil ¶
NotNil creates a query part where the value must exist. This is done by finding results between byte 0x0 and 0xff
type QueryPath ¶
QueryPath is the interface for the query path given in queries
func NewIRIPath ¶
NewIRIPath creates a QueryPath of JSON-LD terms
func NewJSONPath ¶
NewJSONPath creates a JSON path query: "person.path" or "person.children.#.path" # is used to traverse arrays
type QueryPathComparable ¶
type QueryPathComparable interface { // Equals returns true if the two QueryPathComparable have the same search path. Equals(other QueryPathComparable) bool // QueryPath returns the QueryPath QueryPath() QueryPath }
QueryPathComparable defines if two structs can be compared on query path.
type Reference ¶
type Reference []byte
Reference equals a document hash. In an index, the values are references to docs.
func (Reference) EncodeToString ¶
EncodeToString encodes the reference as hex encoded string
type ReferenceFunc ¶
ReferenceFunc is the func type used for creating references. references are the key under which a document is stored. a ReferenceFunc could be the sha256 func or something that stores document in chronological order. The first would be best for random access, the latter for chronological access
type ReferenceScanFn ¶
ReferenceScanFn is a function type which is called with an index key and a document Reference as value
type Scalar ¶
type Scalar interface { // Bytes returns the byte value Bytes() []byte // contains filtered or unexported methods }
Scalar represents a JSON or JSON-LD scalar (string, number, true or false)
func JSONLDValueCollector ¶
func JSONLDValueCollector(collection *collection, document Document, queryPath QueryPath) ([]Scalar, error)
JSONLDValueCollector collects values given a list of IRIs that represent the nesting of the objects.
func JSONPathValueCollector ¶
func JSONPathValueCollector(_ *collection, document Document, queryPath QueryPath) ([]Scalar, error)
JSONPathValueCollector collects values at a given JSON path expression. Objects are delimited by a dot and lists use an extra # in the expression: object.list.#.key
func MustParseScalar ¶
func MustParseScalar(value interface{}) Scalar
MustParseScalar returns a Scalar based on an interface value. It panics when the value is not supported.
func ParseScalar ¶
ParseScalar returns a Scalar based on an interface value. It returns ErrInvalidValue for unsupported values.
type Store ¶
type Store interface { // Collection creates or returns a Collection of the specified type. // On the db level it's a bucket for the documents and 1 bucket per index. Collection(collectionType CollectionType, name string) Collection // Close the bbolt DB Close() error }
Store is the main interface for storing/finding documents
type StoreOption ¶
type StoreOption func(store *store)
StoreOption is the function type for the Store Options
func WithDocumentLoader ¶
func WithDocumentLoader(documentLoader ld.DocumentLoader) StoreOption
WithDocumentLoader overrides the default document loader
func WithoutSync ¶
func WithoutSync() StoreOption
WithoutSync is a store option which signals the underlying bbolt db to skip syncing with disk
type StringScalar ¶
type StringScalar string
func (StringScalar) Bytes ¶
func (ss StringScalar) Bytes() []byte