个股论坛重做
This commit is contained in:
@@ -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,
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user