We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use a weight system to better search, something like this:
import { Post } from 'contentlayer/generated' import { slug } from '@/shared/lib/slug' export function searchMath(post: Post, search: string) { const sluggedSearch = slug(search) let weight = 0 if (slug(post.title).includes(sluggedSearch)) weight++ if (slug(post.description).includes(sluggedSearch)) weight++ if (slug(post.author).includes(sluggedSearch)) weight++ if (slug(post.category).includes(sluggedSearch)) weight++ if (slug(post.status).includes(sluggedSearch)) weight++ if (slug(post.tags).includes(sluggedSearch)) weight++ return weight }
Then, sort results by weight value, from biggest to smallest, and remove results with value 0.
Also add an array of sources for match, and map to it for match condition:
import { Post } from 'contentlayer/generated' import { slug } from '@/shared/lib/slug' export function searchMath(post: Post, search: string) { const sluggedSearch = slug(search) let weight = 0 const sources = [post.title, post.description, post.author, post.category, post.status, post.tags] sources.forEach(source => slug(post.title).includes(sluggedSearch) && weight++) return weight }
The text was updated successfully, but these errors were encountered:
e1976e8
No branches or pull requests
Use a weight system to better search, something like this:
Then, sort results by weight value, from biggest to smallest, and remove results with value 0.
Also add an array of sources for match, and map to it for match condition:
The text was updated successfully, but these errors were encountered: