Improve multiple word search
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
Jorge Vargas 2025-05-01 20:44:20 -06:00
parent 87b2fc0796
commit 1cd11fea2b
2 changed files with 7 additions and 7 deletions

View file

@ -19,17 +19,17 @@ let { page } = Astro.props
if (page < 1) page = 1 if (page < 1) page = 1
const queryString = query const queryString = query
.toLowerCase() .trim()
.split('_') .split(/[\s_\-:]+/)
.map((w) => `+${w}`)
.join(' ') .join(' ')
const findQuery: Prisma.albumsFindManyArgs = { const findQuery: Prisma.albumsFindManyArgs = {
select: { title: true, releaseDate: true, id: true }, select: { title: true, releaseDate: true, id: true },
where: { where: {
OR: [{ title: { search: queryString } }, { subTitle: { search: queryString } }] OR: [{ title: { search: queryString } }, { subTitle: { search: queryString } }]
}, },
orderBy: { orderBy: {
_relevance: { fields: ['title', 'subTitle'], sort: 'desc', search: query.toLowerCase() } _relevance: { fields: ['title', 'subTitle'], sort: 'desc', search: queryString }
} }
} }
const countQuery: Prisma.albumsCountArgs<DefaultArgs> = { const countQuery: Prisma.albumsCountArgs<DefaultArgs> = {
@ -76,6 +76,6 @@ const end = Math.min(page * take, count)
} }
</div> </div>
<div class='text-xl flex gap-x-2'> <div class='flex gap-x-2'>
<SearchNav query={query} count={count} take={take} page={page} /> <SearchNav query={query} count={count} take={take} page={page} />
</div> </div>

View file

@ -14,9 +14,9 @@ const pageCount = Math.ceil(count / take)
pageCount > 1 pageCount > 1
? Array.from({ length: pageCount }, (_, i) => ? Array.from({ length: pageCount }, (_, i) =>
page === i + 1 ? ( page === i + 1 ? (
<span class='bg-gray rounded px-2 cursor-pointer'>{i + 1}</span> <span class='text-xl bg-gray rounded px-2 cursor-pointer'>{i + 1}</span>
) : ( ) : (
<a class='bg-gray/50 rounded px-2' href={`/search?q=${query}&page=${i + 1}`}> <a class='text-xl bg-gray/50 rounded px-2' href={`/search?q=${query}&page=${i + 1}`}>
{i + 1} {i + 1}
</a> </a>
) )