This package provides a file indexer, which indexes files in one or more folders (and their child folders) in an sqlite3 database, and can update when files and folders are added, changed and deleted.
This package is part of a wider project, github.com/mutablelogic/go-sqlite
.
Please see the module documentation
for more information.
An indexing process consists of:
- In
Indexer
object, which runs the indexing process; - A
Queue
object, which receives change events from the indexer and passes them onto the storage; - A
Store
object, which consumes change events and maintains the database.
To create an indexer, use the NewIndexer
function. Pass the unique name for the index,
the path to the folder to index, and a Queue
object. For example,
package main
import (
// Packages
"github.com/mutablelogic/go-sqlite/pkg/indexer"
)
func main() {
name, path := // ....
// Create a queue and indexer
queue := indexer.NewQueue()
indexer, err := indexer.NewIndexer(name, path, queue)
if err != nil {
panic(err)
}
// Perform indexing in background process...
var wg sync.WaitGroup
go Index(&wg, indexer)
go Walk(&wg, indexer)
go Process(&wg, queue)
// Wait for all goroutines to finish
wg.Wait()
// Do any cleanup here
}
The three background goroutines are:
Index
: Watches for changes to the folder and indexes the files;Walk
: Performs a recursive walk of the folder and indexes the files;Process
: Consumes change events from the queue and updates the database.
TODO
TODO
There is an example application here which will index a folder into an sqlite database, and a plugin for go-server here which provides a REST API to the indexing process. You may want to build your own application to index your files, in which case read on.