alphapapa / org-ql

A searching tool for Org-mode, including custom query languages, commands, saved searches and agenda-like views, etc.
GNU General Public License v3.0
1.4k stars 110 forks source link

`ancestor`/`parent` predicates can return incorrect results #365

Closed kofm closed 7 months ago

kofm commented 1 year ago

Hello, I am encountering an unexpected result when using the parent query selector in org-ql. I have the following org file structure:

Description

* Test
** Foo
* Not to be shown
** Bar

When I run the following query:

(org-ql-search "/tmp/test.org" '(parent "Test"))

I expect only to get the 'Foo' result, as it's the only heading with "Test" as a direct parent. However, the query returns both 'Foo' and 'Bar'.

Expected Behavior

According to the docstring for the parent selector:

parent (&optional query) Return non-nil if current heading has a direct parent heading. If QUERY, return non-nil if the parent heading matches it. This selector may be nested, e.g. to match grandparent headings.

I expected the query to return only headings with "Test" as their direct parent. In this case, only 'Foo' should match the query.

Actual Behavior

The query returns both 'Foo' and 'Bar', which seems inconsistent with the docstring definition of the parent selector.

I hope I have understood the documentation, and I would appreciate any clarification or assistance in resolving this issue. Once again, I'd like to express my gratitude for your efforts on the org-ql package. It's genuinely invaluable to my Emacs experience. Thank you!

alphapapa commented 1 year ago

Hi,

Thanks for reporting this. I can confirm the bug. I don't know why it's happening, but I'll investigate when I have time.

In the meantime, I noticed that these queries seem to behave as expected, so you could use them while waiting for a fix:

'(parent (heading "Test"))
'(parent (rifle "Test"))
alphapapa commented 1 year ago

Several smaller fixes are due to be made in 0.7.x releases, and this bug doesn't seem new, so I'm going to defer it until 0.8.

alphapapa commented 7 months ago

Finally, this is fixed. It took a lot of digging. Thanks for your patience.

kofm commented 7 months ago

Thank you very much