Skip to content

Commit 5d67bac

Browse files
0.15.1: 修复返回空字符串的bug && 优化客户端hover说明 && 随键入自动搜索
1 parent 43abb24 commit 5d67bac

File tree

9 files changed

+87
-47
lines changed

9 files changed

+87
-47
lines changed

app/search-files-app/package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/search-files-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"@testing-library/react": "^13.4.0",
88
"bootstrap": "^5.3.3",
99
"react": "^18.3.1",
10-
"react-bootstrap": "^2.10.4",
10+
"react-bootstrap": "^2.10.5",
1111
"react-dom": "^18.3.1",
1212
"react-scripts": "5.0.1",
1313
"web-vitals": "^2.1.4"

app/search-files-app/src-tauri/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ fn main() {
135135
.max_file_size(50_000 /* bytes */)
136136
.target(tauri_plugin_log::Target::new(
137137
tauri_plugin_log::TargetKind::Folder {
138-
path: PathBuf::from("."),
139-
file_name: Some("search_file_app".to_string()),
138+
path: PathBuf::from("./log"),
139+
file_name: Some("./search_file_app".to_string()),
140140
},
141141
))
142142
.rotation_strategy(tauri_plugin_log::RotationStrategy::KeepAll)

app/search-files-app/src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
"productName": "search-files-app",
4646
"mainBinaryName": "search-files-app",
47-
"version": "0.15.0",
47+
"version": "0.15.1",
4848
"identifier": "com.file.efl.toni",
4949
"plugins": {
5050
"cli": {

app/search-files-app/src/elements/ResultsList.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import ResultItem from './ResultItem.js';
55

66
const ResultsList = ({ results, addMessage }) => {
77
// 移除了模态相关的状态和处理函数
8-
8+
console.log("results: ", results);
99
return (
1010
<>
11-
{/* 移除了展示模态按钮 */}
12-
1311
<ListGroup style={{ maxHeight: '400px', overflowY: 'auto' }}>
1412
{results.map((result, index) => (
1513
<ResultItem key={index} result={result} addMessage={addMessage} />

app/search-files-app/src/elements/SearchForm.js

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState, useEffect, useRef } from 'react';
2-
import { Form, Button, Container, Row, Col } from 'react-bootstrap';
2+
import { Form, Button, Container, Row, Col, Tooltip, OverlayTrigger } from 'react-bootstrap';
33
import ResultsList from './ResultsList.js';
44
import NotificationToast from './NotificationToast.js';
55
import HelpBar from './Help.js';
@@ -26,10 +26,15 @@ const SearchForm = () => {
2626

2727
useEffect(() => {
2828
setResults([]);
29-
3029
focusInput();
3130
}, []);
3231

32+
useEffect(() => {
33+
if (entry && !isSmart) {
34+
handleSearch();
35+
}
36+
}, [entry, isFuzzy, isRegex, isSmart]);
37+
3338
const handleSearch = async () => {
3439
setResults([]);
3540
const invoke = window.__TAURI__.core.invoke;
@@ -56,7 +61,6 @@ const SearchForm = () => {
5661
}
5762
};
5863

59-
6064
const addMessage = (msg) => {
6165
setMessage(msg);
6266
setShowToast(true);
@@ -79,38 +83,39 @@ const SearchForm = () => {
7983
onChange={(e) => setEntry(e.target.value)}
8084
ref={inputRef} // 绑定引用
8185
placeholder="Enter your search query"
82-
onKeyDown={(e) => {
83-
if (e.key === 'Enter') {
84-
e.preventDefault(); // 阻止默认行为,避免清空输入框
85-
console.log('Enter pressed');
86-
handleSearch();
87-
}
88-
}}
8986
/>
9087
</Form.Group>
9188
<br />
9289
<div className="d-flex align-items-center gap-3">
93-
<Form.Check
94-
type="checkbox"
95-
label="Fuzzy"
96-
checked={isFuzzy}
97-
onChange={(e) => setIsFuzzy(e.target.checked)}
98-
/>
99-
<Form.Check
100-
type="checkbox"
101-
label="Regex"
102-
checked={isRegex}
103-
onChange={(e) => setIsRegex(e.target.checked)}
104-
/>
105-
<Form.Check
106-
type="checkbox"
107-
label="Smart Mode"
108-
checked={isSmart}
109-
onChange={(e) => setIsSmart(e.target.checked)}
110-
/>
90+
<OverlayTrigger placement="bottom" overlay={<Tooltip>Fuzzy search enables partial matches.</Tooltip>}>
91+
<Form.Check
92+
type="checkbox"
93+
label="Fuzzy"
94+
checked={isFuzzy}
95+
onChange={(e) => setIsFuzzy(e.target.checked)}
96+
/>
97+
</OverlayTrigger>
98+
99+
<OverlayTrigger placement="bottom" overlay={<Tooltip>Regex search enables regex matches and it will add .* in both ends</Tooltip>}>
100+
<Form.Check
101+
type="checkbox"
102+
label="Regex"
103+
checked={isRegex}
104+
onChange={(e) => setIsRegex(e.target.checked)}
105+
/>
106+
</OverlayTrigger>
107+
108+
<OverlayTrigger placement="bottom" overlay={<Tooltip>Smart search search entries in hot dirs which are not cached. It costs more resoureces so it will not raise auto search unless you press the button</Tooltip>}>
109+
<Form.Check
110+
type="checkbox"
111+
label="Smart Mode"
112+
checked={isSmart}
113+
onChange={(e) => setIsSmart(e.target.checked)}
114+
/>
115+
</OverlayTrigger>
116+
111117
<HelpBar></HelpBar>
112-
<ConfigBar></ConfigBar
113-
>
118+
<ConfigBar></ConfigBar>
114119
<Button variant="primary" type="button" className="ms-auto"
115120
onClick={handleSearch}>
116121
Search

src/cache/trie.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl TrieNode {
115115

116116
// 如果当前节点的名称与目标名称相匹配,将当前节点的路径加入结果
117117

118-
if pattern_match(&self.entry_name, entry_name, is_fuzzy) {
118+
if !self.entry_name.is_empty() && pattern_match(&self.entry_name, entry_name, is_fuzzy) {
119119
results.push(self.full_path.clone());
120120
}
121121

src/server/api.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use crate::{
1414

1515
pub fn api_search(entry: String, is_fuzzy: bool) -> Vec<(String, bool)> {
1616
debug!("search: entry({}), is_fuzzy({})", entry, is_fuzzy);
17+
if entry.is_empty() {
18+
return Vec::new();
19+
}
1720
let guard = CACHER.lock().unwrap(); // 使用 mut 解锁后可以释放锁
1821
let res = guard.search_entry(&entry, is_fuzzy);
1922

@@ -48,6 +51,13 @@ pub fn api_search(entry: String, is_fuzzy: bool) -> Vec<(String, bool)> {
4851
}
4952

5053
pub fn api_hot_search(entry: String, is_fuzzy: bool, is_regex: bool) -> Vec<(String, bool)> {
54+
debug!(
55+
"hot_search: entry({}), is_fuzzy({}), is_regex({})",
56+
entry, is_fuzzy, is_regex
57+
);
58+
if entry.is_empty() {
59+
return Vec::new();
60+
}
5161
let res = search_files_from_hot_dirs(&entry, is_fuzzy, is_regex);
5262

5363
let mut cache_guard = CACHER.lock().unwrap();
@@ -70,7 +80,9 @@ pub fn api_hot_search(entry: String, is_fuzzy: bool, is_regex: bool) -> Vec<(Str
7080

7181
pub fn api_regex_search(path: String) -> Vec<(String, bool)> {
7282
debug!("regex_search: entry({})", path);
73-
83+
if path.is_empty() {
84+
return Vec::new();
85+
}
7486
let guard = CACHER.lock().unwrap(); // 使用 mut 解锁后可以释放锁
7587
let res = guard.search_path_regex(&path);
7688

@@ -119,3 +131,23 @@ pub fn api_unstar_path(path_data: String) -> bool {
119131
Err(_) => false,
120132
}
121133
}
134+
135+
#[allow(unused)]
136+
mod tests {
137+
use super::*;
138+
use crate::{cache::cache::init_trie, db::SqliteDatabase};
139+
use std::sync::{Arc, Mutex};
140+
141+
#[test]
142+
fn test_search() {
143+
let raw_db = SqliteDatabase::new(&PathBuf::from(
144+
"C:\\Users\\toni\\AppData\\Local\\search-files-app\\sqlite3.db",
145+
))
146+
.unwrap();
147+
let db = Arc::new(Mutex::new(raw_db));
148+
init_trie((db));
149+
150+
let res = api_search("小论文".to_string(), false);
151+
println!("{:?}", res)
152+
}
153+
}

src/util/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,21 @@ use std::os::windows::ffi::OsStringExt;
1313
#[cfg(target_os = "windows")]
1414
use winapi::um::fileapi::GetLogicalDriveStringsW;
1515

16-
/// 模糊匹配
16+
/// 匹配
1717
pub fn pattern_match(entry: &str, pattern: &str, is_fuzzy: bool) -> bool {
1818
let entry_l = entry.to_lowercase();
1919
let pattern_l = pattern.to_lowercase();
20+
21+
// 只取前缀部分进行匹配
22+
let entry_prefix: String = entry_l.chars().take(pattern_l.chars().count()).collect();
23+
let pattern_prefix: String = pattern_l.chars().take(entry_l.chars().count()).collect();
24+
2025
if is_fuzzy {
2126
// 设定一个模糊匹配的阈值,比如距离小于等于2
2227
let threshold = 2;
23-
levenshtein(&entry_l, &pattern_l) <= threshold
28+
levenshtein(&entry_prefix, &pattern_prefix) <= threshold
2429
} else {
25-
entry_l == pattern_l
30+
entry_prefix == pattern_prefix
2631
}
2732
}
2833

0 commit comments

Comments
 (0)