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