-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add autocomplete suggestions feature in search page #1030
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Yash-1511 , thanks for the useful PR. I've left some comments, feel free to ask any clarifications if required. Looking forward to get this PR in soon!
suggestionsTimeoutRef.current = setTimeout(() => { | ||
getFileSuggestions(value); | ||
}, 100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we get all files indexed by user once on search page load (instead of every keystroke)? This would avoid unnecessary API and DB calls to server and hopefully make file filter suggestions faster too
return; | ||
} | ||
|
||
setFocusSearchResult(null); | ||
const filePrefix = query.substring(5).trim(); // Remove "file:" prefix | ||
const apiUrl = `/api/file-suggestions?q=${encodeURIComponent(filePrefix)}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just call the GET /api/content/computer
API endpoint to get all files indexed for the user once? This will reduce API calls and remove the need for the new file suggestions API endpoint. But the sorting and filtering logic that you added to the /api/file-suggestions
API endpoint would need to move to the client
if (!searchQuery.trim()) { | ||
function getFileSuggestions(query: string) { | ||
// Get suggestions only if query starts with "file:" | ||
if (!query.toLowerCase().startsWith("file:")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This limits the file:
filters to be only added at the start of the query. This conflicts with the slash commands which are expected to be at start of query currently. So for example, you wouldn't be able to do queries like /notes file:"Notes/Tasks.org"
.
It'd be good if the file filter can be placed anywhere in query or maybe at the end of query is fine too for now?
if (!query.toLowerCase().startsWith("file:")) { | |
if (!query.toLowerCase().endsWith("file:")) { |
return; | ||
} | ||
|
||
setFocusSearchResult(null); | ||
const filePrefix = query.substring(5).trim(); // Remove "file:" prefix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic will need to be updated if file:
is a suffix instead of a prefix/infix as suggested in another comment
File Path Autocompletion in Search
Closes #1024
Description
Added file path autocompletion to enhance the search experience in Khoj. Users can now easily search for specific files by typing "file:" followed by the file name, with real-time suggestions appearing as they type.
Changes
/api/file-suggestions
to get file path suggestionsFeatures
Screenshots
[Add screenshots showing the file path autocompletion in action]
Testing
Dependencies
No new dependencies were added.
Notes