-
Notifications
You must be signed in to change notification settings - Fork 240
/
how-to-filter-threads-using-query-language.mdx
68 lines (50 loc) · 2.03 KB
/
how-to-filter-threads-using-query-language.mdx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
meta:
title: "How to filter threads with query language"
description:
"Learn how to filter for certain threads using their metadata with our query
language"
---
When using Comments and retrieving threads with our REST API, it’s possible to
filter for specific threads using
[custom metadata](/docs/products/comments/metadata) and our custom query
language. This enables the
[Get Threads REST API](/docs/api-reference/rest-api-endpoints#get-rooms-roomId-threads)
to have filtering that works the same as with
[`useThreads`](/docs/api-reference/liveblocks-react#useThreads) and
[`liveblocks.getThreads`](/docs/api-reference/liveblocks-node#get-rooms-roomId-threads).
## Query language
You can filter threads by their metadata, allowing you to select for certain
properties, values, or even for string prefixes. Filters can be combined using
`AND` logic.
```js
// Threads with { status: 'open' } string metadata
metadata['status']:'open'
// Threads with `{ org }` string metadata that starts with "liveblocks:"
metadata['org']^'liveblocks:'
// Threads with { priority: 3 } number metadata
metadata['priority']:3
// Threads with { resolved: false } boolean metadata
metadata['resolved']:false
// Combine queries with AND
metadata['status']:'open' AND metadata['priority']:3
// A more complex combination
metadata['status']:'closed' AND metadata['org']^'liveblocks:'
```
<Banner>
The `AND` is optional and can actually be omitted, but we’re using it here for
clarity.
</Banner>
### How to use
To use the query language with the
[REST API](/docs/api-reference/rest-api-endpoints#get-rooms-roomId-threads) pass
your query string to the `query` parameter. For example, given this query:
```js
metadata['status']:'open' AND metadata['priority']:3
```
Encode it, and add it to the `query` parameter:
```
https://api.liveblocks.io/v2/rooms/{roomId}/threads?query=metadata%5B'status'%5D%3A'open'%20AND%20metadata%5B'priority'%5D%3A3
```
To learn more on _setting_ custom metadata on threads, make sure to
[read our guide](/docs/products/comments/metadata).