(define (find-note tags words) ;; INPUTS: '(tags) (with-output-to-string (lambda () (write "SELECT distinct n.id, n.title FROM notes n LEFT JOIN notes_tags nt ON nt.note_id = n.id LEFT JOIN tags t ON nt.tag_id = t.id JOIN fulltext ft ON ft.docid = n.id WHERE 1=1") (when (not (equal? "" tags)) (write (string-append "AND t.name in (" tags ")\n"))) (when (not (equal? "" words)) (write (string-append "AND ft.fulltext MATCH '" words "'\n"))) (write ";"))))