> For the complete documentation index, see [llms.txt](https://jeanhuas-organization.gitbook.io/imarket/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jeanhuas-organization.gitbook.io/imarket/api/search-sou-suo-gong-neng.md).

# Search（搜索功能）

## **GET /api/Search/Posts**

* **描述**: 搜索帖子。
* **参数**:
  * `keyWord` (string, required): 关键词
  * `page` (integer, optional, default=1): 页码
  * `pageSize` (integer, optional, default=10): 每页大小
* **响应**: 200 OK

请求示例

```
//api/Search/Posts?keyWord=<string>&page=1&pageSize=10
```

示例代码

```javascript
const myHeaders = new Headers();
myHeaders.append("Authorization", "<API Key>");

const requestOptions = {
  method: "GET",
  headers: myHeaders,
  redirect: "follow"
};

fetch("//api/Search/Posts?keyWord=<string>&page=1&pageSize=10", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
```

返回示例

```json
{
  "success": true,
  "posts": [
    {
      "id": 1,
      "title": "第一个帖子",
      "nickname": "admin imarket",
      "avatar": "test",
      "content": "这个是第一个帖子",
      "favoriteNums": 1,
      "likeNums": 0,
      "createdAt": "2025-01-22T16:41:31"
    }
  ]
}
```

***

## **GET /api/Search/HotRanking**

* **描述**: 获取热门排行榜。

{% hint style="warning" %}
返回值为最近一周的最多点赞和最多收藏10篇帖子，如果帖子没有点赞或收藏，则可能少于10篇
{% endhint %}

* **响应**: 200 OK

请求示例

```
//api/Search/HotRanking
```

示例代码

```javascript
const myHeaders = new Headers();
myHeaders.append("Authorization", "<API Key>");

const requestOptions = {
  method: "GET",
  headers: myHeaders,
  redirect: "follow"
};

fetch("//api/Search/HotRanking", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
```

返回示例

```json
{
  "success": true,
  "like": [
    {
      "id": 1,
      "title": "第一个帖子",
      "content": "这个是第一个帖子",
      "userId": 3214,
      "createdAt": "2025-01-22T16:41:31",
      "likeCount": 1
    }
  ],
  "favorite": [
    {
      "id": 2,
      "title": "第一个帖子",
      "content": "这个是第一个帖子",
      "userId": 3214,
      "createdAt": "2025-01-22T16:41:31",
      "favoriteCount": 1
    }
  ]
}
```
