jplattel / obsidian-query-language

An Obsidian plugin allowing you to query your notes
176 stars 6 forks source link

Inconsistent results in OQL vs obsidian search results #16

Closed jorgb closed 3 years ago

jorgb commented 3 years ago

I am using 2.0.0 and the results are inconsistent with what I get when I perform a search in Obsidian itself.

For example:

name: Paintings
query: 
    $and:
        - content: "tag:#artbook"
        - content: "tag:#painting"
template: "list"

Shows me 3 results.

When I search in Obsidian with tag:#artbook tag:#painting I get 27 results.

So the indexing is not consistent with the results. Right now since the results are inconstent, the plugin becomes unreliable and counts and hits are not representative to what is really in my database.

I know you are working to make it better, but it looks like indexed results are not consistent with Obsidian's result. Is there maybe a way to reindex?

Just a side note, I used TiddlyWiki for a while, and they have a language where you can "program" results to filter. Either collapse the results to a count, or display them as a list, or feed them to a template.

They are called "tiddler filters" and they have a syntax like;

<$list filter="[tag[ListWidget]sort[title]]"/>

It seems you are trying to accomplish similar with the plugin as well. So I wanted to toss it in for inspiration;

https://tiddlywiki.com/static/Filters.html

They are quite powerful, and would truly like to see in obsidian some day.

jplattel commented 3 years ago

Hey @jorgb!

Thanks for the feedback! The query block statement for OQL is an "AND" statement, meaning that the notes matched should have both tags. While the query in the Obsidian search is an "OR", meaning that the notes should contain at least 1 of the tags. Can you confirm this by changing &and into $or?

Otherwise it is indeed a indexing bug that needs investigation..

As for the filters in TiddlyWiki, I didn't know of those, will be looking into it! 👍

jplattel commented 3 years ago

Alright, I'm mistaken, the search you supplied does run as an "AND" search. Will have a look on why this isn't working correctly!

jplattel commented 3 years ago

Could you try the following:

```oql
name: Paintings
query: 
    $and:
        - content: "'#artbook"
        - content: "'#painting"     
template: "list"


The way OQL queries doesn't exactly match Obsidian since I'm using a different search engine. Please note the single quotes at the start of the string that needs to be matched, in this case it means an exact match.
jorgb commented 3 years ago

Hi @jplattel Yes that one produces the exact amount of hits. Could you tell me why there is a single quote needed in front of the hashtag but not at the end?

The results I get are now consistent;

// Debugging OQL, total results: 27
// Query: 
{
  "$and": [
    {
      "content": "'#artbook"
    },
    {
      "content": "'#painting"
    }
  ]
}

Edit: I did not see the quotes in the query expansion so I edited a part of the message. Still wondering about the quote that is needed though.

jplattel commented 3 years ago

The single quote has to do with the way you search with Fuse. There's more information here: https://fusejs.io/examples.html#extended-search :)