Skip to content

Commit

Permalink
Gjør klar for å dele søk i index (backend) og søk (frontend)
Browse files Browse the repository at this point in the history
Co-authored-by: Magnar Sveen <magnar.sveen@mattilsynet.no>
  • Loading branch information
cjohansen and magnars committed Oct 12, 2023
1 parent efe8d5c commit b2b20fe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dev/matvaretabellen/dev.clj
Expand Up @@ -8,7 +8,7 @@
[integrant.repl.state]
[matvaretabellen.core :as matvaretabellen]
[matvaretabellen.foodcase-import :as foodcase-import]
[matvaretabellen.search :as search]
[matvaretabellen.search-index :as index]
[powerpack.app :as app]))

(def config (-> (config/from-file "./config/local-config.edn")
Expand Down Expand Up @@ -37,7 +37,7 @@
(d/db conn)))


(search/index-foods {} (d/db conn) :en)
(index/index-foods {} (d/db conn) :en)

(seq (d/datoms (d/db (:datomic/conn integrant.repl.state/system))
:avet :page/uri))
Expand Down
4 changes: 2 additions & 2 deletions src/matvaretabellen/pages.clj
@@ -1,6 +1,6 @@
(ns matvaretabellen.pages
(:require [clojure.data.json :as json]
[matvaretabellen.search :as search]
[matvaretabellen.search-index :as index]
[mt-designsystem.components.search-input :refer [SearchInput]]
[mt-designsystem.components.site-header :refer [SiteHeader]]
[powerpack.html :as html]))
Expand All @@ -21,7 +21,7 @@

(defn render-foods-index [db page]
{:content-type "application/json"
:body (json/write-str (search/index-foods {} db (:page/locale page)))})
:body (json/write-str (index/build-index db (:page/locale page)))})

(defn render-frontpage [context db page]
(html/render-hiccup
Expand Down
@@ -1,4 +1,4 @@
(ns matvaretabellen.search
(ns matvaretabellen.search-index
"This is a way too short and over-simplified implementation of some concepts
loosely borrowed from Elastic Search. It works on an in-memory index
represented by a map, and may be suitable to power searches in client-side
Expand Down Expand Up @@ -193,6 +193,10 @@
db)
(map #(d/entity db %))))))

(defn build-index [db locale]
{:index (index-foods nil db locale)
:stop-words (stop-words locale)})

(comment

(index-document {} (create-schema :nb) "lol" {:food/name {:nb "Vitamin D12"}})
Expand Down

0 comments on commit b2b20fe

Please sign in to comment.