0
# Search & Discovery
1
2
Search across messages, files, and other content within your Slack workspace.
3
4
## Capabilities
5
6
### Universal Search
7
8
Search across all content types in your workspace.
9
10
```python { .api }
11
def all(self, query, sort=None, sort_dir=None, highlight=None, count=None, page=None):
12
"""
13
Search all content (messages and files) in workspace.
14
15
Args:
16
query (str): Search query string
17
sort (str, optional): Sort order ('score', 'timestamp')
18
sort_dir (str, optional): Sort direction ('asc', 'desc')
19
highlight (bool, optional): Highlight search terms in results
20
count (int, optional): Number of results per page
21
page (int, optional): Page number
22
23
Returns:
24
Response: Combined search results including messages and files
25
"""
26
```
27
28
### Message Search
29
30
Search specifically within messages and conversations.
31
32
```python { .api }
33
def messages(self, query, sort=None, sort_dir=None, highlight=None, count=None, page=None):
34
"""
35
Search messages in workspace.
36
37
Args:
38
query (str): Search query string
39
sort (str, optional): Sort order ('score', 'timestamp')
40
sort_dir (str, optional): Sort direction ('asc', 'desc')
41
highlight (bool, optional): Highlight search terms in results
42
count (int, optional): Number of results per page
43
page (int, optional): Page number
44
45
Returns:
46
Response: Message search results with context and metadata
47
"""
48
```
49
50
### File Search
51
52
Search specifically within files uploaded to your workspace.
53
54
```python { .api }
55
def files(self, query, sort=None, sort_dir=None, highlight=None, count=None, page=None):
56
"""
57
Search files in workspace.
58
59
Args:
60
query (str): Search query string
61
sort (str, optional): Sort order ('score', 'timestamp')
62
sort_dir (str, optional): Sort direction ('asc', 'desc')
63
highlight (bool, optional): Highlight search terms in results
64
count (int, optional): Number of results per page
65
page (int, optional): Page number
66
67
Returns:
68
Response: File search results with metadata and snippets
69
"""
70
```
71
72
Usage:
73
```python
74
# Search all content
75
results = slack.search.all('project update')
76
77
# Search only messages
78
messages = slack.search.messages('from:@john deadline', sort='timestamp', sort_dir='desc')
79
80
# Search only files with highlighting
81
files = slack.search.files('budget spreadsheet', highlight=True)
82
83
# Paginated search
84
first_page = slack.search.all('quarterly report', count=10, page=1)
85
second_page = slack.search.all('quarterly report', count=10, page=2)
86
```
87
88
## Search Query Syntax
89
90
Slack search supports various query operators:
91
92
- **Basic text**: `project update`
93
- **User filter**: `from:@username` or `from:me`
94
- **Channel filter**: `in:#channel-name`
95
- **Date filters**: `after:2023-01-01`, `before:2023-12-31`, `on:2023-06-15`
96
- **File type**: `type:pdf`, `type:image`
97
- **Exact phrases**: `"exact phrase"`
98
- **Boolean operators**: `AND`, `OR`, `NOT`
99
100
## Types
101
102
```python { .api }
103
class Search(BaseAPI):
104
"""Search functionality for workspace content."""
105
def all(self, query, sort=None, sort_dir=None, highlight=None, count=None, page=None): ...
106
def files(self, query, sort=None, sort_dir=None, highlight=None, count=None, page=None): ...
107
def messages(self, query, sort=None, sort_dir=None, highlight=None, count=None, page=None): ...
108
```