Skip to content

Instantly share code, notes, and snippets.

@jvia
Last active February 4, 2020 16:52
Show Gist options
  • Save jvia/61f8564718ade6980a4167c62fb5f8d8 to your computer and use it in GitHub Desktop.
Save jvia/61f8564718ade6980a4167c62fb5f8d8 to your computer and use it in GitHub Desktop.
{vase/plugins [com.nytimes.vase.elasticsearch]
vase/service (fern/lit vase/service
{:apis [@tmdb/api]
:service-map
{:io.pedestal.http/resource-path "/public"
:io.pedestal.http/port 8080
:io.pedestal.http/secure-headers {:content-security-policy-settings
{:object-src "none"}}}})
tmdb/api (fern/lit vase/api {:path "/"
:on-startup [@elasticsearch @create-index]
:on-request [@elasticsearch
io.pedestal.http/json-body]
:routes #{["/index/:id" :put [@tmdb/index]]
["/search" :get [@tmdb.v1/search]]}})
elasticsearch (fern/lit vase.elasticsearch/connect {:hosts ["http://localhost:9200"]})
create-index (fern/lit vase.elasticsearch/create {:name "tmdb" :settings "dev/settings.json"})
tmdb/index (fern/lit vase.elasticsearch/request
{:params [id]
:url [:tmdb :_doc id]
:method :put})
tmdb.v1/search (fern/lit vase.elasticsearch/request
{:params [q dbg]
:url [:tmdb :_search]
:method :get
:body {:_source [:title :release_date]
:explain (or dbg false)
:query (let [q (or q "")]
{:bool
{:should
[;; SHOULD have all the user’s query terms match somewhere in the document
{:multi_match {:query q
:fields ["overview"
"title"
"directors.name"
"cast.name"]
:type :cross_fields}}
;; SHOULD have full query exactly matching the title
{:match_phrase {"title_exact_match" {:query (str "|" q "|")}}}
;; SHOULD have part of the query match a director’s or cast member’s full name
{:multi_match
{:query q
:fields ["directors.name.bigrammed"
"cast.name.bigrammed"]}}
;; SHOULD have full query, exactly matching a director’s or cast member’s full name, scored by popularity and recency
{:function_score
{:query {:match_phrase {"names_exact_match" (str "|" q "|")}}
:functions
[{:field_value_factor {:field "vote_average" :modifier "sqrt"}}
{:gauss {"release_date" {:origin "now" :scale "5500d" :decay 0.5}}}]}}]}})}})}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment