I was wondering if there is a way to gather questions with Logseq. Because quite often I find myself posting questions to myself and/or my colleagues, that I would research before posting somewhere.
In a similar manner like a TODO, but instead a QUESTION for example. Ideally with some nice rendering.
Also with query support, like TODO has. For example: {{query (and (todo todo) (between -21d today))}}
but instead one would write {{query (and (question question) (between -21d today))}}
I can imagine this would be also useful in combination with page references. Something like this
QUESTION [[Nick]] why do you like Logseq so much?
then a query to get all of the question to Nick would be
{{query (and (question question) [[Nick]])}}
I bet there is another way to collect people/project related questions with Logseq, I would love to hear your way of doing it, please share.
You can just use a tag, I use #q
and if I have an answer I add #a
as a child-block
Then you can search {{query (and [[q]] (between -7d today))}}
You can use CSS to make a question look different:
[data-refs-self='["q"]'] > .flex-row {
font-weight: bold;
}
4 Likes
@Alex_QWxleA thanks for the idea! It actually what I am looking for.
Unfortunately, custom css you have posted does not change any appearance of the blocks with #q tags. I’ve tried also experimenting with it, changing color an so on, but no effect also after restarting logseq. Any ideas what might be missing there?
[data-refs-self='["q"]']>.flex-row {
font-weight: bold;
color: red;
}
Copied it straight from my setup, but this should be the “correct” way:
[data-refs-self*='"q"']>.flex-row {
font-weight: bold;
color: red;
}
See: [attribute] | CSS-Tricks - CSS-Tricks
You can use the inspector to see what is being used. It is a bit finicky, but possible
1 Like
@Alex_QWxleA thanks! It works!
How would you implement css to color it in green only if a block has #q and #a reference in it?
Something like this should work:
[data-refs-self*='"q"']>.flex-row {
font-weight: bold;
}
[data-refs-self*='"a"'] > .flex-row {
font-style: italic;
}
[data-refs-self*='"q"'][data-refs*='"a"'] {
background-color: rgb(243, 240, 230);
}
unfortunately that does not work. For some reason it’s not picking up that line:
[data-refs-self*='"q"'][data-refs*='"a"'] {...}
any idea what might be wrong?
No idea, maybe a typo somewhere?
This is an empty graph, custom.css (copied from my previous message):
This is the result:
1 Like
that works! Needed just some minor adjustments. Final css:
[data-refs-self*='"q"']>.flex-row {
font-weight: bold;
color: #e67a00;
}
[data-refs-self*='"a"']>.flex-row {
font-weight: bold;
color: #6a994e;
}
[data-refs-self*='"q"'][data-refs*='"a"'] {
background-color: rgba(243, 240, 230, 0.2);
}
Any idea how would I query for all unanswered questions? Writing something like this:
{{query (and [[q]] (not [[a]]))}}
unfortunately returns all blocks marked #q even if one of the children blocks contains #a reference. How would you fix it?
This was a tricky one to figure out, but thanks to Darvis at the forum:
#+BEGIN_QUERY
{:query [:find (pull ?b [*])
:where
[?b :block/refs [:block/name "q"]]
(not-join [?b]
[?child :block/parent ?b]
[?child :block/refs [:block/name "a"]]
)
]
}
#+END_QUERY
1 Like
Thank you!!! Can you recommend some tutorials about queries? Everything I’ve watched on Youtube was about {{query}}
syntax, but it looks like there is way more… your solution looks more like SQL
This is my own page, sorry about that : https://qwxlea.github.io/#/page/datalog%2Fintro%20to%20datalog
If you have questions or comments you can do that here or on twitter (or Discord)
1 Like
Hey Alex, can you please help me figure out how to add another reference to the initial query? All unanswered questions with a reference to a person
#+BEGIN_QUERY
{:query [:find (pull ?b [*])
:where
[?b :block/refs [:block/name "q"]]
[?b :block/refs [:block/refs ?"Nick"]]
(not-join [?b]
[?child :block/parent ?b]
[?child :block/refs [:block/name "a"]]
)
]
}
#+END_QUERY
I’ve tried the one above, but somehow it doesn’t seem to work…
This also doesn’t work for me. Perhaps @Alex_QWxleA has an updated version?
I’ve found out that there is a bug in queries. It looks like in the future version, we will be able to accomplish this with a simple “AND/NOT” Query. Here is a video on YouTUbe with timestamp, where this bug is discussed: [Queries Learning Sprint] Week 2: Simple queries — Understanding Logseq’s outline logic and searchin - YouTube
:block/refs
contains the ID of other blocks, so you can’t do something like [:block/refs ?"Nick"]
. You can try this query instead.
#+BEGIN_QUERY
{:query [:find (pull ?b [*])
:where
[?b :block/refs [:block/name "q"]]
[?b :block/refs [:block/name "nick"]]
(not-join [?b]
[?child :block/parent ?b]
[?child :block/refs [:block/name "a"]]
)
]
}
#+END_QUERY
Also remember that :block/name
will only accept lowercase characters. So pass “Nick” as “nick”.