Skip to content

Org SuperTag Query User Guide

yibie edited this page Jul 28, 2025 · 1 revision

Top Options

  • Tail: Empty list ^:nil
  • Startup: Show everything showeverything

Overview

Org SuperTag Query provides two different query methods:

  1. File-internal query expression – Write the query directly in the org file; after execution, results are inserted into the file.
  2. Interactive query retrieval – Use an interactive interface to search, with results displayed in a dedicated buffer.

File-Internal Query Expression

This method allows you to embed query expressions directly in the org file. After execution, results are inserted below the query block.

Basic Syntax

#+BEGIN_SRC org-supertag-query  
query-expression  
#+END_SRC  

Examples

Simple tag query

#+BEGIN_SRC org-supertag-query  
(tag "project")  
#+END_SRC  

Complex condition query

#+BEGIN_SRC org-supertag-query  
(and (tag "work") (field "status" "done"))  
#+END_SRC  

Keyword search

#+BEGIN_SRC org-supertag-query  
(term "idea")  
#+END_SRC  

Exclude specific tag

#+BEGIN_SRC org-supertag-query  
(not (tag "archive"))  
#+END_SRC  

Usage Method

  1. Insert a query block in the org file.
  2. Place the cursor inside the query block.
  3. Press "C-c C-c" to execute the query.
  4. Results will be inserted below the query block.

Shortcuts

  • "C-c C-c": Execute the current query block.
  • "M-x org-supertag-insert-query-block": Insert a new query block interactively.

Interactive Query Retrieval

This method uses an interactive interface to search, with results displayed in a dedicated query buffer.

Keyword Search

Usage

  1. Call "M-x org-supertag-query-interactive" or "M-x org-supertag-query".
  2. Enter keywords (multiple keywords separated by spaces).
  3. View results in the dedicated query buffer.
  4. Perform selection, navigation, or export operations.

Example Keywords

  • "project": Search for nodes containing "project".
  • "idea work": Search for nodes containing both "idea" and "work".
  • "urgent": Search for nodes containing "urgent".

S-expression Search

Usage

  1. Call "M-x org-supertag-query-interactive-sexp".
  2. Enter an S-expression query.
  3. View results in the dedicated query buffer.
  4. Perform selection, navigation, or export operations.

Example S-expressions

  • "(tag "project")": Search for nodes with the "project" tag.
  • "(and (tag "work") (field "status" "done"))": Search for nodes satisfying both conditions.
  • "(not (tag "archive"))": Search for nodes without the "archive" tag.

Shortcuts

  • "C-c C-q": Start interactive keyword search.
  • "C-c C-s": Start interactive S-expression search.

Query Result Operations

In the query results buffer, you can:

  • "n/p": Navigate to next/previous result.
  • "SPC": Toggle selection.
  • "RET": Visit the selected node.
  • "i": Insert a link to the selected node in its original location.
  • "e f": Export to a specified file.
  • "e n": Export to a new file.
  • "q": Exit the query buffer.

Query Expression Syntax

Basic Queries

  • "(tag "tag-name")": Search by tag.
  • "(property "prop-name" "prop-Value")": Search by property.
  • "(term "keyword")": Full-text search in headings and content.

Logical Operations

  • "(and expr1 expr2 ...)": AND operation.
  • "(or expr1 expr2 ...)": OR operation.
  • "(not expr)": NOT operation.

Time-based Queries

You can now include time conditions to retrieve nodes created before, after, or within a specific timeframe.

Operators

  • "(before "date")": Find nodes created before this date.
  • "(after "date")": Find nodes created after this date.
  • "(between "start-date" "end-date")": Find nodes created between two dates.

Date Formats

Date arguments can be in one of three formats:

  1. Absolute date: A string in ""YYYY-MM-DD" format (e.g., "2023-10-26").
  2. Relative date: A string with "+" or "-", a number, and a unit (e.g., "-7d" for 7 days ago).
  3. Current time: Use the string "now".

Syntax Notes

  • All string arguments in the query must be enclosed in double quotes (").

Examples

Find all work projects

#+BEGIN_SRC org-supertag-query :results raw
(and (tag "work") (tag "project"))
#+END_SRC

Find completed tasks

#+BEGIN_SRC org-supertag-query :results raw
(and (tag "task") (field "status" "done"))
#+END_SRC

Find notes created last week

#+BEGIN_SRC org-supertag-query :results raw
(between "-7d" "now")
#+END_SRC

Find all Emacs-related projects created after 2023

#+BEGIN_SRC org-supertag-query :results raw
(and
  (tag "project")
  (term "Emacs")
  (after "2023-12-31"))
#+END_SRC

Notes

  1. Ensure the database is initialized and synced ("M-x org-supertag-sync").
  2. File-internal query expressions use S-expression syntax; use "M-x org-supertag-insert-query-block" to create properly formatted blocks.
  3. Interactive query retrieval uses simple keyword searches.
  4. All string arguments in S-expressions (tags, property values, dates) must be enclosed in double quotes (").