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,20 +27,27 @@ export default async function handler(
blocks: [],
}
result.blocks = await unbodyApi
.searchPostBlocks({
tags,
type: ['text', 'image'],
postId: Array.isArray(id) ? id[0] : id,
query: Array.isArray(q) ? q.join(' ') : q,
method: 'nearText',
certainty: 0.85,
const query: Parameters<(typeof unbodyApi)['searchPostBlocks']>[0] = {
tags,
type: ['text', 'image'],
postId: Array.isArray(id) ? id[0] : id,
query: Array.isArray(q) ? q.join(' ') : q,
method: 'nearText',
certainty: 0.85,
limit: parseInt(limit, 50),
skip: parseInt(skip, 0),
})
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({
data: result,
})