diff --git a/src/fediverse-post-local-search.lisp b/src/fediverse-post-local-search.lisp index 71bac7f..a7818b9 100644 --- a/src/fediverse-post-local-search.lisp +++ b/src/fediverse-post-local-search.lisp @@ -54,10 +54,6 @@ "folder") (:function (lambda (a) (db::quote-symbol a)))) -(defrule fedisearch-column-value (and #\" (+ (not #\")) #\") - (:text t)) - - (defrule fedisearch-column-value (and #\" (+ (not #\")) #\") (:text t)) diff --git a/src/gempub.lisp b/src/gempub.lisp index 846bcb2..8bd70c9 100644 --- a/src/gempub.lisp +++ b/src/gempub.lisp @@ -16,51 +16,52 @@ (in-package :gempub) -(defrule title "title" (:constant :title)) -(defrule gpubVersion "gpubVersion" (:constant :gpubVersion)) -(defrule index "index" (:constant :index)) -(defrule author "author" (:constant :author)) -(defrule language "language" (:constant :language)) -(defrule charset "charset" (:constant :charset)) -(defrule description "description" (:constant :description)) -(defrule published "published" (:constant :published)) -(defrule publishDate "publishDate" (:constant :publishDate)) -(defrule revisionDate "revisionDate" (:constant :revisionDate)) -(defrule copyright "copyright" (:constant :copyright)) -(defrule license "license" (:constant :license)) -(defrule version "version" (:constant :version)) -(defrule cover "cover" (:constant :cover)) +(defrule gempub-title "title" (:constant :title)) +(defrule gempub-gpubVersion "gpubVersion" (:constant :gpubVersion)) +(defrule gempub-index "index" (:constant :index)) +(defrule gempub-author "author" (:constant :author)) +(defrule gempub-language "language" (:constant :language)) +(defrule gempub-charset "charset" (:constant :charset)) +(defrule gempub-description "description" (:constant :description)) +(defrule gempub-published "published" (:constant :published)) +(defrule gempub-publishDate "publishDate" (:constant :publishDate)) +(defrule gempub-revisionDate "revisionDate" (:constant :revisionDate)) +(defrule gempub-copyright "copyright" (:constant :copyright)) +(defrule gempub-license "license" (:constant :license)) +(defrule gempub-version "version" (:constant :version)) +(defrule gempub-cover "cover" (:constant :cover)) -(defrule blank (or #\space #\Newline #\Tab) +(defrule gempub-blank (or #\space #\Newline #\Tab) (:constant nil)) -(defrule blanks (* blank) +(defrule gempub-blanks (* gempub-blank) (:constant nil)) -(defrule key-value-separator #\:) +(defrule gempub-key-value-separator #\:) -(defrule value (+ (not #\Newline)) +(defrule gempub-value (+ (not #\Newline)) (:text t)) -(defrule key (or title - gpubVersion - index - author - language - charset - description - published - publishDate - revisionDate - copyright - license - version - cover)) +(defrule gempub-key (or gempub-title + gempub-gpubVersion + gempub-index + gempub-author + gempub-language + gempub-charset + gempub-description + gempub-published + gempub-publishDate + gempub-revisionDate + gempub-copyright + gempub-license + gempub-version + gempub-cover)) -(defrule entry (and key (? blanks) key-value-separator (? blanks) value blanks) +(defrule gempub-entry (and gempub-key (? gempub-blanks) gempub-key-value-separator + (? gempub-blanks) gempub-value gempub-blanks) (:function (lambda (a) (list (first a) (fifth a))))) -(defrule metadata (* entry) +(defrule gempub-metadata (* gempub-entry) (:function flatten)) (defgeneric parse-metadata (object)) @@ -125,95 +126,96 @@ (loop for added in added-file do (ui:notify (format nil (_ "Added gempub ~s into the library") added)))))) -(defrule spaces (+ blank) +(defrule gempub-spaces (+ gempub-blank) (:constant nil)) -(defrule publish-date-alias "publishedDate" +(defrule gempub-publish-date-alias "publishedDate" (:constant "\"published-date\"")) -(defrule revision-date-alias "revisionDate" +(defrule gempub-revision-date-alias "revisionDate" (:constant "\"revision-date\"")) -(defrule column-alias (or publish-date-alias - revision-date-alias)) +(defrule gempub-column-alias (or gempub-publish-date-alias + gempub-revision-date-alias)) -(defrule column (or column-alias - "title" - "author" - "language" - "description" - "publish-date" - "revision-date" - "published" - "copyright") +(defrule gempub-column (or gempub-column-alias + "title" + "author" + "language" + "description" + "publish-date" + "revision-date" + "published" + "copyright") (:text t)) -(defrule column-value (and #\" (+ (not #\")) #\") +(defrule gempub-column-value (and #\" (+ (not #\")) #\") (:text t)) -(defrule term (or and-where - or-where - like - =-term - !=-term - <-term - >-term - <=-term - >=-term) +(defrule gempub-term (or gempub-and-where + gempub-or-where + gempub-like + gempub-=-term + gempub-!=-term + gempub-<-term + gempub->-term + gempub-<=-term + gempub->=-term) (:function (lambda (a) (join-with-strings a " ")))) -(defrule like (and column spaces "like" spaces column-value) +(defrule gempub-like (and gempub-column gempub-spaces "like" + gempub-spaces gempub-column-value) (:function (lambda (a) (format nil "~a like \"%~a%\"" (first a) (string-trim '(#\") (fifth a)))))) -(defrule =-term (and column spaces "=" spaces column-value) +(defrule gempub-=-term (and gempub-column gempub-spaces "=" gempub-spaces gempub-column-value) (:function (lambda (a) (format nil "~a = ~a" (first a) (fifth a))))) -(defrule <-term (and column spaces "<" spaces column-value) +(defrule gempub-<-term (and gempub-column gempub-spaces "<" gempub-spaces gempub-column-value) (:function (lambda (a) (format nil "~a < ~a" (first a) (fifth a))))) -(defrule >-term (and column spaces ">" spaces column-value) +(defrule gempub->-term (and gempub-column gempub-spaces ">" gempub-spaces gempub-column-value) (:function (lambda (a) (format nil "~a > ~a" (first a) (fifth a))))) -(defrule <=-term (and column spaces "<=" spaces column-value) +(defrule gempub-<=-term (and gempub-column gempub-spaces "<=" gempub-spaces gempub-column-value) (:function (lambda (a) (format nil "~a <= ~a" (first a) (fifth a))))) -(defrule >=-term (and column spaces ">=" spaces column-value) +(defrule gempub->=-term (and gempub-column gempub-spaces ">=" gempub-spaces gempub-column-value) (:function (lambda (a) (format nil "~a >= ~a" (first a) (fifth a))))) -(defrule !=-term (and column spaces "!=" spaces column-value) +(defrule gempub-!=-term (and gempub-column gempub-spaces "!=" gempub-spaces gempub-column-value) (:function (lambda (a) (format nil "~a != ~a" (first a) (fifth a))))) -(defrule and-where (and term spaces "and" spaces term)) +(defrule gempub-and-where (and gempub-term gempub-spaces "and" gempub-spaces gempub-term)) -(defrule or-where (and term spaces "or" spaces term)) +(defrule gempub-or-where (and gempub-term gempub-spaces "or" gempub-spaces gempub-term)) -(defrule where-clause (and "where" spaces (+ term)) +(defrule gempub-where-clause (and "where" gempub-spaces (+ gempub-term)) (:function (lambda (a) (strcat "where " (join-with-strings (third a) " "))))) (defun parse-search-gempub (query) (let* ((where-clause (when (string-not-empty-p query) - (parse 'where-clause query))) + (parse 'gempub-where-clause query))) (sql-query (if where-clause (strcat (format nil "select * from \"~a\" ~a"