I use the search function frequently! For some reason, I will search for things, and the search criteria will either completely not find the word I am looking for, or suggest very obscure instances of the word. Or even variations of the word, without actually giving me the page i am looking for.
For instance, I might have a page I use frequently on say “infectious disease,” but when I search “infectious disease,” the search function will not even suggest that page at all, but will instead find me random instances of teh words “infectious” or “disease” scattered throughout my vault.
Some help would be greatly appreciated! One of the things I really use obsidian for is to be able to quickly access notes I have made.
Indeed, searching something in Obsidian might not seem intuitive at first, but you might find this official documentation helpful.
In short, writing infectious disease in the search bar will search for files that contain both infectious and disease, but not necessarily in that order, nor one right after the other.
To search for an exact phrase, surround it with quotes, for example "star wars".
The double quotes surrounding the words will make it so that Obsidian will search occurrences of the entire sentence, not individual words. For example, "infectious disease" will search for the exact characters infectious disease, which is different from just writing infectious disease.
The page I linked above contains a lot of documentation about this and plenty of other tips to take advantage of Obsidian’s powerful search feature.
Also, if you are interested in a search that “just works” (quoting from this Reddit post), you might want to look into the Obsidian community plugin Omnisearch.
I haven’t looked into the plugin in details and I do not use it myself, but from what I gather, it is faster and more user-friendly than Obsidian default search feature. I believe it is a great plugin if you heavily need search.
I frequently use the following format: /search term. That’s one slash and the unambiguous search term that won’t give you lines with either search and term.
Then if you feel adventurous, you can try what the regular expressions /search.*?term, /search.*term, /search[\s\S]*?term and /search[\s\S]*term do – replace the search and term parts with whatever you want to search for, e.g. work.*relat, etc.
Yes, Obsidian expects some computer savvy from you and I think it’s a good thing also. You can indeed stay closer to regex and always search with /search.*?term; that will also find searchterm, but that’s not that bad.
I am using the following Templater script to take over the global search used with CTRL+SHIFT+F.
With this I can find all compounds with word stems properly.
<%*
// Get the active workspace
const workspace = app.workspace;
// Ensure there's an active editor
const activeLeaf = workspace.activeLeaf;
if (!activeLeaf || !activeLeaf.view || !activeLeaf.view.sourceMode) {
new Notice("No active editor found.");
return;
}
// Get the editor instance
const editor = activeLeaf.view.sourceMode.cmEditor;
// Capture the current selection
let selection = editor.getSelection().trim();
// If no selection, cancel the search
if (!selection) {
new Notice("No text selected.");
return;
}
// Prepend '/' to the search term
let searchTerm = "/" + selection;
// Temporarily store the cursor position or selection range
const cursorPosition = editor.getCursor();
// URL-encode the search query
const encodedQuery = encodeURIComponent(searchTerm);
// Construct the Obsidian URI for the search
const uri = `obsidian://search?query=${encodedQuery}`;
// Create a temporary anchor to trigger the URI
const link = document.createElement('a');
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// Restore the original selection after the script is executed
editor.setSelection(cursorPosition, cursorPosition);
// Optionally: Copy the search query to clipboard
navigator.clipboard.writeText(searchTerm).then(() => {
new Notice(`Copied to clipboard:\n${searchTerm}`);
}).catch(err => {
console.error('Could not copy text: ', err);
});
_%>
Usage: save then register script in Templater settings, bind it to the combination mentioned above then in your document, select text and hit key combo.
If your selection has special characters such as the following, you need to add a \ before them (manually edit the query in search bar) or (I forgot to add here before) use the second version below:
<%*
// Second iteration of script escapes special characters
// Get the active workspace
const workspace = app.workspace;
// Ensure there's an active editor
const activeLeaf = workspace.activeLeaf;
if (!activeLeaf || !activeLeaf.view || !activeLeaf.view.sourceMode) {
new Notice("No active editor found.");
return;
}
// Get the editor instance
const editor = activeLeaf.view.sourceMode.cmEditor;
// Capture the current selection
let selection = editor.getSelection().trim();
// If no selection, cancel the search
if (!selection) {
new Notice("No text selected.");
return;
}
// Function to escape special characters for regex search
function escapeSpecialCharacters(text) {
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
// Escape special characters in the selection
let escapedSelection = escapeSpecialCharacters(selection);
// Prepend '/' to the search term
let searchTerm = "/" + escapedSelection;
// Temporarily store the cursor position or selection range
const cursorPosition = editor.getCursor();
// URL-encode the search query
const encodedQuery = encodeURIComponent(searchTerm);
// Construct the Obsidian URI for the search
const uri = `obsidian://search?query=${encodedQuery}`;
// Create a temporary anchor to trigger the URI
const link = document.createElement('a');
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// Restore the original selection after the script is executed
editor.setSelection(cursorPosition, cursorPosition);
// Optionally: Copy the search query to clipboard
navigator.clipboard.writeText(searchTerm).then(() => {
new Notice(`Copied to clipboard:\n${searchTerm}`);
}).catch(err => {
console.error('Could not copy text: ', err);
});
_%>
Script also adds selection (query) to the clipboard.