mirror of
https://github.com/jorgev259/soc_site-astro.git
synced 2025-06-29 07:57:41 +00:00
Improve search result order by relevance
This commit is contained in:
parent
a4b8cf5aab
commit
f675e177b7
1 changed files with 10 additions and 21 deletions
|
|
@ -11,31 +11,20 @@ interface Props {
|
|||
|
||||
const take = 20
|
||||
const { query } = Astro.props
|
||||
|
||||
const queryString = query
|
||||
.toLowerCase()
|
||||
.split('_')
|
||||
.map((w) => `+${w}`)
|
||||
.join(' ')
|
||||
const findQuery: Prisma.albumsFindManyArgs = {
|
||||
select: { title: true, releaseDate: true, id: true },
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
title: {
|
||||
search: query
|
||||
.toLowerCase()
|
||||
.split('_')
|
||||
.map((w) => `+${w}`)
|
||||
.join(' ')
|
||||
}
|
||||
},
|
||||
{
|
||||
subTitle: {
|
||||
search: query
|
||||
.toLowerCase()
|
||||
.split('_')
|
||||
.map((w) => `+${w}`)
|
||||
.join(' ')
|
||||
}
|
||||
}
|
||||
]
|
||||
OR: [{ title: { search: queryString } }, { subTitle: { search: queryString } }]
|
||||
},
|
||||
orderBy: { publishedAt: 'desc' }
|
||||
orderBy: {
|
||||
_relevance: { fields: ['title', 'subTitle'], sort: 'desc', search: query.toLowerCase() }
|
||||
}
|
||||
}
|
||||
const countQuery: Prisma.albumsCountArgs<DefaultArgs> = {
|
||||
where: findQuery.where
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue