alphapapa / alphapapa/org-ql

Can the top level of a document be returned in a query?

Aperta
#253 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Emacs Lisp
Stelle
1.6k
Fork
120
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

# Table of contents

- [The context](#the-context)
- [The problem](#the-problem)
- [Minimal working example](#minimal-working-example)
- [The question](#the-question)

# The context

I'm a user of Org Roam. I've been using Org Mode as a data system for storing entities of different types (e.g. bookmarks, contacts, any entity that have properties). Here are some examples

The following is an Org Mode file (which happens to be an Org Roam node)

```org
:PROPERTIES:
:INSTANCE_OF: radio station
:CONTENT: news
:LANGUAGE: ENG
:OFFICIAL_SITE: https://www.bbc.co.uk/sounds/play/live:bbc_radio_one
:STREAM_AUDIO: https://stream.live.vc.bbcmedia.co.uk/bbc_radio_one
:END:

#+TITLE: BBC Radio 1

* Note

I find this radio station interesting because XYZ.

* Note

I listened XYZ today.
```

The following is another Org Mode file (which also happens to be an Org Roam node)

```org
:PROPERTIES:
:INSTANCE_OF: subreddit
:CONTENT: emacs
:LANGUAGE: ENG
:LINK: https://reddit.com/r/emacs
:END:

#+TITLE: r/emacs

* Note

I read XYZ today.
```

The following is another Org Mode file (which also happens to be an Org Roam node)

Some entities don't have notes. This is important for a point that is later on explained.

```org
:PROPERTIES:
:INSTANCE_OF+: youtube playlist
:LINK: https://www.youtube.com/playlist?list=PLn0nrSd4xjjaSLBSzmno-3Ods6FJE9nlO
:TOPICS+: computer science
:LANGUAGE: ENG
:END:

#+TITLE: ACM A.M. Turing Award Laureate Interviews
```

At this point, I think it is clear what my workflow is.

Because I store entities in that format, I then want to perform queries such as the following

- List all the youtube playlists that have to do with computer science.
- List all the subreddits whose main language is english.

# The problem

Apparently, `org-ql` doesn't support performing queries on those properties that are located in the top level of the document.

A workaround would be to query the `Note` headings and make them inherit the properties of the top level of the document, but as I mentioned, some entities don't have notes.

## Minimal working example

This section explains as minimal working example for understanding that the current implementation of Org Roam doesn't return the top level of the document as a match when performing queries.

Consider the following file with name `main.org`

```org
:PROPERTIES:
:MY_PROPERTY: one
:END:

* TODO The 1st heading
:PROPERTIES:
:MY_PROPERTY: two
:END:

* TODO The 2nd heading
:PROPERTIES:
:MY_PROPERTY: three
:END:

* TODO The 3rd heading
:PROPERTIES:
:MY_PROPERTY: four
:END:
```

The following query works as expected.

```lisp
(with-current-buffer "main.org"
(pp (org-ql-select (current-buffer)
'(todo "TODO"))))
```

```
((headline
(:raw-value "The 1st heading" :begin 39 :end 61 :pre-blank 0 :contents-begin 62 :contents-end 62 :level 1 :priority nil :tags nil :todo-keyword
#("TODO" 0 4
(line-prefix "" wrap-prefix
#("* " 0 2
(face org-indent))
fontified t face org-todo))
:todo-type todo :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 39 :MY_PROPERTY "two" :title
(#("The 1st heading" 0 15
(:parent #1)))))
(headline
(:raw-value "The 2nd heading" :begin 100 :end 122 :pre-blank 0 :contents-begin 123 :contents-end 123 :level 1 :priority nil :tags nil :todo-keyword
#("TODO" 0 4
(line-prefix "" wrap-prefix
#("* " 0 2
(face org-indent))
fontified t face org-todo))
:todo-type todo :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 100 :MY_PROPERTY "three" :title
(#("The 2nd heading" 0 15
(:parent #1)))))
(headline
(:raw-value "The 3rd heading" :begin 163 :end 185 :pre-blank 0 :contents-begin 186 :contents-end 186 :level 1 :priority nil :tags nil :todo-keyword
#("TODO" 0 4
(line-prefix "" wrap-prefix
#("* " 0 2
(face org-indent))
fontified t face org-todo))
:todo-type todo :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 163 :MY_PROPERTY "four" :title
(#("The 3rd heading" 0 15
(:parent #1))))))
```

The following query also works as expected.

```lisp
(with-current-buffer "main.org"
(pp (org-ql-select (current-buffer)
'(property "MY_PROPERTY" "two"))))
```

```
((headline
(:raw-value "The 1st heading" :begin 39 :end 61 :pre-blank 0 :contents-begin 62 :contents-end 62 :level 1 :priority nil :tags nil :todo-keyword
#("TODO" 0 4
(line-prefix "" wrap-prefix
#("* " 0 2
(face org-indent))
fontified t face org-todo))
:todo-type todo :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 39 :MY_PROPERTY "two" :title
(#("The 1st heading" 0 15
(:parent #1))))))
```

The following query shows that it is not possible to match the top level of the document.

```lisp
(with-current-buffer "main.org"
(pp (org-ql-select (current-buffer)
'(property "MY_PROPERTY" "one"))))
```

```
nil
```

# The question

- Is there any way to return the top level of the document when performing a query?

If this is not possible, I would really appreciate suggestions for my workflow so that I can query the properties of the entities that I store in headlines.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.