|
|
|
@ -147,7 +147,54 @@ func (d *NoteDAO) exists(path string) (bool, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *NoteDAO) Find(opts note.FinderOpts, callback func(note.Match) error) (int, error) {
|
|
|
|
|
rows, err := func() (*sql.Rows, error) {
|
|
|
|
|
rows, err := d.findRows(opts)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
|
|
count := 0
|
|
|
|
|
for rows.Next() {
|
|
|
|
|
count++
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
id, wordCount int
|
|
|
|
|
title, body, snippet string
|
|
|
|
|
path, checksum string
|
|
|
|
|
created, modified time.Time
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
err := rows.Scan(&id, &path, &title, &body, &wordCount, &created, &modified, &checksum, &snippet)
|
|
|
|
|
if err != nil {
|
|
|
|
|
d.logger.Err(err)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(note.Match{
|
|
|
|
|
Snippet: snippet,
|
|
|
|
|
Metadata: note.Metadata{
|
|
|
|
|
Path: path,
|
|
|
|
|
Title: title,
|
|
|
|
|
Body: body,
|
|
|
|
|
WordCount: wordCount,
|
|
|
|
|
Created: created,
|
|
|
|
|
Modified: modified,
|
|
|
|
|
Checksum: checksum,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return count, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type findQuery struct {
|
|
|
|
|
SnippetCol string
|
|
|
|
|
WhereExprs []string
|
|
|
|
|
OrderTerms []string
|
|
|
|
|
Args []interface{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *NoteDAO) findRows(opts note.FinderOpts) (*sql.Rows, error) {
|
|
|
|
|
snippetCol := `""`
|
|
|
|
|
whereExprs := make([]string, 0)
|
|
|
|
|
orderTerms := make([]string, 0)
|
|
|
|
@ -223,46 +270,9 @@ ON n.id = notes_fts.rowid`
|
|
|
|
|
query += fmt.Sprintf("\nLIMIT %d", opts.Limit)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fmt.Println(query)
|
|
|
|
|
// fmt.Println(args)
|
|
|
|
|
return d.tx.Query(query, args...)
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
|
|
count := 0
|
|
|
|
|
for rows.Next() {
|
|
|
|
|
count++
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
id, wordCount int
|
|
|
|
|
title, body, snippet string
|
|
|
|
|
path, checksum string
|
|
|
|
|
created, modified time.Time
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
err := rows.Scan(&id, &path, &title, &body, &wordCount, &created, &modified, &checksum, &snippet)
|
|
|
|
|
if err != nil {
|
|
|
|
|
d.logger.Err(err)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(note.Match{
|
|
|
|
|
Snippet: snippet,
|
|
|
|
|
Metadata: note.Metadata{
|
|
|
|
|
Path: path,
|
|
|
|
|
Title: title,
|
|
|
|
|
Body: body,
|
|
|
|
|
WordCount: wordCount,
|
|
|
|
|
Created: created,
|
|
|
|
|
Modified: modified,
|
|
|
|
|
Checksum: checksum,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return count, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func dateField(filter note.DateFilter) string {
|
|
|
|
|