Simple database: Difference between revisions
Content added Content deleted
(→{{header|Common Lisp}}: add search function, search title and tags, list all tags) |
m (→{{header|Common Lisp}}: improve search, add match by words, search tags) |
||
Line 431: | Line 431: | ||
(defun match-title (term episode) |
(defun match-title (term episode) |
||
(when ( |
(when (string-equal (format nil "~{~a~^ ~}" term) (episode-title episode)) |
||
episode)) |
|||
(defun fuzzy-title (term episode) |
|||
(when (set-difference |
|||
(mapcar #'(lambda (word) |
|||
(search word (episode-title episode) :test 'string-equal)) |
|||
term) |
|||
'(NIL)) |
|||
episode)) |
|||
(defun match-tags (term episode) |
|||
(when (intersection (mapcar #'intern term) (episode-tags episode)) |
|||
episode)) |
|||
(defun search-all (term database) |
(defun search-all (term database) |
||
Line 440: | Line 452: | ||
(mapcar #'(lambda (episode) |
(mapcar #'(lambda (episode) |
||
(cond ((match-title term episode) |
(cond ((match-title term episode) |
||
(push episode exact-results |
(push episode exact-results)) |
||
((fuzzy-title term episode) |
|||
(push episode fuzzy-results)) |
|||
((match-tags term episode) |
|||
(push episode tag-results)))) |
|||
(get-all database)) |
(get-all database)) |
||
exact-results) |
(append (sort exact-results #'compare-by-date) |
||
(sort tag-results #'compare-by-date) |
|||
(sort fuzzy-results #'compare-by-date)))) |
|||
(defun watch-search (term) |
(defun watch-search (term) |
||
(format t "~{~& ~a~%~}" |
(format t "~{~& ~a~%~}" (search-all term *db*))) |
||
(defun list-all-tags (database) |
(defun list-all-tags (database) |