Browse Source

implement 'repopuluate meilisearch DB' functionality (in search).

The main feature is the repopulate-database function which clears out the
Meilisearch DB index containing this site's searchable information and
repopulates it with the site's nera.db information.

I, also, added a delete-index function (also in search package) but that is
mostly a convenience feature. It allows me to quickly delete any index in the
Meilisearch DB which I made by mistake (E.G. wrong name, change of plan) and
remove old indexes from other projects which are no longer in use (on local
dev. machine mostly).
stable
Craig Oates 1 year ago
parent
commit
0596972877
  1. 37
      src/search.lisp

37
src/search.lisp

@ -1,6 +1,7 @@
(defpackage #:search
(:use #:cl
#:app-constants
#:archive
#:cl-json
#:local-time
#:utils)
@ -16,7 +17,9 @@
#:set-filter-attributes
#:delete-all-entries
#:create-dump
#:update-ranking-rules))
#:update-ranking-rules
#:repopulate-database
#:delete-index))
(in-package #:search)
;; Explains the "~{~A~^,~}" in the format call below.
@ -41,7 +44,6 @@ Note: The JSON object to encoded as a string."
("thumbnail-path" . ,thumbnail-path-value)
("year" . ,publish-year-value)
("month" . ,publish-month-value)
;; ("day" . ,(local-time:timestamp-day created-at-value))
("keywords" . ,(cl-ppcre:split "," keywords-value))))))
(defun build-search-url (path)
@ -52,6 +54,7 @@ site is running in and use the beta or prod. URL's to connect to meilisearch.
the base URL."
(if (ritherdon-archive.config:developmentp)
(concatenate 'string "http://localhost:7700" path)
(utils:build-url-root)
(concatenate 'string "https://www.nera.com" path)))
(defun delete-entry (id)
@ -145,3 +148,33 @@ database first (when no search term is entered by the user)."
(utils:run-bash-command
(format nil "curl -X PATCH \'~a\' -H \'Authorization: ~a\' -H \'Content-Type: application/json\' --data-binary \'[ \"words\", \"typo\", \"proximity\", \"attribute\", \"sort\", \"exactness\",\"rank:asc\", \"year:desc\" ]\'"
(build-search-url "/indexes/nera/settings") (meilisearch-api-key))))
(defun repopulate-database (archive-entries)
"Empties the Meilisearch database and populates it with `ARCHIVE-ENTRIES'."
(delete-all-entries)
(loop for entry in archive-entries
do
(submit-entry
(build-payload (archive::search-id-of entry)
(archive::title-of entry)
(format nil "view/archive/~a"
(archive::slug-of entry))
(format nil "storage/thumb/archive/~a"
(archive::slug-of entry))
(archive::month-of entry)
(archive::year-of entry)
(archive::keywords-of entry)))))
(defun delete-index (index-name)
"Deletes `INDEX-NAME' in Meilisearch DB, doesn't need to be this project.
Because Meilisearch is a seperate service running alongside this website, it can
host searchable databases for other projects on the system. `INDEX-NAME' refers
to those other databases.
I have not hard-coded this project's database name into this function out of
convenience. I can call this function from SLIME/SLY and clean-up my Meilisearch
dev. instance. It, also, helps if I've made botched this project's DB with an
incorrect name and need to quickly delete it."
(utils:run-bash-command
(format nil "curl -X DELETE \'~a\'"
(build-search-url (format nil "/indexes/~a" index-name)))))

Loading…
Cancel
Save