Rust_Search
v2.1.0
用 Rust 构建的极快的文件搜索箱
请在此处报告您在使用 Rust 搜索时遇到的任何问题:问题
在 Cargo.toml 中添加rust_search = "2.0.0"
。
[ dependencies ]
rust_search = " 2.0.0 "
use rust_search :: SearchBuilder ;
fn main ( ) {
let search : Vec < String > = SearchBuilder :: default ( )
. location ( "~/path/to/directory" )
. search_input ( "what to search" )
. more_locations ( vec ! [ "/anotherPath/to/search" , "/keepAddingIfYouWant/" ] )
. limit ( 1000 ) // results to return
. ext ( "extension" )
. strict ( )
. depth ( 1 )
. ignore_case ( )
. hidden ( )
. build ( )
. collect ( ) ;
for path in search {
println ! ( "{}" , path ) ;
}
}
use rust_search :: { SearchBuilder , similarity_sort } ;
fn main ( ) {
let search_input = "fly" ;
let mut search : Vec < String > = SearchBuilder :: default ( )
. location ( "~/Desktop/" )
. search_input ( search_input )
. depth ( 1 )
. ignore_case ( )
. build ( )
. collect ( ) ;
similarity_sort ( & mut search , & search_input ) ;
for path in search {
println ! ( "{:?}" , path ) ;
}
}
不进行相似性排序的搜索
["afly.txt", "bfly.txt", "flyer.txt", "fly.txt"]
使用相似度排序搜索
["fly.txt", "flyer.txt", "afly.txt", "bfly.txt",]
use rust_search :: SearchBuilder ;
let files : Vec < String > = SearchBuilder :: default ( )
. location ( "/path/to/directory" )
. ext ( "file_extension" )
. build ( )
. collect ( ) ;
use rust_search :: SearchBuilder ;
let files : Vec < String > = SearchBuilder :: default ( )
. location ( "/path/to/directory" )
. depth ( 1 )
. build ( )
. collect ( ) ;
要按创建日期、修改日期、文件大小和/或自定义过滤器过滤文件,请使用:
use rust_search :: { FileSize , FilterExt , SearchBuilder } ;
use std :: time :: { Duration , SystemTime } ;
let search : Vec < String > = SearchBuilder :: default ( )
. location ( "~/path/to/directory" )
. file_size_greater ( FileSize :: Kilobyte ( 200.0 ) )
. file_size_smaller ( FileSize :: Megabyte ( 10.0 ) )
. created_after ( SystemTime :: now ( ) - Duration :: from_secs ( 3600 * 24 * 10 ) )
. created_before ( SystemTime :: now ( ) )
. modified_after ( SystemTime :: now ( ) - Duration :: from_secs ( 3600 * 24 * 5 ) )
. custom_filter ( |dir| dir . metadata ( ) . unwrap ( ) . is_file ( ) )
. custom_filter ( |dir| !dir . metadata ( ) . unwrap ( ) . permissions ( ) . readonly ( ) )
. build ( )
. collect ( ) ;
更多示例请参考文档
样本大小的差异是由于 fd 和 glob 是不同的工具并且具有不同的用例。 fd 是一个搜索文件和目录的命令行工具。 glob 是一个可用于搜索文件和目录的库。该基准测试是在 MacBook Air M2、16 GB 统一内存上完成的。
基准测试是使用 hyperfine 完成的,基准测试文件位于基准测试驱动器文件夹中。
基准测试是在包含 300K 文件的目录上进行的。
命令/库 | 方法] | 最小[秒] | 最大[秒] | 相对的 |
---|---|---|---|---|
rust_search | 1.317±0.002 | 1.314 | 1.320 | 1.00 |
glob | 22.728±0.023 | 22.690 | 22.746 | 17.25±0.03 |
基准测试是在包含 45K 文件的目录上完成的。
命令/库 | 平均值[毫秒] | 最短[毫秒] | 最大[毫秒] | 相对的 |
---|---|---|---|---|
rust_search | 680.5±2.1 | 678.3 | 683.6 | 1.00 |
fd -e .js | 738.7±10.2 | 720.8 | 746.7 | 1.09±0.02 |
+ rust_search is 17.25 times faster than Glob.
+ rust_search** is 1.09 times faster than FD.
由于该库仍处于早期阶段,因此任何贡献都将受到高度重视。
如果您想为该项目做出贡献,请按照以下步骤操作:
该项目根据 MIT 许可条款获得许可。
单击下面的按钮加入 Discord 服务器或 Linkedin