Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
✨ 内容块动态查询嵌入 siyuan-note/siyuan#48
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 17, 2020
1 parent 518a0f6 commit 771ccdd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
42 changes: 24 additions & 18 deletions General Operations/Search_20200924100839-5oe1j4n.sy.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ If the search keyword starts with the following characters, type filtering is en
For example, if you want to search for all heading blocks containing `Markdown`, you can use `#Markdown` as the search criteria.

## For geeks...
{: id="20201117103851-gx21lz6"}

Global text search support:

Expand All @@ -37,30 +38,35 @@ For SQL search, use the built-in SQLite database (system temporary folder/siyuan

This table is used to store content block data.

| Field | Type | Description |
| -------: | :--: | ------------------------------------------------------- |
| id | text | Self-incrementing primary key |
| block_id | text | Content block ID |
| box | text | Notebook name |
| path | text | Path of the document where the content block is located |
| tree_id | text | Abstract Syntax Tree ID, as the same as root node ID |
| content | text | Content block Markdown |
| type | text | Content block type |
| Field | Type | Description |
| -: | :-: | - |
| id | text | Self-incrementing primary key |
| block_id | text | Content block ID |
| box | text | Notebook name |
| path | text | Path of the document where the content block is located |
| tree_id | text | Abstract Syntax Tree ID, as the same as root node ID |
| content | text | Content block Markdown |
| type | text | Content block type |

Example:

```sql
SELECT * FROM blocks WHERE content LIKE'%content block%' AND type ='NodeParagraph'
SELECT * FROM blocks WHERE content LIKE '%content block%'
```

List of `type` content block type values:

* `NodeDocument` document block
* `NodeHeading` header block
* `NodeParagraph` paragraph block
* `NodeList` list block
* `NodeListItem` list item block
* `NodeDocument` Document block
* `NodeHeading` Heading block
* `NodeParagraph` Paragraph block
* `NodeList` List block
* `NodeListItem` List item block
* `NodeMathBlock` Mathematical formula block
* `NodeCodeBlock` code block
* `NodeBlockquote` block quote block
* `NodeTable` table block
* `NodeCodeBlock` Code block
* `NodeBlockquote` Blockquote block
* `NodeTable` Table block

### Default query conditions

* If you do not specify the `type` column, the default will add `type = NodeParagraph`, that is, only query paragraph blocks
* If `LIMIT` is not specified, only the first 32 results will be returned at most
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Dynamic query embed syntax

The syntax of the content block dynamic query embed is:

```sql
!{{ SELECT * FROM blocks WHERE content LIKE '%content block%' }}
```

It needs to be used on its own line. The script syntax used is SQL. For details, please refer to ((20201117103851-gx21lz6 "here")).

### Example

* Query list items that contain `content block`:

```sql
!{{ SELECT * FROM blocks WHERE content LIKE '%content block%' AND type = 'NodeListItem' }}
```
* The query content contains both `content block` and `reference` paragraph blocks:

```sql
!{{ SELECT * FROM blocks WHERE content LIKE'%content block%' AND content LIKE'%reference%' }}
```
* The query content contains title blocks of both `content block` and `embed`, and the first 2 items are selected in descending order of time:

```sql
!{{ SELECT * FROM blocks WHERE (content LIKE '%content block%' AND content LIKE '%embed%') AND type ='NodeHeading' ORDER BY block_id DESC LIMIT 4 }}
```

0 comments on commit 771ccdd

Please sign in to comment.