Skip to content

Commit

Permalink
Revert "Use fuse to do fuzzy search to find files"
Browse files Browse the repository at this point in the history
This reverts commit 2ae361b.
  • Loading branch information
truell20 committed Mar 27, 2023
1 parent 42fd394 commit a3e56fb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 322 deletions.
213 changes: 0 additions & 213 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"css-loader": "^6.7.2",
"electron": "22.0.0",
"electron-devtools-installer": "^3.2.0",
"electron-reloader": "^1.2.3",
"electron-winstaller": "^5.1.0",
"eslint": "^8.36.0",
"eslint-plugin-import": "^2.27.5",
Expand Down Expand Up @@ -142,7 +141,6 @@
"emojilib": "^3.0.8",
"fix-path": "^4.0.0",
"fork-ts-checker-webpack-plugin": "^7.2.14",
"fuse.js": "^6.6.2",
"gunzip-file": "^0.1.1",
"line-diff": "^2.1.1",
"lodash.debounce": "^4.0.8",
Expand Down
33 changes: 16 additions & 17 deletions src/features/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,8 @@ const searchUnseenFiles = async (query: string, state: FullState) => {
const rootPath = state.global.rootPath!
// Now we need to search the files that haven't been seen yet

let nameResultsFuture = await connector.searchFilesNameGit({
query,
rootPath,
})
let pathResultsFuture = await connector.searchFilesPathGit({
query,
rootPath,
})
let nameResultsFuture = connector.searchFilesNameGit({ query, rootPath })
let pathResultsFuture = connector.searchFilesPathGit({ query, rootPath })

const [initialNameResults, initialPathResults] = await Promise.all([
nameResultsFuture,
Expand Down Expand Up @@ -266,20 +260,19 @@ export const searchFile = (query: string) =>
}
} = {}

const queryKeywords = query.toLowerCase().split(' ')

const matchesQuery = (str: string) =>
queryKeywords.every((keyword) =>
str.toLowerCase().replace(/\s+/g, '').includes(keyword)
)

for (let fid in files) {
let fileId = parseInt(fid)
const file = files[fid]
let filename = file.name
const path = getPathForFileId(state, fileId)

if (query === '' || matchesQuery(path)) {
if (
query === '' ||
filename
.toLowerCase()
.replace(/\s+/g, '')
.includes(query.toLowerCase().replace(/\s+/g, ''))
) {
resultsSet[path] = { path, filename, score: 0 }

if (Object.keys(resultsSet).length > 50) {
Expand All @@ -296,7 +289,13 @@ export const searchFile = (query: string) =>
const path = getPathForFileId(state, fileId)
const relativePath = getRelativePathForFileId(state, fileId)

if (query === '' || matchesQuery(relativePath)) {
if (
query == '' ||
relativePath
.toLowerCase()
.replace(/\s+/g, '')
.includes(query.toLowerCase().replace(/\s+/g, ''))
) {
if (!(path in resultsSet)) {
resultsSet[path] = { path, filename, score: 1 }
}
Expand Down

0 comments on commit a3e56fb

Please sign in to comment.