nextra icon indicating copy to clipboard operation
nextra copied to clipboard

Flexsearch does not return page results when no section results are matched

Open silas opened this issue 2 years ago • 1 comments

Right now the Flexsearch component will not show results unless both the pageIndexand sectionIndex contains results.

This makes it so page titles don't get shown in the results much of this time. You can see this on the nextra.site site by searching for showcase.

It might be worth special casing sectionResults.length === 0 and adding a page-only fallback.

Note that this also effects if any results will get shown at all, since the pageIndex search is limited to 5 results, if none of those have searchIndex matches, you won't get any results.

Might make sense

As a side note, it might be worth considering exporting the Search component so it's a bit easier for people to implement their own search algorithm. Right now you have to fork a lot of code if you want to replace one of the builtin algorithms.

This would probably make it a bit easier for people to experiment with the search algorithm in their own project and potentially upstream some of those improvements.

I realize this might not make sense, just an idea.

silas avatar Oct 12 '23 16:10 silas

The Flexsearch component (not sure about Search unless it's configurable because Flexsearch wraps around it and hardcode's its usage) should definitely be exported imo. A lot of people have asked for it after a quick look as the issues.

I'm also having an issue where a page called "ExactlyThis" is not being listed as the top result when searching for "ExactlyThis" and other pages are ranked higher for mentioning this phrase in the content. I don't know why the page title is not ranked higher (especially against pages that don't even mention that phrase in their page's title). Exact page title names should be taken into consideration, but I can't tell if that's happening or if it's a bug.

Mike-Logit avatar Aug 06 '24 14:08 Mike-Logit

closing since flexsearch was migrated to pagefind in nextra 4 https://the-guild.dev/blog/nextra-4#new-search-engine--pagefind

dimaMachina avatar Jan 30 '25 23:01 dimaMachina