Search

Article Image

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.

There are multiple types of searches, all using the same search mechanism and query language:

  • Quick search which can be found in the Launch Bar for small one-off searches.
    • The results are shown in a popup and it has an infinite scroll.
  • Full search is the more advanced search mechanism.
    • The results are displayed in a separate page and it has multiple advanced features (search script, fast search, include archived notes, order by, limit).
    • Bulk Actions such as adding a label/relation can be applied to the results.
    • The results are paginated and they can be displayed in any Collections view (e.g. grid, list, calendar, table).
  • Some Collections such as board view have a dedicated search bar which applies to that collection.
    • In this case, the results are displayed directly in the collection instead of a popup and they are limited to the collection but the query language remains the same.
  • From the Launch Bar, look for the dedicated search button.
  • To limit the search to a note and its children, select Search in subtree () from the Note tree contextual menu or press Ctrl+Shift+S.
  • Go to Jump to & command palette, look for something then press Show in full search below the results (or Ctrl+Enter).

Interaction

To search for notes, click on the icon in the Launch Bar or press the keyboard shortcut.

  1. Set the text to search for in the Search string field.
    1. Apart from searching for words literally, there is also the possibility to search for attributes or properties of notes.
    2. See the examples below for more information.
  2. To limit the search to a note and its sub-children, set a note in Ancestor.
    1. This value is also pre-filled if the search is triggered from a hoisted note or a workspace.
    2. To search the entire database, keep the value empty.
  3. 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.
  4. In addition to that, the search can be configured via the Add search option menu, as described in the follow-up section.
  5. Press Search () to trigger the search. The results are displayed below the search configuration pane.
  6. The Search & Execute actions () entry in the menu beside Search is only relevant if at least one action has been added (as described in the section below).
  7. The Save to note () entry in the same menu will create a new note with the search configuration. For more information, see Saved Search.

Features

Autocomplete

To help with the syntax, Trilium offers an autocomplete functionality which can be triggered by pressing Ctrl+Space.

Some suggestions also open on their own as you type: label and relation names after # and ~, fields after ., operators, values, and notes after @. Keywords such as and, or, not, orderBy and limit appear only on Ctrl+Space, since a plain word is usually a search term.

No suggestion is selected when a list opens on its own, so Enter runs the search as typed. To insert a suggestion, select it with Down and press Enter. The list opened with Ctrl+Space and the notes after @ open on the best match instead, so Enter inserts it.

The autocomplete offers:

  • Basic operators such as *= and keywords (limit, not).
  • Fields for object-like fields such as note or ~relation, triggered by typing ..
  • Contextual enumerations such as note.type = " or note.mime = ".
  • Label names by typing #.
    • A small gear on the name's icon indicates a system attribute.
    • After typing the label name, the value is also autocompleted with values that are present in the database.
  • Relation names by typing ~.
  • Note IDs can be inserted easily by typing @ and looking for a note.
    • If the note ID is under a valid syntax, it will be shown as a chip of the note instead of the raw ID.
    • This is especially useful for queries that make use of the note ID such as searching by template: ~template.noteId = @

Syntax highlighting

The search input features syntax highlighting, making recognized fields such as note. and operators like NOT stand out.

The same highlighting is available in Code notes, for example to keep a collection of queries: set the language of the note to Trilium Search Query. The language is not enabled by default; add it from Options → Code Notes → Available MIME types in the dropdown.

Error highlighting & linting

The search is also checked for errors in two phases, which will be displayed as a red squiggle:

  • Linter errors which identify common error patterns and also provide a way to fix them.
  • Search errors which are checked by the server, without indicating the exact place the error occurred.

An error the search only runs into while running, such as an operator that note content cannot be searched with, is shown in a Search error card instead: below the search string, or at the top of the Quick search results.

Multiline

Long or complicated searches can be formatted by using newlines, similar to SQL queries. Newlines are treated just like spaces.

To add a new line, press Shift+Enter.

Search options

Click Add search option to choose an option to apply.

  • 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 button to the right of it.

The options available are:

  1. Search script
    1. This feature allows writing a Code note that will handle the search on its own.
  2. Fast search
    1. 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).
    2. This method can speed up the search considerably for large databases.
  3. Include archived
    1. Archived Notes will also be included in the results, whereas otherwise they would be ignored.
  4. Order by
    1. Allows changing the criteria for ordering the results, for example to order by creation date or alphabetically instead of by relevancy (default).
    2. It's also possible to change the order (ascending or descending) of the results.
  5. Limit
    1. Limits the results to a given maximum.
    2. This can help if the number of results would otherwise be high, at the cost of not being able to view all the results.
  6. Debug
    1. This will print additional information in the server log (see Error logs), regarding how the search expression was parsed.
    2. 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.

The same menu ends with a Bulk actions section for applying changes such as adding a label or a relation to the matched notes. Its groups—Labels, Relations, Notes and Other—each open a list of the actions in the corresponding group of the Bulk Actions dialog, which is an alternative for operating directly with notes within the Note Tree. Choosing one adds it to the search; unlike the other options, the same action can be added more than once (e.g. to apply multiple labels). After defining the actions, first press Search to check the matched notes and then choose Search & Execute actions from the menu beside it to trigger the actions.

Viewing search results

Results appear below the search pane, by default in the Search preview view. Each result is drawn as a snippet card with the note title, the path to it, a short excerpt of the matching text, and the attributes that matched. The excerpt of a code note keeps its indentation and is shown in the code font.

To show the results as a plain note list instead, choose List from the Collection Properties bar. The List view shows one row per note, with the note's title and content preview.

The search will also highlight the words from the title or content that matched:

  • With a solid underlined green for a direct match;
  • With a dotted underline orange for a partial match (matched by the fuzzy search).

In addition, the Search preview view offers:

  • The total number of results is always shown, so you can immediately tell how broad a query is.
  • A page-size selector lets you choose how many results to display per page. Your choice is remembered and synced across your devices (stored in the searchResultsPageSize option), so you do not have to reset it on every device.
  • Clicking a result's title opens the note and jumps straight to the first match. The in-note find bar opens pre-filled with the first word of your search, so you can step through its matches with the find controls. To have the find bar look for a whole phrase instead, put the phrase in quotes in the search, e.g. "The Lord of the Rings". In read-only notes, the other words of the search are highlighted as well. The excerpt and attributes can be selected without opening the note.
  • Open all results in new tabs (, the button above the results) opens every result in a tab of its own, up to 50. Each tab opens on its first match with the find bar pre-filled, as when clicking a result.
  • If a match is inside a collapsed section (for example a folded heading), that section is expanded automatically so the match is visible.
  • When the excerpt is cut short, a Show more button expands the card to the note's full content, with the search terms highlighted. Show less returns to the excerpt.

A saved search can also be Printing & Exporting as PDF from the Print/export to PDF… item of the Note menu, in either Search preview or List view. The results are laid out as a list, as they stand when printing starts.

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. Writing towers AND #book does the same; to search for the word "and" itself, put it in quotes.
  • c# or towers#book: A # or ~ inside a word is part of the text, so these find notes containing "c#" or "towers#book". To start a label or relation, put a space before it.
  • 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: Find notes with the "dateNote" label within the last 30 days. Supported date 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.
  • note.content %= '\\d{2}:\\d{2} (PM|AM)': Find notes that mention a time. Backslashes in a regex must be escaped.

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
    • People
      • J. R. R. Tolkien
        • relation: “son” points to "Christopher Tolkien" note
        • Christopher Tolkien
  • ~author.title *= Tolkien OR (#publicationDate >= 1954 AND #publicationDate <= 1960): Use boolean expressions and parentheses to group expressions.
  • towers (#genre = fantasy OR #genre = scifi): A group can open the expression part directly, without a # or ~ before the parenthesis. Here it finds notes containing "towers" whose genre is fantasy or scifi.
  • 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".
  • note.links.title = 'Tolkien': Find notes linking to a note named "Tolkien".
  • note.backlinks.title = 'Reading list': Find the notes that "Reading list" links to.
  • A link is a relation you created, such as ~author, or one that content creates: an internal link (~internalLink), an image (~imageLink), an included note (~includeNoteLink) or a relation map connection (~relationMapLink). Relations that configure a note, such as ~template or a saved search's ~ancestor, are not links.

See also Under the hood for more syntax references.

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, contentAndAttachmentsSize, contentAndAttachmentsAndRevisionsSize, 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:

  1. Find notes with the author label "Tolkien".
  2. Order the results by publicationDate in descending order.
  3. Use note.title as a secondary ordering if publication dates are equal.
  4. Limit the results to the first 10 notes.

Negation

Some queries can only be expressed with negation:

#book AND not(note.ancestors.title = 'Tolkien')

This query finds all book notes not in the "Tolkien" subtree.

Under the Hood

See the dedicated page to understand how progressive search works in Trilium, as well as some advanced use cases.

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

Search Configuration

Parameters

ParameterValueDescription
MIN_FUZZY_TOKEN_LENGTH3Minimum characters the ~= and ~* operators accept
MAX_EDIT_DISTANCE2Ceiling on character changes, reached only by 7+ character terms; shorter terms allow fewer. See the Fuzzy tolerance section above
RESULT_SUFFICIENCY_THRESHOLD5Minimum exact results before fuzzy fallback
MAX_CONTENT_SIZE10MBMaximum note content size for search processing

Limits

  • Searched note content is limited to 10MB per note to prevent performance issues
  • Notes exceeding this limit will still be included in title and attribute searches
  • Terms of 3 characters or fewer are matched exactly; typo tolerance starts at 4 characters