fix: use hybrid as fallback for post search

This commit is contained in:
Hossein Mehrabi 2023-09-29 15:52:41 +03:30
parent 588fe4d29a
commit 0a055d82a7
No known key found for this signature in database
GPG Key ID: 45C04964191AFAA1
1 changed files with 18 additions and 11 deletions

View File

@ -27,8 +27,7 @@ export default async function handler(
blocks: [],
}
result.blocks = await unbodyApi
.searchPostBlocks({
const query: Parameters<(typeof unbodyApi)['searchPostBlocks']>[0] = {
tags,
type: ['text', 'image'],
postId: Array.isArray(id) ? id[0] : id,
@ -38,7 +37,15 @@ export default async function handler(
limit: parseInt(limit, 50),
skip: parseInt(skip, 0),
})
}
result.blocks = await unbodyApi
.searchPostBlocks(query)
.then((res) => res.data)
if (result.blocks.length === 0)
result.blocks = await unbodyApi
.searchPostBlocks({ ...query, method: 'hybrid' })
.then((res) => res.data)
res.status(200).json({