mirror of
https://github.com/LukeHagar/discoursejs.git
synced 2025-12-06 04:19:37 +00:00
78 lines
44 KiB
Markdown
78 lines
44 KiB
Markdown
# Search
|
|
(*search*)
|
|
|
|
## Overview
|
|
|
|
### Available Operations
|
|
|
|
* [search](#search) - Search for a term
|
|
|
|
## search
|
|
|
|
Search for a term
|
|
|
|
### Example Usage
|
|
|
|
```typescript
|
|
import { SDK } from "@lukehagar/discoursejs";
|
|
|
|
const sdk = new SDK();
|
|
|
|
async function run() {
|
|
const result = await sdk.search.search(1, "api @blake #support tags:api after:2021-06-04 in:unseen in:open order:latest_topic");
|
|
|
|
// Handle the result
|
|
console.log(result)
|
|
}
|
|
|
|
run();
|
|
```
|
|
|
|
### Standalone function
|
|
|
|
The standalone function version of this method:
|
|
|
|
```typescript
|
|
import { SDKCore } from "@lukehagar/discoursejs/core.js";
|
|
import { searchSearch } from "@lukehagar/discoursejs/funcs/searchSearch.js";
|
|
|
|
// Use `SDKCore` for best tree-shaking performance.
|
|
// You can create one instance of it to use across an application.
|
|
const sdk = new SDKCore();
|
|
|
|
async function run() {
|
|
const res = await searchSearch(sdk, 1, "api @blake #support tags:api after:2021-06-04 in:unseen in:open order:latest_topic");
|
|
|
|
if (!res.ok) {
|
|
throw res.error;
|
|
}
|
|
|
|
const { value: result } = res;
|
|
|
|
// Handle the result
|
|
console.log(result)
|
|
}
|
|
|
|
run();
|
|
```
|
|
|
|
### Parameters
|
|
|
|
| Parameter | Type | Required | Description | Example |
|
|
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
| `page` | *number* | :heavy_minus_sign: | N/A | [object Object] |
|
|
| `q` | *string* | :heavy_minus_sign: | The query string needs to be url encoded and is made up of the following options:<br/>- Search term. This is just a string. Usually it would be the first item in the query.<br/>- `@<username>`: Use the `@` followed by the username to specify posts by this user.<br/>- `#<category>`: Use the `#` followed by the category slug to search within this category.<br/>- `tags:`: `api,solved` or for posts that have all the specified tags `api+solved`.<br/>- `before:`: `yyyy-mm-dd`<br/>- `after:`: `yyyy-mm-dd`<br/>- `order:`: `latest`, `likes`, `views`, `latest_topic`<br/>- `assigned:`: username (without `@`)<br/>- `in:`: `title`, `likes`, `personal`, `messages`, `seen`, `unseen`, `posted`, `created`, `watching`, `tracking`, `bookmarks`, `assigned`, `unassigned`, `first`, `pinned`, `wiki`<br/>- `with:`: `images`<br/>- `status:`: `open`, `closed`, `public`, `archived`, `noreplies`, `single_user`, `solved`, `unsolved`<br/>- `group:`: group_name or group_id<br/>- `group_messages:`: group_name or group_id<br/>- `min_posts:`: 1<br/>- `max_posts:`: 10<br/>- `min_views:`: 1<br/>- `max_views:`: 10<br/><br/>If you are using cURL you can use the `-G` and the `--data-urlencode` flags to encode the query:<br/><br/>```<br/>curl -i -sS -X GET -G "http://localhost:4200/search.json" \<br/>--data-urlencode 'q=wordpress @scossar #fun after:2020-01-01'<br/>```<br/> | [object Object] |
|
|
| `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | |
|
|
| `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | |
|
|
| `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | |
|
|
|
|
### Response
|
|
|
|
**Promise\<[operations.SearchResponseBody](../../sdk/models/operations/searchresponsebody.md)\>**
|
|
|
|
### Errors
|
|
|
|
| Error Object | Status Code | Content Type |
|
|
| --------------- | --------------- | --------------- |
|
|
| errors.SDKError | 4xx-5xx | */* |
|