Search working internally. Results not yet shown in interface
This commit is contained in:
parent
2116549154
commit
9b9c5add18
3 changed files with 71 additions and 35 deletions
20
src-tauri/Cargo.lock
generated
20
src-tauri/Cargo.lock
generated
|
|
@ -144,6 +144,7 @@ name = "apographe"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"comrak",
|
"comrak",
|
||||||
|
"fuzzy-matcher",
|
||||||
"html_tag",
|
"html_tag",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
@ -1236,6 +1237,15 @@ dependencies = [
|
||||||
"slab",
|
"slab",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fuzzy-matcher"
|
||||||
|
version = "0.3.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "54614a3312934d066701a80f20f15fa3b56d67ac7722b39eea5b4c9dd1d66c94"
|
||||||
|
dependencies = [
|
||||||
|
"thread_local",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fxhash"
|
name = "fxhash"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
|
|
@ -4149,6 +4159,16 @@ dependencies = [
|
||||||
"syn 2.0.87",
|
"syn 2.0.87",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thread_local"
|
||||||
|
version = "1.1.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.3.36"
|
version = "0.3.36"
|
||||||
|
|
|
||||||
|
|
@ -27,4 +27,4 @@ tauri-plugin-fs = "2"
|
||||||
tauri-plugin-log = "2"
|
tauri-plugin-log = "2"
|
||||||
shellexpand = "3.1.0"
|
shellexpand = "3.1.0"
|
||||||
html_tag = "0.1.3"
|
html_tag = "0.1.3"
|
||||||
|
fuzzy-matcher = "0.3"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
|
||||||
use html_tag::HtmlTag;
|
use html_tag::HtmlTag;
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, DirEntry},
|
fs::{self, DirEntry},
|
||||||
|
|
@ -12,6 +13,55 @@ pub fn search_files(basepath: &str, searchstring: &str, filter: Vec<String>) ->
|
||||||
Err(_) => Vec::new(),
|
Err(_) => Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn _search_files(path: &Path, searchstring: &str, filter: &Vec<String>) -> Vec<String> {
|
||||||
|
let mut search_results: Vec<String> = Vec::new();
|
||||||
|
if let Ok(entries) = fs::read_dir(path) {
|
||||||
|
for dir_entry_res in entries {
|
||||||
|
if let Ok(dir_entry) = dir_entry_res {
|
||||||
|
if let Ok(metadata) = fs::metadata(dir_entry.path()) {
|
||||||
|
if metadata.is_file() {
|
||||||
|
if entry_match(&dir_entry, searchstring, filter) {
|
||||||
|
let div = search_result_div_from_dir_entry(&dir_entry).to_html();
|
||||||
|
println!("{:?}", div);
|
||||||
|
search_results.push(div);
|
||||||
|
}
|
||||||
|
} else if metadata.is_dir() {
|
||||||
|
search_results.append(&mut _search_files(
|
||||||
|
&dir_entry.path(),
|
||||||
|
searchstring,
|
||||||
|
&filter,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("{:?}", search_results);
|
||||||
|
return search_results;
|
||||||
|
}
|
||||||
|
fn entry_match(dir_entry: &DirEntry, searchstring: &str, filter: &Vec<String>) -> bool {
|
||||||
|
if filter.contains(
|
||||||
|
&dir_entry
|
||||||
|
.path()
|
||||||
|
.extension()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_string_lossy()
|
||||||
|
.to_string(),
|
||||||
|
) {
|
||||||
|
let matcher = SkimMatcherV2::default();
|
||||||
|
let search_match: Option<i64> =
|
||||||
|
matcher.fuzzy_match(&dir_entry.file_name().to_string_lossy(), searchstring);
|
||||||
|
// debug!(
|
||||||
|
// "{} = {} : {:?}",
|
||||||
|
// search_str, &application.name, search_match
|
||||||
|
// );
|
||||||
|
if let Some(score) = search_match {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// self.matches.sort_by(|a, b| b.1.cmp(&a.1));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
fn search_result_div_from_dir_entry(dir_entry: &DirEntry) -> HtmlTag {
|
fn search_result_div_from_dir_entry(dir_entry: &DirEntry) -> HtmlTag {
|
||||||
let mut file_div = HtmlTag::new("div")
|
let mut file_div = HtmlTag::new("div")
|
||||||
|
|
@ -44,37 +94,3 @@ fn search_result_div_from_dir_entry(dir_entry: &DirEntry) -> HtmlTag {
|
||||||
file_div.add_child(file_button);
|
file_div.add_child(file_button);
|
||||||
return file_div;
|
return file_div;
|
||||||
}
|
}
|
||||||
pub fn _search_files(path: &Path, searchstring: &str, filter: &Vec<String>) -> Vec<String> {
|
|
||||||
let mut search_results: Vec<String> = Vec::new();
|
|
||||||
if let Ok(entries) = fs::read_dir(path) {
|
|
||||||
for dir_entry_res in entries {
|
|
||||||
if let Ok(dir_entry) = dir_entry_res {
|
|
||||||
if let Ok(metadata) = fs::metadata(dir_entry.path()) {
|
|
||||||
if metadata.is_file() {
|
|
||||||
if filter.contains(
|
|
||||||
&dir_entry
|
|
||||||
.path()
|
|
||||||
.extension()
|
|
||||||
.unwrap_or_default()
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string()
|
|
||||||
) {
|
|
||||||
let div =search_result_div_from_dir_entry(&dir_entry).to_html();
|
|
||||||
println!("{:?}", div);
|
|
||||||
search_results
|
|
||||||
.push(div);
|
|
||||||
}
|
|
||||||
} else if metadata.is_dir() {
|
|
||||||
search_results.append(&mut _search_files(
|
|
||||||
&dir_entry.path(),
|
|
||||||
searchstring,
|
|
||||||
&filter,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
println!("{:?}", search_results);
|
|
||||||
return search_results;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue