Simple database: Difference between revisions
Content added Content deleted
m (→{{header|Common Lisp}}: small improvements: prompt more and better defaults for make-episode, improve output formatting) |
(→{{header|Common Lisp}}: add search function, search title and tags, list all tags) |
||
Line 429: | Line 429: | ||
(compare-by-date (car (series-episodes (get-value series1 *db*))) |
(compare-by-date (car (series-episodes (get-value series1 *db*))) |
||
(car (series-episodes (get-value series2 *db*)))))))) |
(car (series-episodes (get-value series2 *db*)))))))) |
||
(defun match-title (term episode) |
|||
(when (and episode (equal (format nil "~{~a~^ ~}" term) (episode-title episode))) |
|||
episode)) |
|||
(defun search-all (term database) |
|||
(let ((exact-results '()) |
|||
(fuzzy-results '()) |
|||
(tag-results '())) |
|||
(mapcar #'(lambda (episode) |
|||
(cond ((match-title term episode) |
|||
(push episode exact-results)))) |
|||
(get-all database)) |
|||
exact-results)) |
|||
(defun watch-search (term) |
|||
(format t "~{~& ~a~%~}" (sort (search-all term *db*) #'compare-by-date))) |
|||
(defun list-all-tags (database) |
|||
(let ((tags (make-hash-table :test 'equal))) |
|||
(mapcar #'(lambda (tag) (setf (gethash tag tags) (1+ (or (gethash tag tags) 0)))) |
|||
(apply #'append (mapcar #'episode-tags (get-all database)))) |
|||
tags)) |
|||
(defun watch-tags () |
|||
(maphash #'(lambda (tag count) (format t "~a (~d) " tag count)) |
|||
(list-all-tags *db*)) |
|||
(terpri)) |
|||
(defun watch-load (dbfile) |
(defun watch-load (dbfile) |
||
Line 453: | Line 481: | ||
((equal (cadr argv) "series") (watch-series-names)) |
((equal (cadr argv) "series") (watch-series-names)) |
||
((equal (cadr argv) "all") (watch-all)) |
((equal (cadr argv) "all") (watch-all)) |
||
((equal (cadr argv) "tags") (watch-tags)) |
|||
((equal (cadr argv) "search") (watch-search (cddr argv))) |
|||
(T (watch-series (format nil "~{~a~^ ~}" (cdr argv))))))) |
(T (watch-series (format nil "~{~a~^ ~}" (cdr argv))))))) |
||