个股论坛重做

This commit is contained in:
2026-01-06 14:57:33 +08:00
parent 38abb260da
commit ebf9fc2bf2
2 changed files with 20 additions and 18 deletions

View File

@@ -1300,12 +1300,16 @@ def es_search_proxy(index):
try:
body = request.get_json()
print(f"[Community API] ES 搜索请求: index={index}, body={body}")
result = es_client.search(index=index, body=body)
print(f"[Community API] ES 搜索成功: 返回 {result.get('hits', {}).get('total', {})} 条结果")
return jsonify(result)
except Exception as e:
print(f"[Community API] ES 搜索失败: {e}")
import traceback
traceback.print_exc()
return api_error(f'搜索失败: {str(e)}', 500)

View File

@@ -111,37 +111,35 @@ export const getMessages = async (
const { before, after, limit = 50 } = options;
// 构建 ES 查询
const query: any = {
bool: {
must: [
{ term: { channel_id: channelId } },
{ term: { is_deleted: false } },
],
must_not: [
{ exists: { field: 'thread_id' } }, // 排除讨论串消息
],
},
};
// 只查询主消息(非讨论串消息)
const filters: any[] = [
{ term: { channel_id: channelId } },
];
// 分页游标
if (before) {
query.bool.must.push({
range: { created_at: { lt: before } },
});
filters.push({ range: { created_at: { lt: before } } });
}
if (after) {
query.bool.must.push({
range: { created_at: { gt: after } },
});
filters.push({ range: { created_at: { gt: after } } });
}
const query: any = {
bool: {
filter: filters,
must_not: [
{ term: { is_deleted: true } },
],
},
};
// 查询时总是按时间降序获取(最新的在前)
const response = await fetch(`${ES_API_BASE}/community_messages/_search`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query,
sort: [{ created_at: 'desc' }],
sort: [{ created_at: { order: 'desc' } }],
size: limit,
}),
});