Skip to content

Commit

Permalink
Use SearchResult component
Browse files Browse the repository at this point in the history
Still needs to add `context`

[Fixes #14832]

[ci skip]
  • Loading branch information
tsmacdonald committed Feb 16, 2021
1 parent 7ec9672 commit 68b1ffa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
19 changes: 2 additions & 17 deletions frontend/src/metabase/home/containers/SearchApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Database from "metabase/entities/databases";

import Card from "metabase/components/Card";
import EmptyState from "metabase/components/EmptyState";
import EntityItem from "metabase/components/EntityItem";
import SearchResult from "metabase/search/components/SearchResult";
import Subhead from "metabase/components/type/Subhead";
import { FILTERS } from "metabase/collections/components/ItemTypeFilterBar";

Expand Down Expand Up @@ -180,22 +180,7 @@ const SearchResultSection = ({ title, items }) => (
break;
}

return (
<Link
to={item.getUrl()}
key={item.id}
data-metabase-event={`Search Results;Item Click;${item.model}`}
>
<EntityItem
variant="list"
name={item.getName()}
iconName={item.getIcon()}
iconColor={item.getColor()}
item={item}
extraInfo={extraInfo}
/>
</Link>
);
return <SearchResult result={item} />;
})}
</Card>
);
20 changes: 14 additions & 6 deletions src/metabase/search/scoring.clj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@
[[score-1 _result-1] [score-2 _result-2]]
(compare score-1 score-2))

(defn- serialize
"Massage the raw result from the DB into something more useful for the client"
[{:keys [collection_id collection_name] :as row} {:keys [score match column] :as hit}]
(-> row
(assoc
:matched_column column
:matched_text match
:score score
:collection {:id collection_id :name collection_name})))

(defn accumulate-top-results
"Accumulator that saves the top n (defined by `search-config/max-filtered-results`) sent to it"
([] (PriorityQueue. search-config/max-filtered-results compare-score-and-result))
Expand All @@ -140,11 +150,9 @@
"Returns a pair of [score, result] or nil. The score is a vector of comparable things in priority order. The result
has `:matched_column` and `matched_text` injected in"
[query-string result]
(let [{:keys [score column match] :as hit} (score-with-match query-string result)]
(let [hit (score-with-match query-string result)]
(and hit
[[(- score)
[[(- (:score hit))
(model->sort-position (:model result))
(:name result)]
(assoc result
:matched_column column
:matched_text match)])))
(:name result)],
(serialize result hit)])))

0 comments on commit 68b1ffa

Please sign in to comment.