10 KiB
Search

Note search enables you to find notes by searching for text in the title, content, or attributes of the notes. You also have the option to save your searches, which will create a special search note which is visible on your navigation tree and contains the search results as sub-items.
Accessing the search
- From the Launch Bar, look for the dedicated search button.
- To limit the search to a note and its children, select Search from subtree from the Note tree contextual menu or press Ctrl+Shift+S.
Interaction
To search for notes, click on the magnifying glass icon on the toolbar or press the keyboard shortcut.
- Set the text to search for in the Search string field.
- Apart from searching for words ad-literam, there is also the possibility to search for attributes or properties of notes.
- See the examples below for more information.
- To limit the search to a note and its sub-children, set a note in Ancestor.
- This value is also pre-filled if the search is triggered from a hoisted note or a workspace.
- To search the entire database, keep the value empty.
- To limit the search to only a few levels of hierarchy (e.g. look in sub-children but not in sub-sub-children of a note), set the depth field to one of the provided values.
- In addition to that, the search can be configured via the Add search options buttons, as described in the follow-up section.
- Press Search to trigger the search. The results are displayed below the search configuration pane.
- The Search & Execute actions button is only relevant if at least one action has been added (as described in the section below).
- The Save to note will create a new note with the search configuration. For more information, see Saved Search.
Search options
Click on which search option to apply from the Add search option section.
- For each search option selected, the search configuration will update to reveal the entry. Each search option will have its own configuration.
- To remove a search option, simply press the X button to the right of it.
The options available are:
- Search script
- This feature allows writing a Code note that will handle the search on its own.
- Fast search
- The search will not look into the content of the notes, but it will still look into note titles and attributes, relations (based on the search query).
- This method can speed up the search considerably for large databases.
- Include archived
- Archived Notes will also be included in the results, whereas otherwise they would be ignored.
- Order by
- Allows changing the criteria for ordering the results, for example to order by creation date or alphabetically instead of by relevancy (default).
- It's also possible to change the order (ascending or descending) of the results.
- Limit
- Limits the results to a given maximum.
- This can help if the number of results would otherwise be high, at the cost of not being able to view all the results.
- Debug
- This will print additional information in the server log (see Error logs), regarding how the search expression was parsed.
- This function is especially useful after understanding the search functionality in detail, in order to determine why a complex search query is not working as expected.
- Action
- Apart from just searching, it is also possible to apply actions such as to add a label or a relation to the notes that have been matched by the search.
- Unlike other search configurations, here it's possible to apply the same action multiple times (i.e. in order to be able to apply multiple labels to notes).
- The actions given are the same as the ones in Bulk Actions, which is an alternative for operating directly with notes within the Note Tree.
- After defining the actions, first press Search to check the matched notes and then press Search & Execute actions to trigger the actions.
Simple Note Search Examples
rings tolkien
: Full-text search to find notes containing both "rings" and "tolkien"."The Lord of the Rings" Tolkien
: Full-text search where "The Lord of the Rings" must match exactly.note.content *=* rings OR note.content *=* tolkien
: Find notes containing "rings" or "tolkien" in their content.towers #book
: Combine full-text and attribute search to find notes containing "towers" and having the "book" label.towers #book or #author
: Search for notes containing "towers" and having either the "book" or "author" label.towers #!book
: Search for notes containing "towers" and not having the "book" label.#book #publicationYear = 1954
: Find notes with the "book" label and "publicationYear" set to 1954.#genre *=* fan
: Find notes with the "genre" label containing the substring "fan". Additional operators include*=*
for "contains",=*
for "starts with",*=
for "ends with", and!=
for "is not equal to".#book #publicationYear >= 1950 #publicationYear < 1960
: Use numeric operators to find all books published in the 1950s.#dateNote >= TODAY-30
: A "smart search" to find notes with the "dateNote" label within the last 30 days. Supported smart values include NOW +- seconds, TODAY +- days, MONTH +- months, YEAR +- years.~author.title *=* Tolkien
: Find notes related to an author whose title contains "Tolkien".#publicationYear %= '19[0-9]{2}'
: Use the '%=' operator to match a regular expression (regex). This feature has been available since Trilium 0.52.
Advanced Use Cases
~author.relations.son.title = 'Christopher Tolkien'
: Search for notes with an "author" relation to a note that has a "son" relation to "Christopher Tolkien". This can be modeled with the following note structure:- Books
- Lord of the Rings
- label: “book”
- relation: “author” points to “J. R. R. Tolkien” note
- Lord of the Rings
- People
- J. R. R. Tolkien
- relation: “son” points to "Christopher Tolkien" note
- Christopher Tolkien
- J. R. R. Tolkien
- Books
~author.title *= Tolkien OR (#publicationDate >= 1954 AND #publicationDate <= 1960)
: Use boolean expressions and parentheses to group expressions. Note that expressions starting with a parenthesis need an "expression separator sign" (# or ~) prepended.note.parents.title = 'Books'
: Find notes with a parent named "Books".note.parents.parents.title = 'Books'
: Find notes with a grandparent named "Books".note.ancestors.title = 'Books'
: Find notes with an ancestor named "Books".note.children.title = 'sub-note'
: Find notes with a child named "sub-note".
Search with Note Properties
Notes have properties that can be used in searches, such as noteId
, dateModified
, dateCreated
, isProtected
, type
, title
, text
, content
, rawContent
, ownedLabelCount
, labelCount
, ownedRelationCount
, relationCount
, ownedRelationCountIncludingLinks
, relationCountIncludingLinks
, ownedAttributeCount
, attributeCount
, targetRelationCount
, targetRelationCountIncludingLinks
, parentCount
, childrenCount
, isArchived
, contentSize
, noteSize
, and revisionCount
.
These properties can be accessed via the note.
prefix, e.g., note.type = code AND note.mime = 'application/json'
.
Order by and Limit
#author=Tolkien orderBy #publicationDate desc, note.title limit 10
This example will:
- Find notes with the author label "Tolkien".
- Order the results by
publicationDate
in descending order. - Use
note.title
as a secondary ordering if publication dates are equal. - Limit the results to the first 10 notes.
Negation
Some queries can only be expressed with negation:
#book AND not(note.ancestor.title = 'Tolkien')
This query finds all book notes not in the "Tolkien" subtree.
Under the Hood
Label and Relation Shortcuts
The "full" syntax for searching by labels is:
note.labels.publicationYear = 1954
For relations:
note.relations.author.title *=* Tolkien
However, common label and relation searches have shortcut syntax:
#publicationYear = 1954
#author.title *=* Tolkien
Separating Full-Text and Attribute Parts
Search syntax allows combining full-text search with attribute-based search seamlessly. For example, tolkien #book
contains:
- Full-text tokens -
tolkien
- Attribute expressions -
#book
Trilium detects the separation between full text search and attribute/property search by looking for certain special characters or words that denote attributes and properties (e.g., #, ~, note.). If you need to include these in full-text search, escape them with a backslash so they are processed as regular text:
"note.txt"
\#hash
#myLabel = 'Say "Hello World"'
Escaping Special Characters
Special characters can be enclosed in quotes or escaped with a backslash to be used in full-text search:
"note.txt"
\#hash
#myLabel = 'Say "Hello World"'
Three types of quotes are supported: single, double, and backtick.
Type Coercion
Label values are technically strings but can be coerced for numeric comparisons:
note.dateCreated =* '2019-05'
This finds notes created in May 2019. Numeric operators like #publicationYear >= 1960
convert string values to numbers for comparison.
Auto-Trigger Search from URL
You can open Trilium and automatically trigger a search by including the search url encoded string in the URL:
http://localhost:8080/#?searchString=abc