Skip to content

feat: highlight matched characters in search results#73

Open
d-rita wants to merge 11 commits into
mainfrom
DHIS2-21203/search-highlighting
Open

feat: highlight matched characters in search results#73
d-rita wants to merge 11 commits into
mainfrom
DHIS2-21203/search-highlighting

Conversation

@d-rita
Copy link
Copy Markdown
Contributor

@d-rita d-rita commented May 1, 2026

Implements DHIS2-21203


Description

This PR highlights the matched characters from the filter/search term within the search results. It uses the Highlighter component from the react-highlight-words dependency.

For highlighting, the ranges of the matched indices returned by the fuse search are used. The idea is to highlight the parts of the returned results that best match the filter, and ignore the minor matches so as to reduce the visual noise hence improving the user experience.
The range is selected by looking at either the longest contiguous match or the total number of scattered matches within a word. Every word is isolated and matched against the filter. The number of words in the filter is also taken into account so as to determine how many words within the search result need to be highlighted.

Possibility:
use the new token search feature in fuse js to search multi-word queries.

Tasks

  • Implementation of fuzzy highlighting
  • Highlight the matched app name for shortcuts returned with their app
  • Update and modify current tests
  • Add tests for new helper function, i.e. pickHighlightRanges
  • Increase threshold from 0.3 to 0.4 to get more fuzzy matches

Testing

  • Run yarn to install new dependency: react-highlight-words
  • Open command palette using ctrl/cmd + k or clicking the 9 grid icon and try different search patterns.

Screenshots

  • Full app name match
full app name filter
  • Full shortcut name match
full shortcut filter
  • Partial app name match
partial app filter
  • Partial shortcut name match
partial shortcut filter
  • Partial filter matching either app or shortcut
app and shortcut partial filter
  • Typo
typo search

d-rita added 2 commits May 1, 2026 14:24
- use react-highlight-words highlighter component to mark all matched characters from the filter
@d-rita d-rita requested review from a team and cooper-joe May 1, 2026 13:24
Diana Nanyanzi and others added 4 commits May 20, 2026 03:17
- refine the logic in the filterItemsPerView function with separate helper
- keep shortcut matches for each matched app for highlighting
- use the matched characters and number of words in filter to define highlighting range
- use the longest contiguous range, or total number of matched characters
- create separate files for fuzzy matching, highlighting, and filtering functions
@d-rita d-rita force-pushed the DHIS2-21203/search-highlighting branch from c9f824f to cf9bf74 Compare May 20, 2026 00:43
d-rita and others added 3 commits May 20, 2026 04:21
- update failing test to cater for results returned with new threshold
- refactor returned variable for highlighting ranges
Copy link
Copy Markdown
Member

@cooper-joe cooper-joe left a comment

Choose a reason for hiding this comment

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

I've reviewed the matching and I think the threshold setting is about right.

The part that felt the most off was actually the styling. I've pushed a commit which reduces the impact of the highlight, I think this helps to provide the user with a hint of "why is this returned?" while still allowing fuzzy matching to do its job.

@sonarqubecloud
Copy link
Copy Markdown

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