obsidian#sortSearchResults TypeScript Examples
The following examples show how to use
obsidian#sortSearchResults.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: commandHandler.ts From obsidian-switcher-plus with GNU General Public License v3.0 | 6 votes |
override getSuggestions(inputInfo: InputInfo): CommandSuggestion[] {
const suggestions: CommandSuggestion[] = [];
if (inputInfo) {
inputInfo.buildSearchQuery();
const { hasSearchTerm, prepQuery } = inputInfo.searchQuery;
const itemsInfo = this.getItems();
itemsInfo.forEach((item) => {
let shouldPush = true;
let match: SearchResult = null;
if (hasSearchTerm) {
match = fuzzySearch(prepQuery, item.name);
shouldPush = !!match;
}
if (shouldPush) {
suggestions.push({
type: 'command',
item,
match,
});
}
});
if (hasSearchTerm) {
sortSearchResults(suggestions);
}
}
return suggestions;
}
Example #2
Source File: editorHandler.ts From obsidian-switcher-plus with GNU General Public License v3.0 | 6 votes |
override getSuggestions(inputInfo: InputInfo): EditorSuggestion[] {
const suggestions: EditorSuggestion[] = [];
if (inputInfo) {
inputInfo.buildSearchQuery();
const { hasSearchTerm, prepQuery } = inputInfo.searchQuery;
const { excludeViewTypes, includeSidePanelViewTypes } = this.settings;
const items = this.getOpenLeaves(excludeViewTypes, includeSidePanelViewTypes);
items.forEach((item) => {
let shouldPush = true;
let match: SearchResult = null;
if (hasSearchTerm) {
match = fuzzySearch(prepQuery, item.getDisplayText());
shouldPush = !!match;
}
if (shouldPush) {
const file = item.view?.file;
suggestions.push({ type: 'editor', file, item, match });
}
});
if (hasSearchTerm) {
sortSearchResults(suggestions);
}
}
return suggestions;
}
Example #3
Source File: headingsHandler.ts From obsidian-switcher-plus with GNU General Public License v3.0 | 6 votes |
override getSuggestions(inputInfo: InputInfo): SupportedSuggestionTypes[] {
let suggestions: SupportedSuggestionTypes[] = [];
if (inputInfo) {
inputInfo.buildSearchQuery();
const { prepQuery, hasSearchTerm } = inputInfo.searchQuery;
if (hasSearchTerm) {
const { limit } = this.settings;
suggestions = this.getAllFilesSuggestions(prepQuery);
sortSearchResults(suggestions);
if (suggestions.length > 0 && limit > 0) {
suggestions = suggestions.slice(0, limit);
}
} else {
suggestions = this.getRecentFilesSuggestions();
}
}
return suggestions;
}
Example #4
Source File: relatedItemsHandler.ts From obsidian-switcher-plus with GNU General Public License v3.0 | 6 votes |
override getSuggestions(inputInfo: InputInfo): RelatedItemsSuggestion[] {
const suggestions: RelatedItemsSuggestion[] = [];
if (inputInfo) {
this.inputInfo = inputInfo;
inputInfo.buildSearchQuery();
const { hasSearchTerm, prepQuery } = inputInfo.searchQuery;
const cmd = inputInfo.parsedCommand(Mode.RelatedItemsList) as SourcedParsedCommand;
const items = this.getRelatedFiles(cmd.source.file);
items.forEach((item) => {
let shouldPush = true;
let match: SearchResult = null;
if (hasSearchTerm) {
match = fuzzySearch(prepQuery, this.getTitleText(item));
shouldPush = !!match;
}
if (shouldPush) {
suggestions.push({
type: 'relatedItems',
relationType: 'diskLocation',
file: item,
match,
});
}
});
if (hasSearchTerm) {
sortSearchResults(suggestions);
}
}
return suggestions;
}
Example #5
Source File: starredHandler.ts From obsidian-switcher-plus with GNU General Public License v3.0 | 6 votes |
override getSuggestions(inputInfo: InputInfo): StarredSuggestion[] {
const suggestions: StarredSuggestion[] = [];
if (inputInfo) {
inputInfo.buildSearchQuery();
const { hasSearchTerm, prepQuery } = inputInfo.searchQuery;
const itemsInfo = this.getItems();
itemsInfo.forEach(({ file, item }) => {
let shouldPush = true;
let match: SearchResult = null;
if (hasSearchTerm) {
match = fuzzySearch(prepQuery, item.title);
shouldPush = !!match;
}
if (shouldPush) {
suggestions.push({ type: 'starred', file, item, match });
}
});
if (hasSearchTerm) {
sortSearchResults(suggestions);
}
}
return suggestions;
}
Example #6
Source File: symbolHandler.ts From obsidian-switcher-plus with GNU General Public License v3.0 | 6 votes |
override getSuggestions(inputInfo: InputInfo): SymbolSuggestion[] {
const suggestions: SymbolSuggestion[] = [];
if (inputInfo) {
this.inputInfo = inputInfo;
inputInfo.buildSearchQuery();
const { hasSearchTerm, prepQuery } = inputInfo.searchQuery;
const symbolCmd = inputInfo.parsedCommand(Mode.SymbolList) as SourcedParsedCommand;
const items = this.getItems(symbolCmd.source, hasSearchTerm);
items.forEach((item) => {
let shouldPush = true;
let match: SearchResult = null;
if (hasSearchTerm) {
match = fuzzySearch(prepQuery, SymbolHandler.getSuggestionTextForSymbol(item));
shouldPush = !!match;
}
if (shouldPush) {
const { file } = symbolCmd.source;
suggestions.push({ type: 'symbol', file, item, match });
}
});
if (hasSearchTerm) {
sortSearchResults(suggestions);
}
}
return suggestions;
}
Example #7
Source File: workspaceHandler.ts From obsidian-switcher-plus with GNU General Public License v3.0 | 6 votes |
override getSuggestions(inputInfo: InputInfo): WorkspaceSuggestion[] {
const suggestions: WorkspaceSuggestion[] = [];
if (inputInfo) {
inputInfo.buildSearchQuery();
const { hasSearchTerm, prepQuery } = inputInfo.searchQuery;
const items = this.getItems();
items.forEach((item) => {
let shouldPush = true;
let match: SearchResult = null;
if (hasSearchTerm) {
match = fuzzySearch(prepQuery, item.id);
shouldPush = !!match;
}
if (shouldPush) {
suggestions.push({ type: 'workspace', item, match });
}
});
if (hasSearchTerm) {
sortSearchResults(suggestions);
}
}
return suggestions;
}
Example #8
Source File: index.ts From obsidian-switcher-plus with GNU General Public License v3.0 | 5 votes |
mockSortSearchResults = mockFn<typeof sortSearchResults>().mockImplementation()