Skip to content
New issue

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

feat: Strip HTML from rich text search results #3783

Merged
merged 6 commits into from
Oct 24, 2024
Merged

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Oct 9, 2024

What does this PR do?

  • Strips HTML tags from rich text fields
  • Splits HTML elements with newlines to display in the SearchResultCard
Before After
image image

@@ -27,6 +33,7 @@ export const useSearch = <T extends object>({
useExtendedSearch: true,
includeMatches: true,
minMatchCharLength: 3,
ignoreLocation: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, just the first 60 characters are searched which was giving me some unexpected false negative results.

The testing I've done doesn't make this feel much slower performance-wise - will flag this when this PR is tested.

Docs: https://www.fusejs.io/api/options.html#ignorelocation

@DafyddLlyr DafyddLlyr changed the title dp/search strip html feat: Strip HTML from rich text search results Oct 9, 2024
Copy link

github-actions bot commented Oct 9, 2024

Removed vultr server and associated DNS entries

@DafyddLlyr DafyddLlyr marked this pull request as draft October 9, 2024 10:31
@DafyddLlyr DafyddLlyr force-pushed the dp/search-strip-html branch from a7aa02a to d80c5f8 Compare October 21, 2024 11:24
@DafyddLlyr DafyddLlyr force-pushed the dp/search-strip-html branch from 1c631c2 to 9298ae6 Compare October 21, 2024 14:11
@@ -307,7 +241,7 @@ const defaultFormatter: SearchResultFormatter = {
getIconKey: ({ item }) => item.type,
getTitle: ({ item }) =>
(item.data?.title as string) || (item.data?.text as string) || "",
getHeadline: ({ item, key }) => get(item, key)?.toString() || "",
getHeadline: ({ matchValue }) => matchValue,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice simplification! Rather than try to reverse engineer the match back via multiple different getHeadline() methods, we can just use the original matchValue which fuse.js used.

@DafyddLlyr DafyddLlyr requested a review from a team October 23, 2024 10:35
@DafyddLlyr DafyddLlyr marked this pull request as ready for review October 23, 2024 10:36
@jamdelion
Copy link
Contributor

Looks nice and clean without the markdown in the search result :) I do find it a bit odd that several seemingly unrelated strings are sometimes thrown up in bold (e.g aph in 'paragraph' in your example), but I think I gathered from how you talked about this a few weeks ago that this whole feature has been quite tricky to get right! At least it certainly seems to throw up the most likely search results first, in my testing anyway. :)

@DafyddLlyr DafyddLlyr merged commit dee8f85 into main Oct 24, 2024
12 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/search-strip-html branch October 24, 2024 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants