Simple database: Difference between revisions

m
→‎{{header|Common Lisp}}: improve search, add match by words, search tags
(→‎{{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:
 
(defun match-title (term episode)
(when (and episode (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)
Line 440 ⟶ 452:
(mapcar #'(lambda (episode)
(cond ((match-title term episode)
(push episode exact-results))))
((fuzzy-title term episode)
(push episode fuzzy-results))
((match-tags term episode)
(push episode tag-results))))
(get-all database))
(append (sort exact-results #'compare-by-date))
(sort tag-results #'compare-by-date)
(sort fuzzy-results #'compare-by-date))))
 
(defun watch-search (term)
(format t "~{~& ~a~%~}" (sort (search-all term *db*) #'compare-by-date)))
 
(defun list-all-tags (database)
Anonymous user