X-Git-Url: https://git.hcoop.net/clinton/lisp-on-lines.git/blobdiff_plain/da26d00333fa0ced964dc777a00bd917c543e4ed..38a016c7ea89d37ea32cfeb8d1e30033c9e3d614:/src/lisp-on-lines.lisp diff --git a/src/lisp-on-lines.lisp b/src/lisp-on-lines.lisp index 7658722..8a9a88b 100644 --- a/src/lisp-on-lines.lisp +++ b/src/lisp-on-lines.lisp @@ -16,7 +16,7 @@ Generates a form that, when evaluated, initialises the given table as an lol obj This involves creating a meta-model, a clsql view-class, and the setting up the default attributes for a mewa presentation" `(progn - (def-view-class/table ,table) + (def-view-class-from-table ,table) (set-default-attributes (quote ,(meta-model::sql->sym table)))))) (defmacro initialize-lol-for-table (&rest tables) @@ -27,4 +27,46 @@ This involves creating a meta-model, a clsql view-class, and the setting up the (defmacro initialize-lol-for-database () "expands to init-i-f-t using the listing of tables provided by meta-model" - `(initialize-lol-for-table ,@(meta-model::list-tables))) \ No newline at end of file + `(initialize-lol-for-table ,@(meta-model::list-tables))) + +;;;; * AJAX stuff + +;;;; TODO: This search stuff should probably me refactored elsewhere + +(defmethod find-slots-of-type (model &key (type 'string) + (types '((string)) types-supplied-p)) + "returns a list of slots matching TYPE, or matching any of TYPES" + (let (ty) + (if types-supplied-p + (setf ty types) + (setf ty (list type))) + (remove nil (mapcar #'(lambda (st) (when (member (second st) ty) + (first st))) + (lisp-on-lines::list-slot-types model))))) + + +(defmethod word-search (class-name slots search-terms + &key (limit 10) (where (sql-and t))) + (select class-name + :where (sql-and + where + (word-search-where class-name slots search-terms :format-string "~a%")) + :flatp t + :limit limit)) + + +(defmethod word-search (class-name slots (s string) &rest args) + (apply #'word-search class-name slots + (split-sequence:split-sequence #\Space s) args)) + +(defmethod word-search-where (class-name slots search-terms &key (format-string "%~a%")) + (sql-or + (mapcar #'(lambda (term) + (apply #'sql-or + (mapcar #'(lambda (slot) + (sql-uplike + (sql-slot-value class-name slot) + (format nil format-string term))) + slots))) + search-terms))) +