旧搜索 - baddate/trilium GitHub Wiki

本文档介绍了0.43及更老版本中使用的搜索语法。有关最新语法,请参见搜索

Trilium支持在笔记中搜索。有几种搜索笔记的方法:

  • 本地搜索 - 在当前显示的笔记中搜索。按CTRL - F打开搜索对话框。在服务器版本中,这由浏览器处理;在桌面版(Electron版)中,有一个单独的对话框。
  • 全文搜索 - 搜索文本和代码笔记内容。由于此操作是通过数据库搜索实现的,因此仅适用于不受保护的笔记(无论您是否处于受保护的会话中都没关系)
  • 属性搜索 - 例如,您可以搜索具有特定标签的笔记 - 请参阅下面的属性查询语法
  • 您可以将搜索字符串(由全文搜索或属性搜索组成)保存到被称作的"saved search"笔记中。如果展开此笔记,您将看到搜索结果作为子笔记。
  • 保存的搜索还可以通过关系引用脚本 - 展开后,脚本将提供结果列表

您可以通过单击左侧的放大镜图标或按CTRL - S键盘快捷键来激活搜索。

全文

每当搜索字符串不是以@(用于属性搜索)或=(用于脚本保存的搜索)开头时,就会触发全文搜索。

全文搜索未归档的未删除,未受保护的文本笔记和代码笔记的标题和内容。

输入字符串由空格分隔符标记,并且每个单独的token(单词)必须出现在标题或内容中。如果您不希望这种自动标记,可以在搜索中用双引号引起来,例如"hello world"将搜索完全匹配。

属性查询语法

标准属性

在这里,您可以按标准属性进行查询:

  • @abc - 返回带有标签abc的笔记
  • @!abc - 返回没有标签abc的笔记
  • @year=2019 - 匹配具有标签year的值为2019的笔记
  • @year!=2019 - 匹配带有标签year,但值不是2019或根本没有标签year的笔记。
    • 如果您想表达条件: 笔记必须带有year标签,但值不是2019,则可以使用@year @year!=2019
  • @year<=2000 - 返回标签year值为2000或更小的笔记。><>=<=d都是支持的。
    • 在这种情况下,参数可以解析为数字,因此可以进行按数字比较。但是也可以以相同的方式按字典顺序比较字符串。如下所示,这对于比较日期很有用。
  • @rock @pop - 匹配同时带有rockpop标签的笔记
    • @rock and @pop 是另一种替代语法
  • @rock or @pop - 只能有一个标签
    • 在搜索字符串中使用两个运算符的情况, and优先级高于or
  • @frontMan=*John - 匹配frontMan标签以"John"开头的笔记。还有!=*b表示"不以…"开头,*=表示"以…结尾"和!*="不以…结尾",*=*表示"包含"和!*=*表示"不包含"

虚拟属性

也可以通过所谓的"虚拟属性"进行查询:

  • dateCreated - 笔记创建日期的本地日期,格式为YYYY-MM-DD HH:mm:ss.sss + OOPP,其中OOPP是相对于UTC的小时和分钟偏移量(例如,中欧时间为"+0100")
  • dateModified - 在YYYY-MM-DD HH:mm:ss.sss + OOPP中对最后一个音符进行修改的本地日期
  • utcDateCreated - 笔记创建日期的UTC日期,格式为YYYY-MM-DD HH:mm:ss.sssZ
  • utcDateModified - 最后一个笔记的修改日期的UTC日期,格式为YYYY-MM-DD HH:mm:ss.sssZ
  • noteId
  • isProtected - 如果笔记受保护,则为1,否则为0
  • title - 如果要单独搜索标题,则很有用
  • content
  • type - ,textcode,,或者imagefilesearchrelation - map
  • mime - 例如text/html表示文字笔记
  • text - 标题和内容的全文属性
    • 例如@text*=*Hello。这样您就可以同时搜索文本和属性。
  • isArchived - 仅过滤归档笔记@!archived然后仅过滤未归档的笔记。请注意,此过滤器在OR关系中不起作用,它始终为AND。
  • in - 例如,@in=VuvLpfAPx2L9将仅过滤那些具有noteId为VuvLpfAPx2L9的笔记作为祖先之一的笔记 - 即笔记在VuvLpfAPx2L9的子树中。使用否定运算符 - @in!=VuvLpfAPx2L9将过滤没有笔记VuvLpfAPx2L9作为其祖先的笔记。始于Trilium 0.37版本

顺序和限制

可以通过一个或多个属性对结果进行排序,例如,@orderBy=year, - genre将按year标签的升序对笔记进行排序,然后按genre标签的降序(由于-符号)对笔记进行排序。

您也可以使用例如:@limit=1仅返回第一个结果来限制结果的数量。如果没有limit,则返回所有笔记。

日期比较

属性值是无类型的字符串,这意味着尽管您可以将诸如数字或日期之类的任何值保存到其中,但是Trilium并不真正知道它是什么类型的值,因此也无法对其进行正确处理。

幸运的是,如果我们坚持以YYYY-MM-DD格式存储日期,我们仍然可以做很多事情,因为这些日期可以作为字符串正确地比较 - 例如@dateCreated>=2015 - 01 - 01,即使Trilium仅进行字符串比较,也将返回自2015年以来创建的笔记。

如果要查找2015年创建的笔记该怎么办?您可以像这样使用"以…开头"运算符(=*):@dateCreated=*2019 - 这将匹配带有以"2019"开头的标签的笔记,该年份创建的所有笔记都将满足。

智能过滤器

Trilium支持一些特殊值,这些特殊值可能会帮助您进行一些搜索查询:

  • NOW 表示此刻且达到秒精度,例如 2019 - 04 - 01 10:12:54
    • NOW - 3600 表示1小时前
  • TODAY 表示今天且精度为天,例如 2019 - 04 - 01
    • TODAY - 1意味着昨天,TODAY+1意味着明天
  • MONTH 表示本月,例如 2019 - 04
    • MONTH - 1 指上个月 - 即 2019 - 03
  • YEAR 表示当前年份,例如 2019
    • YEAR - 1 表示去年 - 2018年

使用此方法,您可以创建查询,例如:

  • @dateModified>=NOW - 3600 - 告诉我过去一小时内更改过的笔记
  • @dateCreated=*TODAY - 1 - 告诉我昨天整个期间创建的笔记

保存的搜索

Trilium提供了一种将常用搜索另存为笔记树中的笔记的方法。搜索结果将作为此"saved search"笔记的子笔记出现。您可以看到它是如何工作的:

使用脚本关系保存搜索

如果保存的搜索字符串以开头=,则将以下字符串用作关系名称,并执行目标脚本以获取音符结果列表。

因此,假设搜索字符串为=handler,然后Trilium尝试找到具有名称为"handler"关系的保存笔记。关系应该指向稍后执行的脚本 - 脚本应该返回的那些应作为搜索结果的笔记列表。对于正常的属性/全文搜索不能满足所有需求的用例,可以选择这个方法。

从URL自动触发搜索

像下面的示例一样,打开Trilium将打开搜索窗格并自动触发搜索"abc":

http://localhost:8080/#search=abc

=====================================

This document describes search syntax as used in versions 0.43 and older. For up-to-date syntax see Search.

Trilium supports searching in notes. There are several ways to search notes:

  • local search - searches within currently displayed note. Press CTRL-F to open the search dialog. In server version this is handled by the browser, in desktop (electron) version there's a separate dialog.

  • full text search - search in text and code note content. Since this is implemented as a database search, this works only for not protected notes (doesn't matter if you're in protected session or not)

  • attribute search - you can e.g. search for notes having certain label - see Attribute query syntax below.

  • you can save search string (composed of either fulltext or attribute search) into so-called "saved search" note. If you expand this note, you will see the search results as child notes.

    • saved search can also reference script through relation - upon expanding, the script will provide a list of results

You can activate search by clicking on magnifier icon on the left or pressing CTRL-S keyboard shortcut.

Fulltext

Fulltext search is triggered whenever search string doesn't start with @ (used in attribute search) or = (saved search with script).

Fulltext searches on both title and content of undeleted, unprotected text and code notes which are not archived.

Input string is tokenized by whitespace separators and each individual token (word) must be present in the title or content. If you don't want this automatic tokenization, you can surround your search with double quotes, e.g. "hello world" will search for exact match.

Attribute query syntax

Standard attributes

Here you query by standard attributes:

  • @abc - returns notes with label abc
  • @!abc - returns notes which don't have label abc
  • @year=2019 - matches notes with label year having value 2019
  • @year!=2019 - matches notes with label year, but not having value 2019 or not having label year at all.
    • if you want to express condition that note must have year label, but not value 2019, then you can do that with @year @year!=2019
  • @year<=2000 - return notes with label year having value 2000 or smaller. >, <, >= and <= are supported.
    • In this case parameter can be parsed as a number so number-wise comparison is done. But it's also possible to compare strings lexicographically in the same way. This is useful for comparing dates as seen below.
  • @rock @pop - matches notes which have both rock and pop labels
    • @rock and @pop is an alternative syntax for the same thing
  • @rock or @pop - only one of the labels must be present
    • and has a precedence over or in case both operators are used in a search string
  • @frontMan=*John - matches notes where frontMan label starts with "John". There's also !=* for "doesn't start with", *= for "ends with" and !*= for "does not end with", *=* for "contains" and !*=* for "does not contain"

Virtual attributes

It's also possible to query by so called "virtual attributes":

  • dateCreated - local date of note's creation date in YYYY-MM-DD HH:mm:ss.sss+OOPP where OOPP are hours and minutes of offset compared to UTC (e.g. "+0100" for Central European Time)
  • dateModified - local date of last note's modification in YYYY-MM-DD HH:mm:ss.sss+OOPP
  • utcDateCreated - UTC date of note's creation date in YYYY-MM-DD HH:mm:ss.sssZ
  • utcDateModified - UTC date of last note's modification date in YYYY-MM-DD HH:mm:ss.sssZ
  • noteId
  • isProtected - 1 if the note is protected, 0 otherwise
  • title - useful if you want to search title separately
  • content
  • type - text, code, image, file, search or relation-map
  • mime - e.g. text/html for text note
  • text - fulltext attribute of both title and content together
    • For example @text*=*Hello. So that you can combine searching for both text and attributes.
  • isArchived - filters only for archived notes, @!archived then filters only for non-archived notes. Note that this filter does not work in OR relation, it is always AND.
  • in - for example @in=VuvLpfAPx2L9 will filter only notes which have note with noteId VuvLpfAPx2L9 as one of the ancestors - i.e. note is in the subtree of VuvLpfAPx2L9. With negating operator - @in!=VuvLpfAPx2L9 will filter notes which don't have note VuvLpfAPx2L9 as their ancestor. Since Trilium 0.37

Order and limit

It's possible to order the results by one or more attribute, e.g. @orderBy=year,-genre will order notes by year label in ascending order and then by genre label in descending order (because of - sign).

You can also limit the number of results using e.g. @limit=1 will return only the first result. If there's no limit, then all notes are returned.

Date comparisons

Attribute values are untyped strings which means that although you can save into it any kind of value like number or date, Trilium doesn't really know what kind of value it is and can't really treat it properly.

Fortunately if we stick to storing dates in YYYY-MM-DD format, we can still do quite a lot since such dates can be correctly compared as strings - e.g. @dateCreated>=2015-01-01 will return notes which were created since 2015 even though Trilium is doing just string comparison.

What if you want to find notes created in 2015? You can use "starts with" operator (=*) like this: @dateCreated=*2019 - this will match notes with label starting with string "2019" which all notes created in that year will satisfy.

Smart filters

Trilium supports few special values which will might help you with some search queries:

  • NOW means this instant to second precision, e.g. 2019-04-01 10:12:54
    • NOW-3600 means 1 hour ago
  • TODAY means today with the day precision, e.g. 2019-04-01
    • TODAY-1 means yesterday, TODAY+1 means tomorrow
  • MONTH means this month, e.g. 2019-04
    • MONTH-1 means last month - i.e. 2019-03
  • YEAR means current year, e.g. 2019
    • YEAR-1 means last year - 2018

Using this you can create queries like:

  • @dateModified>=NOW-3600 - show me notes changed in the last hour
  • @dateCreated=*TODAY-1 - show me notes created during whole yesterday

Saved search

Trilium provides a way to save common search as a note in the note tree. Search results will then appear as subnotes of this "saved search" note. You can see how this works in action:

Saved search with script relation

If saved search string starts with =, then the following string is taken as a relation name and the target script is executed to get the list of note results.

So let's say the search string is =handler, then Trilium tries to find this saved note's relation with name "handler". Relation is expected to point to script which is then executed - script is expected to return a list of notes which should be presented as search results. This option exists for use cases where normal attribute/fulltext search doesn't cover all needs.

Auto trigger search from URL

Opening Trilium like in the example below will open search pane and automatically trigger search for "abc":

http://localhost:8080/#search=abc
⚠️ **GitHub.com Fallback** ⚠️