How can i use the built in query language to display a count in a pluging

I am using the code below to search for tasks but the issue is that it opens the seach ui every time it does… I want it to happen in the background. Anyone have a way to do this better while using the Query Language of Obsidian?

async function getTaskBadgeCountSearch2(app) {
	const taskQuery = `tasks not done due today path does not include 50 Resources  group by path sort by priority sort by path hide due date `;
	app.internalPlugins.plugins['global-search'].instance.openGlobalSearch(taskQuery);
	const searchLeaf = app.workspace.getLeavesOfType('search')[0];
	const search = await searchLeaf.open(searchLeaf.view);
	return await new Promise(resolve => setTimeout(() => {
		resolve(search.dom.resultDomLookup.size);

	}, 300)); // the delay here was specified in 'obsidian-text-expand' plugin; I assume they had a reason   
}

I don’t have any ideas about the built-in search of Obsidian, but how about using the Dataview API?

https://blacksmithgu.github.io/obsidian-dataview/resources/develop-against-dataview/

1 Like

Sorry for the delay, I have gotten it working with dataview. After fixing the query to be faster it’s nice but still has a delay and only works on desktop. Trying to find a way to have it work natively with the query language but this is workable for now. Thanks @ush !