diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2025-11-21 20:50:42 -0500 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2025-11-21 20:50:42 -0500 |
| commit | 1aad60b49a32b6bced95a251f266799c031ca83e (patch) | |
| tree | 4b156c7f6df11a164a31a5615d30f9cd6f07c44f | |
| parent | 7383ea149c9444c297e21f21294fd41e67f9c9ff (diff) | |
Update documentation, comments, and tidy codebase
| -rw-r--r-- | pkg/data/db.go | 20 | ||||
| -rw-r--r-- | pkg/data/put_test.go | 2 | ||||
| -rw-r--r-- | pkg/index/filters.go | 2 | ||||
| -rw-r--r-- | pkg/query/compiler.go | 11 | ||||
| -rw-r--r-- | pkg/query/errors.go | 1 | ||||
| -rw-r--r-- | pkg/query/lexer.go | 4 | ||||
| -rw-r--r-- | pkg/query/optimizer.go | 3 |
7 files changed, 29 insertions, 14 deletions
diff --git a/pkg/data/db.go b/pkg/data/db.go index 7d151e1..56024d3 100644 --- a/pkg/data/db.go +++ b/pkg/data/db.go @@ -14,6 +14,20 @@ import ( "github.com/mattn/go-sqlite3" ) +// _ = ` +// CREATE VIEW IF NOT EXISTS search2 AS +// SELECT +// * +// FROM Documents d +// JOIN Documents_fts AS d_fts ON d.id = d_fts.rowid +// +// DocumentAuthors AS da +// JOIN Authors_fts AS a_fts ON da.authorId = a_fts.rowid +// +// DocumentTags AS dt +// JOIN Tags_fts AS t_fts ON dt.tagId = t_fts.rowid +// ` + type Query struct { db *sql.DB } @@ -242,7 +256,6 @@ func createSchema(db *sql.DB, version string) error { ) `) - // FIXME: doesn't set new.id _, err = tx.Exec(` CREATE TRIGGER IF NOT EXISTS trig_ai_authors AFTER INSERT ON Authors @@ -269,7 +282,6 @@ func createSchema(db *sql.DB, version string) error { return err } - // FIXME: doesn't set new.id _, err = tx.Exec(` CREATE TRIGGER IF NOT EXISTS trig_au_authors AFTER UPDATE ON Authors @@ -311,7 +323,6 @@ func createSchema(db *sql.DB, version string) error { return err } - // FIXME: doesn't set new.id _, err = tx.Exec(` CREATE TRIGGER IF NOT EXISTS trig_au_tags AFTER UPDATE ON Tags @@ -353,7 +364,6 @@ func createSchema(db *sql.DB, version string) error { return err } - // FIXME: doesn't set new.id _, err = tx.Exec(` CREATE TRIGGER IF NOT EXISTS trig_au_links AFTER UPDATE ON Links @@ -369,7 +379,6 @@ func createSchema(db *sql.DB, version string) error { return err } - // FIXME: doesn't set new.id _, err = tx.Exec(` CREATE TRIGGER IF NOT EXISTS trig_ai_doc AFTER INSERT ON Documents @@ -396,7 +405,6 @@ func createSchema(db *sql.DB, version string) error { return err } - // FIXME: doesn't set new.id _, err = tx.Exec(` CREATE TRIGGER IF NOT EXISTS trig_au_doc AFTER UPDATE ON Documents diff --git a/pkg/data/put_test.go b/pkg/data/put_test.go index a450196..e4a3c57 100644 --- a/pkg/data/put_test.go +++ b/pkg/data/put_test.go @@ -45,7 +45,7 @@ func TestPut_Insert(t *testing.T) { p := data.NewPut(db, tt.doc) gotErr := p.Insert(t.Context()) if !errors.Is(gotErr, tt.wantErr) { - t.Fatalf("Unexpected error on Insert():, want %v got %v", tt.wantErr, gotErr) + t.Fatalf("Unexpected error on Insert(): want %v got %v", tt.wantErr, gotErr) } else if gotErr != nil { return } diff --git a/pkg/index/filters.go b/pkg/index/filters.go index 3deee6d..083b4af 100644 --- a/pkg/index/filters.go +++ b/pkg/index/filters.go @@ -48,10 +48,8 @@ func ParseFilter(s string) (DocFilter, error) { } return NewMaxFilesizeFilter(size), nil case "ExcludeName", "ExcludeFilename": - // TODO: support escaped commas return NewExcludeFilenameFilter(strings.Split(param, ",")), nil case "IncludeName", "IncludeFilename": - // TODO: support escaped commas return NewIncludeFilenameFilter(strings.Split(param, ",")), nil case "ExcludeParent": return NewExcludeParentFilter(param), nil diff --git a/pkg/query/compiler.go b/pkg/query/compiler.go index 7d24b10..2272933 100644 --- a/pkg/query/compiler.go +++ b/pkg/query/compiler.go @@ -103,6 +103,13 @@ func (s Statements) buildCompile(b *strings.Builder, delim string) ([]any, error } } + // NOTE: cases + // cat op + // any re + // .isOrd ap + // .isSet !ap + // .isSet ap + // any any if op == OP_RE { idx := 0 for _, stmt := range opStmts { @@ -197,6 +204,8 @@ func (s Statements) buildCompile(b *strings.Builder, delim string) ([]any, error } for _, stmt := range opStmts { if stmt.Negated { + // FIXME: doesn't evaluate correctly for when using MATCH operator in SQL + // a potential fix for negated statements is using an EXCEPT-like subquery b.WriteString("NOT ") } b.WriteString(catStr) @@ -278,7 +287,7 @@ func (c Clause) buildCompile(b *strings.Builder) ([]any, error) { } if !isRoot { - b.WriteString(") ") + b.WriteString(")") } return args, nil diff --git a/pkg/query/errors.go b/pkg/query/errors.go index 889d40d..713e9f0 100644 --- a/pkg/query/errors.go +++ b/pkg/query/errors.go @@ -16,7 +16,6 @@ var ErrExpectedMoreStringTokens = errors.New("Expected more string tokens") var ErrUnexpectedValueType = errors.New("Unexpected value type") var ErrEmptyResult = errors.New("Queries are contradictory, will lead to an empty result") - type TokenError struct { got Token gotPrev Token diff --git a/pkg/query/lexer.go b/pkg/query/lexer.go index 0ebdb1d..bdb09ef 100644 --- a/pkg/query/lexer.go +++ b/pkg/query/lexer.go @@ -130,6 +130,10 @@ func (t queryTokenType) isCategory() bool { TOK_CAT_META) } +func (t queryTokenType) isOrdered() bool { + return t == TOK_CAT_DATE || t == TOK_CAT_FILETIME +} + func (t queryTokenType) isDateOperation() bool { return t.Any(TOK_OP_EQ, TOK_OP_AP, TOK_OP_NE, TOK_OP_LT, TOK_OP_LE, TOK_OP_GE, TOK_OP_GT) } diff --git a/pkg/query/optimizer.go b/pkg/query/optimizer.go index 337ee35..21de619 100644 --- a/pkg/query/optimizer.go +++ b/pkg/query/optimizer.go @@ -9,9 +9,6 @@ import ( "github.com/jpappel/atlas/pkg/util" ) -// FIXME: any substring checks on unorderd approximate statements will fail -// this is because quotes are added to all approximate string values - type Optimizer struct { workers uint root *Clause |
