Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
57889804
Unverified
Commit
57889804
authored
4 years ago
by
Tim Macdonald
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Abbreviate search context (#15028)
parent
c20e9b11
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/search/config.clj
+4
-0
4 additions, 0 deletions
src/metabase/search/config.clj
src/metabase/search/scoring.clj
+17
-4
17 additions, 4 deletions
src/metabase/search/scoring.clj
test/metabase/search/scoring_test.clj
+15
-1
15 additions, 1 deletion
test/metabase/search/scoring_test.clj
with
36 additions
and
5 deletions
src/metabase/search/config.clj
+
4
−
0
View file @
57889804
...
...
@@ -23,6 +23,10 @@
"Results in more dashboards than this are all considered to be equally popular."
50
)
(
def
^
:const
surrounding-match-context
"Show this many words of context before/after matches in long search results"
2
)
(
def
searchable-models
"Models that can be searched. The order of this list also influences the order of the results: items earlier in the
list will be ranked higher."
...
...
This diff is collapsed.
Click to expand it.
src/metabase/search/scoring.clj
+
17
−
4
View file @
57889804
...
...
@@ -62,6 +62,18 @@
(
count
search-tokens
)))
fs
))
(
defn-
tokens->string
[
tokens
abbreviate?
]
(
let
[
->string
(
partial
str/join
" "
)
context
search-config/surrounding-match-context
]
(
if
(
or
(
not
abbreviate?
)
(
<=
(
count
tokens
)
(
*
2
context
)))
(
->string
tokens
)
(
str
(
->string
(
take
context
tokens
))
"…"
(
->string
(
take-last
context
tokens
))))))
(
defn-
match-context
"Breaks the matched-text into match/no-match chunks and returns a seq of them in order. Each chunk is a map with keys
`is_match` (true/false) and `text`"
...
...
@@ -71,10 +83,11 @@
{
:text
match-token
:is_match
(
boolean
(
some
#
(
matches?
%
match-token
)
query-tokens
))}))
(
partition-by
:is_match
)
(
map
(
fn
[
matches-or-misses-map
]
{
:is_match
(
:is_match
(
first
matches-or-misses-map
))
:text
(
str/join
" "
(
map
:text
matches-or-misses-map
))}))))
(
map
(
fn
[
matches-or-misses-maps
]
(
let
[
is-match
(
:is_match
(
first
matches-or-misses-maps
))
text-tokens
(
map
:text
matches-or-misses-maps
)]
{
:is_match
is-match
:text
(
tokens->string
text-tokens
(
not
is-match
))})))))
(
def
^
:const
text-score-max
"The maximum text score that could be achieved without normalization. This value is then used to normalize it down to the interval [0, 1]"
...
...
This diff is collapsed.
Click to expand it.
test/metabase/search/scoring_test.clj
+
15
−
1
View file @
57889804
...
...
@@ -129,6 +129,7 @@
(
deftest
match-context-test
(
let
[
context
#
'search/match-context
tokens
(
partial
map
str
)
match
(
fn
[
text
]
{
:text
text
:is_match
true
})
no-match
(
fn
[
text
]
{
:text
text
:is_match
false
})]
(
testing
"it groups matches together"
...
...
@@ -145,7 +146,20 @@
(
is
(
=
[(
no-match
"aviary stats"
)]
(
context
[
"rasta"
"toucan"
]
[
"aviary"
"stats"
]))))))
[
"aviary"
"stats"
]))))
(
testing
"it abbreviates when necessary"
(
is
(
=
[(
no-match
"one two…eleven twelve"
)
(
match
"rasta toucan"
)
(
no-match
"alpha beta…the end"
)]
(
context
(
tokens
'
(
rasta
toucan
))
(
tokens
'
(
one
two
this
should
not
be
included
eleven
twelve
rasta
toucan
alpha
beta
some
other
noise
the
end
))))))))
(
deftest
test-largest-common-subseq-length
(
let
[
subseq-length
(
partial
#
'search/largest-common-subseq-length
=
)]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment