obsidian-query-language
obsidian-query-language copied to clipboard
Request for basic examples
Thanks for this plugin, it looks great and very promising.
I noticed that the examples do focus on query meta-data, not content of the notes.
Thus, I think an addition of the following examples would be very helpful to get started:
Example 1: search for all notes which contain "apple" or "pear" and output number of notes found
Example 2: only search in note "my garden" if it contains "apple" and "pear"
Example 3: count how many times note "my garden" and "garden of my neighbour" link to [[tree]]
Example 4: check if note "my new garden" contains "fruit" AND ("tree" OR "bush")
Hi @ewandel, good idea! I'll add those!
Cool, thanks very much, I'm looking forward to it. Great plug in!
Hi, in the meantime I played around a little bit more and I think I can answer a couple of my questions myself:
Search for content of notes
The previous examples focused on meta-data searches. Of course, OQL may also be used to search the actual content of the notes in Obsidian. The following examples should get you started:
Example 1:
search for all notes which contain "apple" or "pear" and output number of notes found
short notation: A space (" ") is interpreted as AND, a pipe symbol ("|") as an OR:
name: 'boolean OR search'
query: apple | pear
template: "string"
format: "{name}: {count}"
badge: true
debug: true
complete notation (longer, but more flexible):
name: 'OR combination list of results'
query: { $or: [{ "content": "'apple" }, { "content": "'pear" }] }
template: "list"
badge: true
debug: true
Example 2:
only search in note "my garden" and check if it contains "apple" AND "pear"
name: 'Search in single file with AND'
query: { $and: [{ "title": ="my garden" }, {$and: [{ "content": "'apple" }, {"content": "'pear" }]}]}
template: "string"
badge: false
debug: true
includeMatches: false
format: "{count}"
note the "=" in front of "my garden" to force an exact match, while the "'" only requires that the text contains the word, for example a link to [[apple]] or an "apple-tree" will also be found.
Example 3:
count how many times note "my garden" and "garden of my neighbour" link to [[tree]]
*** I still have not figured out how to do this. In particular, in all my examples I only get a count of "0" if my search does not occur, and a count of "1" if there is at least one result. However, I never get a higher count than 1 even if there are multiple hits.
Example 4:
check if note "my new garden" contains "fruit" AND ("tree" OR "bush")
name: 'test'
query: { $and: [{ "title": ="my new garden" }, { "content": "'fruit"}, {$or: [{ "content": "'tree" }, {"content": "'bush" }]}]}
template: "string"
badge: false
debug: true
includeMatches: false
format: "{count}"
This is great, I'll add those to the README with credits!
As for third example, I think this is quite a complex query, I couldn't it to work either... I'll explore some more and report back If I do!
This is great, I'll add those to the README with credits!
Thank you :-D