[Learn Log] Getting the most out of Logseq by understanding queries

Here’s a spot for my query learning sprint log! I’ll be working on populating this with a proper plan tomorrow, but for now here’s a bit about why I’m here.

I started using Logseq about a month ago. I moved from Obsidian, where I was finding more friction that would be ideal in my workflow. I think, for me, Logseq is a better fit because (1) it operates with a journal as a homepage, whereas daily notes are an external plugin for Obsidian; and (2) queries are built-in, as opposed to by plugin (dataview) in Obsidian. It’s also a huge plus that Logseq is open source!

I think part of the reason #2 was such a big sticking point for me is that, before I used Obsidian, I was using Notion. I made extensive use of the databases and rollups available in Notion, but relying on the cloud was a dealbreaker for me. Notion had an outage one day and it basically destroyed my workflow that day, and a recent country-wide outage of Canada’s biggest telecom company reinforced my need for offline capabilities.

What made Notion click for me was learning how to use databases and rollups to make a recipe collection, grocery tracker, and meal planner that all worked together. I’ve been longing to have that back, so I’m hoping to develop a Logseq version over the next couple weeks, as well as streamlining my to-dos and note processing workflows.

3 Likes

Welcome to the forum an learning sprint @ashinonyx!

Logseq queries are not as easy as Notion’s point-and-click tables, but hopefully they’re just as powerful once you discover Datalog. Personally I hope that one day we’ll have a visual query builder tool that will rival Notion’s GUI.

Thanks, Ramses!

Here’s my learning plan. I used Ramses’ and thatgothlibrarian’s learn logs as references when developing my own.

My goal: learn how to get the most out of Logseq by understanding what I can do with queries

I find the best way for me to learn new software is to build something that is useful to me and leverages some of the more complex abilities of that software. Queries seem to me like the most complex - and powerful - built-in feature of Logseq.

I’m still new to Logseq, so my overarching goal is to use this sprint to brainstorm what kinds of useful things I can build for myself with queries. But, since I also want to get some hands-on practice, I’m also going to be building something I used to have in Notion and loved: a recipe manager, grocery manager, and meal planner. The idea is to be able to use queries to see what I’ve liked in the past, what recipes use ingredients I have on-hand, what staple ingredients are low, what I need to buy this week, and more! I think this will need use for both simple queries and advanced queries.

My learning plan

What is my target performance level? What is good enough?

  • Good enough for recipe stuff: a system that I will actually want to use. It’s okay if it still needs some more work, as long as I have an idea of how I might be able to fix it in the future and it’s useable for now.
  • More broadly, I’d like to feel like I know how to do things in queries, or at least know where to look

What are the subskills of this skill? What are the smaller skills I need to master first, and in what order?

  • Understand the difference between simple and advanced queries (jot down some ideas for each as you learn!)
  • Understand properties, namespaces, hierarchy, tagging, etc. (i.e., ways to organize or structure your data)
  • Boolean logic
  • (more to be added as I learn)

What are critical tools? What tools do I need every time I want to learn theory or practice applying it?

What are my learning resources? What are my primary sources of information about this skill?

How will I create feedback loops for myself? Here I’ll think of ways to practice so I’ll challenge myself.

  • If I can, come up with a way to implement the skill in my own workflow
  • If not, copy the example in the resource so I can replicate the results

What are my potential barriers to practice? Think high pre-practice effort, distractions, emotional blockers.

  • Stress - I’m a PhD student trying to finish my thesis, so stress is happening and one of my (very unhelpful) stress responses is to do nothing at all
  • Motivation - I like learning this kind of stuff, so this may be less of an issue, but my motivation does tank in response to stress & mood
  • My attention span is worse for videos than for text, and it looks like a lot of the simple query resources out there are videos

How long will my learning project take?

Until 2022-07-31T04:00:00Z

How much time am I going to spend learning and practicing deliberately each week?

  • Aim for at least 1 hour each day, split between learning and application
  • I expect the ratio of the above to shift from more learning to more application as the sprint progresses

When am I going to study or practice each day? Here I think about what are the best times for me in the day and week to learn and practice.

Likely in the afternoon/evening. My brain doesn’t work in the morning.

Have I reserved my learning sessions in my calendar?

Yes. They’re currently all scheduled for 2pm.

3 Likes

Ohhh … very interested in this! I just started creating my own recipe graph. I look forward to learning how you set yours up. I’m fairly new to Logseq and am wading through what it’s capabilities are.

1 Like

Here’s my notes from today’s learning session:

  • I got bogged down over the last few days (after I made my learning plan) by getting some of the things done for my queries to actually do anything useful. I’m still not done that, but I really should get to learning queries syntax and all that jazz
  • Starting small today: let’s just work our way through the documentation’s page on queries
  • Simple queries all use the syntax {{query [that thing you want to know]}}
  • Advanced queries use [[Datalog]], a declarative logic programming language, implemented here in [[ Clojure]], a dialect of [[Lisp]]
    • Do I fully understand what all this means yet? No, but hopefully we will get there! I have at least heard of lisp before (though I haven’t used it), so there’s that!
  • Simple queries operate using boolean logic filters to help refine what it is you’re searching for:
    • and will match only things that fit all the criteria laid out in your query. It helps decrease the number of search results you’ll get

      • From Boolean logic 101: “Imagine you’re searching a library catalog, a search engine, a database, or even your notes. You want to see everything you have about ‘ghosts’, so you search the keyword ghosts. Let’s say you get 100 results from that. That’s a lot! You realize you actually only wanted to see results about ghosts in Shakespeare plays. You want to decrease your results. You search for ghosts AND Shakespeare. Now you only get 20 results.”
      • Let’s say I want to query papers that talk about both #Smilodon/fatalis and #Panthera/atrox , since they’re sometimes (but not always) found in the same localities. I don’t have my paper notes all properly stored in Logseq yet, so this won’t totally work, but it should at least pull up this block! (it does)
        • {{query((and [[Smilodon/fatalis]] [[Panthera/atrox]] ))}}
    • or does the opposite, and will match things that fit any of the criteria in your query. It will increase the number of search results you’ll get

      • From Boolean logic 101: “OR increases the number of search results. In a Venn diagram, OR brings us the entirety of both circles and where they overlap. This OR is not exclusionary, meaning results can contain both or either.”
      • Maybe I want any paper on any of the three species of Smilodon, including specimens not diagnosed beyond the genus level?
      • {{query((or [[Smilodon]] [[Smilodon/fatalis]] [[Smilodon/gracilis]] [[Smilodon/populator]] ))}}
    • not will reduce the number of search results you get by excluding anything that matches this particular criterion

      • From Boolean logic 101: “Now you want to see results that are about ghosts but not about Shakespeare. You search ghosts NOT Shakespeare. If our original search for ghosts was 100 results, and if our search for ghosts AND Shakespeare was only 20 notes, then the number of notes about ghosts but not about Shakespeare is 80. In a Venn diagram, this query would be only the part of the ghost circle that didn’t overlap with the Shakespeare circle”
      • Now let’s say I want to see anything that talks about #Smilodon/fatalis but not Panthera atrox. These may indicate places where further field work may find some P. atrox fossils, or they may be localities outside the latter’s range, which would be cool (and is probably the case in South America)
      • {{query((and[[Smilodon/fatalis]] (not [[Panthera/atrox]] )))}}
    • between works only for blocks on the journal page, and searches (surprisingly /s) for entries between the date ranges you supply it

      • Let’s see if I can make a query that returns learn logs from the last week
      • {{query((and [[learn log]] (between -7d today)))}}
    • page will search for specific page names only. I have used this in conjunction with not to get [[Active Todos]] to show only active tasks not including the recurring ones on my templates page

1 Like

Notes from 2022-07-20T04:00:00Z

  • Continuing with reading and understanding the Logseq queries documentation

    • Clarification: and, or, and not are operators, while things like between and page are filters
    • Clarification #2: you can list specific dates in the between filter, e.g. {{query (between [[July 15th, 2022]] [[July 31st 2022]])}}
    • Let’s continue learning filters:
      • property allows for filtering within block properties (page properties can also be filtered, see below)
        • this uses the syntax property ([property key] [property value]), with the property key being something like “type”, “author”, etc. and the value being the value for that block. These are specified in block properties as [key]:: [value], e.g., type:: book
        • I don’t have anything with block properties yet, so won’t test this directly now, but I think it should work easily, especially as long as I can get page properties to work
      • full-text queries can be done by simply adding the search term in quotation marks after the query command, e.g., {{query "search term"}}. This will include the search term both inside and outside of links
        • I’m going to try searching for the term “EDI” since I know I have it unlinked in spots
        • {{query(“EDI”)}}
      • task will search for - you guessed it! - tasks, and takes Logseq’s task types (todo, now, later, etc.) as an argument. An example is {{query (task now todo)}}, which will pull all tasks that are listed as TODO or NOW
        • {{query((task now todo))}}
      • priority will similarly search for the different priority tags used by Logseq. I don’t use these currently (though tbh I probably should), so I won’t test that now
      • page-property works just like property but searches pages. It also takes the key and value as arguments
        • I know I can search this one using my [[Readwise]] imports. I’m going to search for pages with the author property of [[Mark S. Boyce]]
          • {{query((page-property author [[Mark S. Boyce]] ))}}
      • page-tags allows you to search for a specific page property: tags. I’ll probably use this later for tagging paper notes/highlights with tags as outlined in my [[Tagging SOP]]
        • all-page-tags lists all your page tags! Neat! I don’t have any yet, so this query turns up blank for me.
        • {{query((all-page-tags))}}
    • You can also sort the results of any simple query using sort-by
      • This takes two arguments, key and order: {{query (sort-by key order)}}
        • key is whether you would like to sort by created-at or updated-at
        • order can be asc or desc and defaults to desc if omitted
  • Now I’ll read [[Jay Colbert]]'s guide to his [[Zettelkasten]] workflow

    • TODO add link to Readwise highlights once they’re imported
    • Lots of interesting queries here, though (a) I haven’t been using a [[Zettelkasten]] and (b) the syntax suggests these are advanced queries, but they also look like they’re simple queries with some extra commands for their display. Maybe revisit once I’m ready for advanced queries
    • I’m still not sure how I’d like to go about using blocks vs pages. Seems like lots of the tips here should work either way, but I’m not entirely sure
      • #question: when you give block properties to a block containing a link to a page, does the page inherit those properties? I suppose not, or else that would break [[Jay Colbert]]'s pretty graph?
  • I should also catch up on the talk on simple queries from today since I had a lazy morning and missed it

    • [Queries Learning Sprint] Week 2: Simple queries — Understanding Logseq’s outline logic and searchin - YouTube
    • Hosted by [[Ramses Oudt]] and [[Bas Grolleman]]
    • Some of the most popular use cases:
      • task/project management
      • content creation
      • learning new skills
    • Can use <% current-page %> in queries (and save that query) and use that to run the same query on multiple pages without changing anything
      • #question: does this need to be wrapped in an and operator with the query value(s)? My assumption is yes?
    • What is a query language?
      • Need some way to tell a computer what to look for
      • Googling is querying! And Google is a database of webpages.
      • Logseq is a database that creates, reads, and edits your markdown files; those files have metadata associated
      • Our queries are telling the Logseq database what we want to see
      • Logseq has two data languages: Datalog for advanced queries and “simple queries”
        • BUT under the hood, simple queries are “preprogrammed” queries, making things easier for the end user
    • Clojure, which is what Logseq queries use, is written slightly differently from most programming languages, which is why the function comes first (e.g. and x y instead of x and y)
      • This sounds like some operations in R tbh, at least in the sense that I’m used to telling R what function I want first, then passing along the data
      • I think the key here is that Clojure operates differently from natural language (at least in English)
    • Bug: queries currently don’t look properly up or down the hierarchy - i.e., it’s only looking for tags in one block and doesn’t include child blocks
      • Ramses says this should be fixed in the next update, so I wonder if it’s done now? There was an update this morning, but that might have been before this talk
        • Nope - we’re using the same version
    • Simple queries are quick and simple, so easiest to write them as you need them
    • Adding to my [[ideas for simple queries]]:
      • book log
      • video game log
      • knitting/sewing/etc project log
      • [academic] project log
      • TODO do some work on what metadata would be useful for the types of pages you’re creating or planning to create
    • Can simple queries access logbook (e.g., time tracking, created at, etc.) entries?
      • There are some workarounds, e.g., creating properties for each thing you want to log (such as minutes spent practicing a language) and using plugins that help visualize this information
      • Can at least do this with advanced queries (will also live update, unlike above), but not for simple queries yet?
    • some fun new things with page (and block??) properties:
      • can click on the key to open it as a page
      • can type :: to get a list of all your properties
  • Side note: I really appreciate how much Logseq feels like a community project. I mean it is, because it’s open source software, but it’s just great to see how responsive the team is to the community’s ideas.

  • I’ll be changing my query learning times to be in the evening, around 8pm. I swear the closer to programming a task is, the more I enjoy doing it at night, haha.

1 Like

Notes from 2022-07-21T04:00:00Z

  • Woke up at around 4am with thoughts on what I should be using queries for and how to implement them. That’s great for my learning, but maybe not so great for my sleep lol

  • Added a recipe template to [[templates]]

    ```
    	  	- title::
    	  	  category:: #recipe
    	  	  status:: #todo #done
    	  	  banner:: "https://images.unsplash.com/photo-1577986195822-9ae6c87430e8?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8"
    	  	  page-icon:: 👩🏻‍🍳🥘
    	  	  recipe-url::
    	  	  recipe-author::
    	  	  recipe-thoughts:: #recipe/try, #recipe/meh, #recipe/okay #recipe/love, #recipe/favourite, #recipe/staple
    	  	  recipe-ingredients::
    	  	  recipe-preptime::  
    	  	  recipe-cooktime::
    	  	  recipe-standtime::
    	  	  recipe-totaltime:: 
    	  	  recipe-servings::
    	  	  cook-on::
    	  	  tags::
    	  	  recipe-photo::
    	  	- # Ingredients
    	  	-
    	  	- # Directions
    	  	-
    	  	- # Notes
    	  	-
    ```
    
    • #question: why do the page properties get re-ordered when the block is in view mode? do not like!
  • Also added a grocery template

    ```
    	  	- title::
    	  	  category:: #grocery
    	  	  status:: #todo #done
    	  	  banner:: "https://images.unsplash.com/photo-1573518011645-aa7ab49d0aa6?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1974&q=80"
    	  	  page-icon:: 👩🏻‍🍳🛒
    	  	  grocery-stock::
    	  	  grocery-type::
    	  	  grocery-store::
    	  	  grocery-needed::
    	  	  grocery-cost::
    	  	- # Recipes with this Ingredient
    	  	- {{query (page-property recipe-ingredients <% current page %> )}}
    ```
    
  • Going to add some recipes so I can get started with some simple queries. These are recipes that were either categorized as favourites or ones to try in my old Notion system.

    • [[Caramelized Cauliflower Cacio e Pepe]]
    • [[Roasted Brussels Sprout Pasta]]
    • [[Butternut Squash Risotto]]
    • [[Toasted Naan]]
    • [[Roasted Jalapeno Hummus]]
    • [[Tofu Bacon]]
  • Have a simple query going to put on the tag pages for specific page properties, all making use of <% current page %> (NOTE TO SELF: there is no hyphen in “current page”!)

    • {{query (page-property category <% current page %>)}}
    • {{query (page-property recipe-thoughts <% current page %>)}}
    • {{query (page-property recipe-author <% current page %>)}}
    • {{query (page-property recipe-ingredients <% current page %>)}}
    • {{query (page-property tags <% current page %>)}}
    • {{query (page-property grocery-stock <% current page %>)}}
    • {{query (page-property grocery-type <% current page %>)}}
  • These are the things I want my recipe system to do, and if I think they can be done with simple or advanced queries (though I haven’t even gotten into learning advanced queries yet)

    • Simple queries
      • See at a glance which recipes I want to try, and which are ones I’ve made before and liked (done)
      • See at a glance which recipes use ingredients I already have on-hand (done)
      • Tell which staple groceries (like oil, salt, pepper, etc.) are running low or out of stock - should just need to add a tag for staple groceries
      • See which recipes I want to make within a specific time frame (to help plan grocery trips) - should be doable with simple queries, using a combination of page properties and between?
      • See which produce are currently in season
    • Advanced queries
      • Tell which groceries are in a planned recipe AND are low/out of stock
        • I can’t think of how to do this with simple queries, but I’m still a novice so please tell me if I’m wrong!
      • Figure out which recipes have all ingredients in stock, or are missing only a few ingredients
3 Likes