The interface encapsulating the various search engine backends.

(ns metabase.search.engine)

Does this instance support the given engine?

(defmulti supported-engine?
  identity)
(defmethod supported-engine? :default [engine]
  (throw (ex-info (format "Unknown search engine: %s" engine)
                  {:engine engine})))

Return a reducible of the search result matching a given query.

(defmulti results
  :search-engine)

Return a set of the models which have at least one result for the given query.

(defmulti model-set
  :search-engine)

For legacy search: perform the in-memory ranking

(defmulti score 
  (fn [{engine :search-engine} _]
    engine))
(defmethod score :default [_search-ctx result]
  {:result (dissoc result :score)
   :score  (:score result)})

Updates the search index by consuming the documents from the given reducible.

(defmulti consume!
  (fn [search-engine _document-reducible]
    search-engine))

Ensure that the search index exists, an is ready to take search queries.

(defmulti init!
  (fn [engine _opts]
    engine))

Perform a full refresh of the given engine's index.

(defmulti reindex!
  (fn [engine _opts] engine))

Stop tracking the current indexes. Used when resetting the appdb.

(defmulti reset-tracking!
  (fn [engine] engine))

List the search engines that are supported. Does not mention the legacy in-place engine.

(defn active-engines
  []
  (for [[k p] (dissoc (methods supported-engine?) :default :search.engine/in-place) :when (p k)] k))

Is the given engine recognized?

(defn known-engine?
  [engine]
  (let [registered? #(contains? (methods supported-engine?) %)]
    (some registered? (cons engine (ancestors engine)))))