Blocks including both conditions A and B

Hi there :wave:

I’d like to do a query of blocks that contain some certain keywords, for example A and B.
In markdown mode, property block is defined as following:

category:: 
type:: 
related:: A
keywords:: B
tags:: 

Using following statements to query failed to return results (returned almost all blocks).

{
       :title [:h1  "A and B"]
       :query [
		:find (pull ?block [*])     
                :where
                [?block :block/properties ?p]
		([(get ?p :related) ?t]
                [(str ?t) ?st]
                [(clojure.string/includes? ?st "A")])
                (  
		[(get ?p :keywords) ?s]
                [(str ?s) ?sq]
                [(clojure.string/includes? ?sq "B")])          
         ]
         :collapsed? false			 
}

What I hope to achieve is that if it contains A and B, it can be retrieved.
Can someone assist me? Thanks.

Should remove both grouping parentheses. In Datalog, whenever parentheses are used, they indicate:

  • not a group
    • e.g. this is wrong: ([...] [...])
  • but some function
    • and they begin with the name of that function, e.g.
      • (pull ...)
      • (get ...)
      • (str ...)
      • (clojure.string/includes? ...)
      • (or-join ...)
      • etc.
1 Like

Change the value as follows:

#+BEGIN_QUERY
{
:title [:h1  "A and B"]
     :query [
	      :find (pull ?block [*])     
              :where
              [?block :block/properties ?p]
              [(get ?p :tags) ?t]
              [(str ?t) ?st]
              [(clojure.string/includes? ?st "A")]             
	      [(get ?p :related) ?s)]
              [(str ?s) ?sq]
              [(clojure.string/includes? ?sq "B")]
       ]
       :collapsed? false			 
}
#+END_QUERY

But it doesn’t work.

  • Logseq’s queries don’t forgive any syntax errors.
    • Line [(get ?p :related) ?s)] contains an excessive closing parenthesis after ?s
  • Tags are configured to turn their values into references.
    • So your ?t doesn’t contain a string, but a value like #{"A"}
    • Should replace:
      • these lines:
                      [(str ?t) ?st]
                      [(clojure.string/includes? ?st "A")] 
        
      • with this line:
                      [(contains? ?t "A")]