Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F132028
sorter.rs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
956 B
Referenced Files
None
Subscribers
None
sorter.rs
View Options
use
super
::
matcher
;
use
rayon
::
prelude
::
*
;
pub
struct
Match
{
pub
score
:
i64
,
pub
content
:
String
,
}
pub
struct
Options
{
pub
pattern
:
String
,
pub
minimum_score
:
i64
,
}
impl
Options
{
pub
fn
new
(
pattern
:
String
)
->
Self
{
Self
{
pattern
,
minimum_score
:
25
,
}
}
}
pub
fn
sort_strings
(
options
:
Options
,
strings
:
Vec
<
String
>
)
->
Vec
<
Match
>
{
let
matcher
=
matcher
::
Matcher
::
new
(
options
.
pattern
);
let
mut
matches
=
strings
.
into_par_iter
()
.
filter_map
(
|
candidate
|
{
let
score
=
matcher
.
score
(
candidate
.
as_str
());
if
score
<
options
.
minimum_score
{
None
}
else
{
Some
(
Match
{
score
,
content
:
candidate
,
})
}
})
.
collect
::
<
Vec
<
Match
>>
();
matches
.
par_sort_unstable_by
(
|
a
,
b
|
a
.
score
.
cmp
(
&
b
.
score
));
matches
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Apr 6 2026, 6:55 PM (5 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
10573
Default Alt Text
sorter.rs (956 B)
Attached To
Mode
R1 ivy.nvim
Attached
Detach File
Event Timeline
Log In to Comment