Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Anything Llm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
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
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
mirrored_repos
MachineLearning
Mintplex Labs
Anything Llm
Commits
fce0d8b7
Unverified
Commit
fce0d8b7
authored
7 months ago
by
Sean Hatfield
Committed by
GitHub
7 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve search of document picker (#2097)
improve search of document picker
parent
26959563
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/components/Modals/ManageWorkspace/Documents/Directory/utils.js
+20
-7
20 additions, 7 deletions
...nents/Modals/ManageWorkspace/Documents/Directory/utils.js
with
20 additions
and
7 deletions
frontend/src/components/Modals/ManageWorkspace/Documents/Directory/utils.js
+
20
−
7
View file @
fce0d8b7
import
strDistance
from
"
js-levenshtein
"
;
import
strDistance
from
"
js-levenshtein
"
;
const
LEVENSHTEIN_MIN
=
8
;
const
LEVENSHTEIN_MIN
=
2
;
// Regular expression pattern to match the v4 UUID and the ending .json
// Regular expression pattern to match the v4 UUID and the ending .json
const
uuidPattern
=
const
uuidPattern
=
...
@@ -18,20 +18,33 @@ export const stripUuidAndJsonFromString = (input = "") => {
...
@@ -18,20 +18,33 @@ export const stripUuidAndJsonFromString = (input = "") => {
export
function
filterFileSearchResults
(
files
=
[],
searchTerm
=
""
)
{
export
function
filterFileSearchResults
(
files
=
[],
searchTerm
=
""
)
{
if
(
!
searchTerm
)
return
files
?.
items
||
[];
if
(
!
searchTerm
)
return
files
?.
items
||
[];
const
normalizedSearchTerm
=
searchTerm
.
toLowerCase
().
trim
();
const
searchResult
=
[];
const
searchResult
=
[];
for
(
const
folder
of
files
?.
items
)
{
for
(
const
folder
of
files
?.
items
)
{
// If folder is a good match then add all its children
const
folderNameNormalized
=
folder
.
name
.
toLowerCase
();
if
(
strDistance
(
folder
.
name
,
searchTerm
)
<=
LEVENSHTEIN_MIN
)
{
// Check for exact match first, then fuzzy match
if
(
folderNameNormalized
.
includes
(
normalizedSearchTerm
))
{
searchResult
.
push
(
folder
);
searchResult
.
push
(
folder
);
continue
;
continue
;
}
}
//
Otherwise c
heck children for
good result
s
//
C
heck children for
matche
s
const
fileSearchResults
=
[];
const
fileSearchResults
=
[];
for
(
const
file
of
folder
?.
items
)
{
for
(
const
file
of
folder
?.
items
)
{
if
(
const
fileNameNormalized
=
stripUuidAndJsonFromString
(
strDistance
(
stripUuidAndJsonFromString
(
file
.
name
),
searchTerm
)
<=
file
.
name
LEVENSHTEIN_MIN
).
toLowerCase
();
// Exact match check
if
(
fileNameNormalized
.
includes
(
normalizedSearchTerm
))
{
fileSearchResults
.
push
(
file
);
}
// Fuzzy match only if no exact matches found
else
if
(
fileSearchResults
.
length
===
0
&&
strDistance
(
fileNameNormalized
,
normalizedSearchTerm
)
<=
LEVENSHTEIN_MIN
)
{
)
{
fileSearchResults
.
push
(
file
);
fileSearchResults
.
push
(
file
);
}
}
...
...
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