Documentation
¶
Overview ¶
Package schema is the schema of the file indexer: its tables, its queries, and the types which are read from, and written to, them.
The schema needs SQLite's full-text search, of fts5, such as:
import _ "github.com/mutablelogic/go-sqlite/ncruces/fts5"
Index ¶
- Constants
- Variables
- func Create(ctx context.Context, conn sqlite.Conn) error
- func FormatSize(size int64) string
- func NewQueries() (*sqlite.Queries, error)
- type Artwork
- type ArtworkID
- type IndexVolumeRequest
- type Object
- type ObjectID
- type ObjectList
- type ObjectListRequest
- type ObjectMark
- type ObjectMeta
- type ObjectPath
- type ObjectSweep
- type Order
- type Progress
- type Status
- type Volume
- type VolumeFinish
- type VolumeID
- type VolumeList
- type VolumeListRequest
- type VolumeMeta
- type VolumePath
- type VolumeStart
Constants ¶
const ( // Version is the version of the schema, of the database's user_version Version = 3 // MinPathLength is the fewest characters of a part of a path, a folder // or a name, which is searched MinPathLength = 3 // ListLimit is the most objects which are listed, or searched, at once ListLimit = 100 // DefaultCutoff is the lowest rank of a search, between 0 and 1, unless // it's set, so the objects which match it least aren't returned DefaultCutoff = 0.15 )
Variables ¶
var Objects string
var Queries string
Functions ¶
func Create ¶
Create creates the schema, in a transaction, when the database hasn't one, and sets its version. A database whose schema is newer is an error.
func FormatSize ¶
FormatSize returns a size in bytes, or in KiB, MiB, GiB or TiB, with one decimal place, when it's larger
func NewQueries ¶
NewQueries returns the queries, which a connection is bound to, with WithQueries, so the types' selectors and writers use them
Types ¶
type ArtworkID ¶
type ArtworkID int64
ArtworkID selects an object's artwork, by its id, which is ErrNotFound when it hasn't any
type IndexVolumeRequest ¶
type IndexVolumeRequest struct {
Path string `json:"path"`
Recursive bool `json:"recursive,omitempty"`
Reindex bool `json:"reindex,omitempty"`
}
IndexVolumeRequest indexes a volume, of a folder, and its folders, when it's recursive, of the files which are new, or changed, or all of them, when they're reindexed
type Object ¶
type Object struct {
ID int64 `json:"id"`
Volume int64 `json:"volume"`
Path string `json:"path"` // Relative to its volume's
Size int64 `json:"size"`
ModTime time.Time `json:"modtime"`
Type string `json:"type,omitempty"`
Kind string `json:"kind,omitempty"`
Title string `json:"title,omitempty"`
Meta map[string]any `json:"meta,omitempty"`
Indexed time.Time `json:"indexed"` // When it was indexed
Run int64 `json:"run"` // The run of its volume which last saw it
Rank *float64 `json:"rank,omitempty"` // How well it matches a search, between 0 and 1, which is higher the better, or nil
}
Object is a file which is indexed, of a volume, which is read
type ObjectList ¶
type ObjectList struct {
ObjectListRequest
Count uint64 `json:"count"`
Body []Object `json:"body,omitempty"`
}
ObjectList is a list of objects, of its request, with the limit which was used, and their count, without their offset and limit
func (*ObjectList) Scan ¶
func (l *ObjectList) Scan(row sqlite.Row) error
Scan reads an object of a list
func (*ObjectList) ScanCount ¶
func (l *ObjectList) ScanCount(row sqlite.Row) error
ScanCount reads the count of a list
func (ObjectList) String ¶
func (o ObjectList) String() string
type ObjectListRequest ¶
type ObjectListRequest struct {
sqlite.OffsetLimit
Volumes []int64 `json:"volume,omitempty" help:"Objects of the volumes, or of all of them"`
Types []string `` /* 177-byte string literal not displayed */
Query *string `json:"q,omitempty" help:"Words, which are all in the objects' text"`
Order Order `` /* 163-byte string literal not displayed */
Cutoff *float64 `` /* 133-byte string literal not displayed */
}
ObjectListRequest lists objects, of the volumes, or all of them, when there are none, the newest first, or, when there's a query, searches them, of its words, which are all in their text, as prefixes, the best first, unless it has another order. A query without any words matches nothing.
type ObjectMark ¶
ObjectMark selects an object which is as it was, of its volume, path, size and when it was modified, to mark it as seen by its volume's run, rather than indexing it again, with Update, which is ErrNotFound when it isn't
type ObjectMeta ¶
type ObjectMeta struct {
Volume int64 `json:"volume"` // Its volume
Path string `json:"path"` // Relative to its volume's
Size int64 `json:"size"` // In bytes
ModTime time.Time `json:"modtime"` // When it was modified
Type string `json:"type,omitempty"` // Its content type
Kind string `json:"kind,omitempty"` // Its kind, such as photo or book
Title string `json:"title,omitempty"` // Its title
Meta map[string]any `json:"meta,omitempty"` // Its metadata, of "ns:key"
Artwork []byte `json:"-"` // An image, which is kept, and read on its own
Text string `json:"-"` // Its content, as Markdown, which is searched, and not kept
Run int64 `json:"run"` // The run of its volume which indexed it
}
ObjectMeta is what's indexed of a file, of a volume, which is written
type ObjectPath ¶
type ObjectPath string
ObjectPath selects the objects of a path, to list them: of their volume's path, and their own, or their own, or the end of it, after a /, such as a file's name
type ObjectSweep ¶
ObjectSweep selects the objects of a volume, which its run didn't see, once its run indexed it, to delete them. The run is the volume's latest, so a run which is indexing, or failed, or an older one, sweeps nothing.
type Order ¶
type Order string
Order is the order of a list of objects
const ( OrderRank Order = "rank" // The best match first, of a search, which is its default OrderDate Order = "date" // The newest first, of when they were modified, which is a list's default OrderPath Order = "path" // By volume, and path OrderSize Order = "size" // The largest first OrderTitle Order = "title" // By title, of any case, and those without one last )
The orders of a list of objects, which, when they're the same, are of their volumes and paths
type Progress ¶
type Progress struct {
Volume int64 `json:"volume"`
Path string `json:"path"` // The volume's path
Run int64 `json:"run"` // The run which is indexing it
Started time.Time `json:"started"` // When the run started
Reindex bool `json:"reindex,omitempty"` // All of its files are indexed again, rather than those which are new, or changed
Current string `json:"current,omitempty"` // The file which is being indexed, within the volume
Total uint64 `json:"total"` // The files of the volume, which are counted before it's walked
Files uint64 `json:"files"` // The files which were seen
Indexed uint64 `json:"indexed"` // Of which were new, or changed, and were indexed
Marked uint64 `json:"marked"` // Of which were as they were, and were marked
Swept uint64 `json:"swept"` // The objects which weren't seen, which were swept, once it's indexed
// When it finished, or nil while it's indexing
Finished *time.Time `json:"finished,omitempty"`
}
Progress is how far a run of a volume has indexed it, while it's indexing, or how it did, once it's finished
type Volume ¶
type Volume struct {
ID int64 `json:"id"`
Path string `json:"path"`
Status Status `json:"status"`
Run int64 `json:"run"` // The run, which marks the objects it sees, or 0
Started *time.Time `json:"started,omitempty"` // When the run started
Finished *time.Time `json:"finished,omitempty"` // When it finished, or nil while it's indexing
Error string `json:"error,omitempty"` // Why it failed
Reader string `json:"reader,omitempty"` // What read it, of the last run which indexed it
Objects uint64 `json:"objects"` // The objects which are indexed
}
Volume is a folder which is indexed, with the status of its indexing
type VolumeFinish ¶
type VolumeFinish struct {
Run int64
Finished time.Time
Error error
Reader string // What read it, which is kept when it's indexed
}
VolumeFinish finishes its run, which indexed it, or failed, of its error, with Update, which is ErrNotFound when it isn't indexing, or the run isn't its latest, as another started after it
type VolumeID ¶
type VolumeID int64
VolumeID selects a volume, by its id, to get, start, finish or delete it
type VolumeList ¶
type VolumeList struct {
VolumeListRequest
Count uint64 `json:"count"`
Body []Volume `json:"body,omitempty"`
}
VolumeList is a list of volumes, of its request, with the limit which was used, and their count
func (*VolumeList) Scan ¶
func (l *VolumeList) Scan(row sqlite.Row) error
Scan reads a volume of a list
func (*VolumeList) ScanCount ¶
func (l *VolumeList) ScanCount(row sqlite.Row) error
ScanCount reads the count of a list
func (VolumeList) String ¶
func (v VolumeList) String() string
type VolumeListRequest ¶
type VolumeListRequest struct {
sqlite.OffsetLimit
}
VolumeListRequest lists the volumes, by their paths
type VolumeMeta ¶
type VolumeMeta struct {
Path string `json:"path"`
}
VolumeMeta is a folder which is indexed, by its absolute path, which is added, or is the one of it already
type VolumePath ¶
type VolumePath string
VolumePath selects a volume, by its absolute path, to get it
type VolumeStart ¶
VolumeStart starts its next run, which is indexing it, with Update