Skip to content
Snippets Groups Projects
Unverified Commit 09ee5aa2 authored by Chris Truter's avatar Chris Truter Committed by GitHub
Browse files

Prefer search results with higher view counts (#49842)

parent 7d6d8896
No related branches found
No related tags found
No related merge requests found
...@@ -1024,6 +1024,7 @@ ...@@ -1024,6 +1024,7 @@
:last-editor-id :r.user_id :last-editor-id :r.user_id
:pinned [:> [:coalesce :collection_position [:inline 0]] [:inline 0]] :pinned [:> [:coalesce :collection_position [:inline 0]] [:inline 0]]
:verified [:= "verified" :mr.status] :verified [:= "verified" :mr.status]
:view-count true
:created-at true :created-at true
:updated-at true} :updated-at true}
:search-terms [:name :description] :search-terms [:name :description]
......
...@@ -674,6 +674,7 @@ ...@@ -674,6 +674,7 @@
:last-edited-at :r.timestamp :last-edited-at :r.timestamp
:pinned [:> [:coalesce :collection_position [:inline 0]] [:inline 0]] :pinned [:> [:coalesce :collection_position [:inline 0]] [:inline 0]]
:table-id false :table-id false
:view-count true
:created-at true :created-at true
:updated-at true} :updated-at true}
:search-terms [:name :description] :search-terms [:name :description]
......
...@@ -309,6 +309,7 @@ ...@@ -309,6 +309,7 @@
;; legacy search uses :active for this, but then has a rule to only ever show active tables ;; legacy search uses :active for this, but then has a rule to only ever show active tables
;; so we moved that to the where clause ;; so we moved that to the where clause
:archived false :archived false
:view-count true
:created-at true :created-at true
:updated-at true} :updated-at true}
:search-terms [:name :description :display_name] :search-terms [:name :description :display_name]
......
...@@ -39,6 +39,10 @@ ...@@ -39,6 +39,10 @@
"Results in more dashboards than this are all considered to be equally popular." "Results in more dashboards than this are all considered to be equally popular."
10) 10)
(def ^:const view-count-scaling
"The larger this value, the longer it will take for the score to approach 1.0. It will never quite reach it."
50)
(def ^:const surrounding-match-context (def ^:const surrounding-match-context
"Show this many words of context before/after matches in long search results" "Show this many words of context before/after matches in long search results"
2) 2)
...@@ -77,15 +81,15 @@ ...@@ -77,15 +81,15 @@
(def weights (def weights
"Strength of the various scorers. Copied from metabase.search.in-place.scoring, but allowing divergence." "Strength of the various scorers. Copied from metabase.search.in-place.scoring, but allowing divergence."
{:pinned 2 ;; simple field {:pinned 2
:bookmarked 2 ;; join with multi-table entity :bookmarked 2
:recency 1.5 ;; date formula :recency 1.5
:dashboard 1 ;; simple field :dashboard 1
:model 0.5 ;; simple field :model 0.5
:official-collection 2 ;; a field we can calculate :official-collection 2
:verified 2 ;; a simple field :verified 2
:text 10 ;; strength of text-scores-weight previously :view-count 2
}) :text 10})
(defn model->alias (defn model->alias
"Given a model string returns the model alias" "Given a model string returns the model alias"
......
...@@ -72,6 +72,8 @@ ...@@ -72,6 +72,8 @@
(OffsetDateTime/parse s))) (OffsetDateTime/parse s)))
(defn- rehydrate [index-row] (defn- rehydrate [index-row]
;; Useful for debugging scoring
#_ (dissoc index-row :legacy_input :created_at :updated_at :last_edited_at)
(-> (merge (-> (merge
(json/parse-string (:legacy_input index-row) keyword) (json/parse-string (:legacy_input index-row) keyword)
(select-keys index-row [:total_score :pinned])) (select-keys index-row [:total_score :pinned]))
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
[:model_rank :int :not-null] [:model_rank :int :not-null]
[:pinned :boolean] [:pinned :boolean]
[:verified :boolean] [:verified :boolean]
[:view_count :int]
;; permission related entities ;; permission related entities
[:collection_id :int] [:collection_id :int]
[:database_id :int] [:database_id :int]
......
...@@ -15,6 +15,14 @@ ...@@ -15,6 +15,14 @@
[column ceiling] [column ceiling]
[:least [:/ [:coalesce column [:inline 0]] [:inline (double ceiling)]] [:inline 1]]) [:least [:/ [:coalesce column [:inline 0]] [:inline (double ceiling)]] [:inline 1]])
(defn- atan-size
"Prefer items whose value is larger, with diminishing gains."
[column scaling]
;; 2/PI * tan^-1 (x/N)
[:*
[:/ [:inline 2] [:pi]]
[:atan [:/ [:cast [:coalesce column [:inline 0.0]] :float] [:inline scaling]]]])
(defn- inverse-duration (defn- inverse-duration
"Score at item based on the duration between two dates, where less is better." "Score at item based on the duration between two dates, where less is better."
[from-column to-column ceiling-in-days] [from-column to-column ceiling-in-days]
...@@ -67,6 +75,7 @@ ...@@ -67,6 +75,7 @@
(def ^:private scorers (def ^:private scorers
{:text [:ts_rank :search_vector :query [:inline ts-rank-normalization]] {:text [:ts_rank :search_vector :query [:inline ts-rank-normalization]]
:view-count (atan-size :view_count search.config/view-count-scaling)
:pinned (truthy :pinned) :pinned (truthy :pinned)
:bookmarked bookmark-score-expr :bookmarked bookmark-score-expr
:recency (inverse-duration :model_updated_at [:now] search.config/stale-time-in-days) :recency (inverse-duration :model_updated_at [:now] search.config/stale-time-in-days)
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
:last-editor-id :last-editor-id
:pinned :pinned
:verified :verified
:view-count
:updated-at]) :updated-at])
(def ^:private default-attrs (def ^:private default-attrs
......
...@@ -70,6 +70,7 @@ ...@@ -70,6 +70,7 @@
:name :name
:query_type :query_type
:type :type
:view_count
:created_at :created_at
:updated_at}, :updated_at},
:where [:= :updated.id :this.id]}}, :where [:= :updated.id :this.id]}},
...@@ -99,7 +100,7 @@ ...@@ -99,7 +100,7 @@
{:search-model "table", {:search-model "table",
:fields :fields
#{:active :description :schema :name :id :db_id :initial_sync_status :display_name #{:active :description :schema :name :id :db_id :initial_sync_status :display_name
:visibility_type :created_at :updated_at} :visibility_type :view_count :created_at :updated_at}
:where [:= :updated.id :this.id]}}, :where [:= :updated.id :this.id]}},
:Database #{{:search-model "table", :fields #{:name}, :where [:= :updated.id :this.db_id]}} :Database #{{:search-model "table", :fields #{:name}, :where [:= :updated.id :this.db_id]}}
:Segment #{{:search-model "segment" :Segment #{{:search-model "segment"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment