Skip to content

Commit

Permalink
Conveniently fallback to using en-US if no match for locale
Browse files Browse the repository at this point in the history
Hermes tries to make it easy by building a cache of preferred descriptions for search and autocompletion. This isn't necessary, but helpful. It usually uses the default locale to choose, but we can now define the locale to use at time of index creation. However, if we do not have a map from locale to a set of language reference sets for a specific locale, this now falls back to using en-US rather than failing with what might appear to be a weird exception.
  • Loading branch information
wardle committed Oct 30, 2021
1 parent ca2b142 commit 676f3d8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/com/eldrix/hermes/impl/search.clj
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,19 @@
(let [ch (async/chan 1 (partition-all 1000))] ;; chunk concepts into batches
(with-open [store (store/open-store store-filename)
writer (open-index-writer search-filename)]
(let [langs (lang/match store language-priority-list)]
(when-not (seq langs) (throw (ex-info "No language refset for any locale listed in priority list"
(let [langs (lang/match store language-priority-list)
langs' (if (seq langs) langs
(do (log/warn "No language refset for any locale in requested priority list" {:priority-list language-priority-list :store-filename store-filename})
(log/warn "Falling back to default of 'en-US'")
(lang/match store "en-US")))]
(when-not (seq langs') (throw (ex-info "No language refset for any locale listed in priority list"
{:priority-list language-priority-list :store-filename store-filename})))
(store/stream-all-concepts store ch) ;; start streaming all concepts
(async/<!! ;; block until pipeline complete
(async/pipeline ;; pipeline for side-effects
(.availableProcessors (Runtime/getRuntime)) ;; Parallelism factor
(doto (async/chan) (async/close!)) ;; Output channel - /dev/null
(map (partial write-batch! store writer langs))
(map (partial write-batch! store writer langs'))
ch))
(.forceMerge writer 1)))))

Expand Down

0 comments on commit 676f3d8

Please sign in to comment.