From: Maciej Pasternacki term&
(term-item-ids term) function (term-items term) function (term-taxonomy term) function (term-synonyms term) function (term-taxonomy term) function TERM-TAXONOMY-NAMEClass init args: :text :taxonomy-name :description
IDs of items associated with given TERM.
Items associated with given TERM.
Items associated with given TERM.
Return list of terms synonymous with TERM.
+
+Two terms are synonymous when they are in the same taxonomy and differ
+only in case. More special cases for synonymity may be introduced
+later.
+
+TERM is always included in the returned list, and it is a first item.
+
+TERM may be also a list, whose first element is taxonomy object or
+name, and second element is term name. This is a case of premature
+optimization.
TERM's taxonomy object
TERM-TEXT
undocumented(term-value item term) function
diff --git a/src/taxonomy.lisp b/src/taxonomy.lisp index 5cd8204..644d6b7 100644 --- a/src/taxonomy.lisp +++ b/src/taxonomy.lisp @@ -15,7 +15,7 @@ #:cl-store-valued-taxonomy #:deftaxonomy #:ensure-taxonomy #:ensure-term #:term #:term-text #:slug #:term-taxonomy-name - #:description #:term-taxonomy + #:description #:term-taxonomy #:term-synonyms #:id #:find-terms #:new-term #:apply-term #:term-value #:item-terms #:order-item-terms #:unbind-term :term-item-ids #:term-items @@ -275,6 +275,30 @@ creation." :slug slug)) 'term-text)))) +(defun term-synonyms (term) + "Return list of terms synonymous with TERM. + +Two terms are synonymous when they are in the same taxonomy and differ +only in case. More special cases for synonymity may be introduced +later. + +TERM is always included in the returned list, and it is a first item. + +TERM may be also a list, whose first element is taxonomy object or +name, and second element is term name. This is a case of premature +optimization." + (query-dao 'term + (sql (:select '* :from 'term + :where (:and (:= 'term-taxonomy + (taxonomy-slug + (etypecase term + (term (term-taxonomy term)) + (list (first term))))) + (:= (:lower 'term-text) + (:lower (etypecase term + (term (term-text term)) + (list (string (second term))))))))))) + (defun apply-term (item term &key value order) "Apply TERM to ITEM, optionally setting its value to VALUE." (query (:insert-into 'item-term :set