Skip to content

Add option to highlight search result matches#2331

Open
danloveg wants to merge 17 commits into
artefactual:qa/2.xfrom
danloveg:dev/search-highlighting
Open

Add option to highlight search result matches#2331
danloveg wants to merge 17 commits into
artefactual:qa/2.xfrom
danloveg:dev/search-highlighting

Conversation

@danloveg
Copy link
Copy Markdown
Contributor

@danloveg danloveg commented Apr 1, 2026

Adds an option to highlight search results for information objects. I've been working with researchers using AtoM recently and they mentioned that being able to see why certain descriptions are returned in the search results at a glance would be a useful feature. This PR adds subtle highlighting to search results to show what text matched the search query. If the title, scope and content, or creator is matched on, then those highlights are added inline to the existing rendered fields. If other fields that are not typically included in the search results are matched on, they are added in a new block. See here:

highlight

Elasticsearch already has this capability, it was just a matter of turning highlighting on and rendering its results. It returns matches wrapped in <mark></mark> tags.

Since administrators might not want this active, you can disable it in the settings. I've made it enabled by default.

setting

I understand this feature probably won't make it for 2.11 but thought I'd open this pull request in case this would be a useful feature for others, as well.

@sarah-mason sarah-mason added the Community Pull requests that have been contributed from community members outside Artefactual label Apr 9, 2026
@anvit
Copy link
Copy Markdown
Contributor

anvit commented Apr 16, 2026

Hi @danloveg , we'd been testing this feature out, and it looks great! We had a couple of minor things we noticed during testing that we wanted to flag:

  • Currently the contrast ratio for the highlight colour against the background colour is too low. I would recommend picking a darker/more saturated shade. You could use Web AIM's contrast checker to test a chosen colour and confirm that it meets the accessibility standards.
  • When a language is picked to narrow down search results, the language code itself shows up as a match. Not sure if this is something that's easy to fix since I haven't dived into this PR yet.
image

@danloveg
Copy link
Copy Markdown
Contributor Author

danloveg commented Apr 27, 2026

Hi @danloveg , we'd been testing this feature out, and it looks great! We had a couple of minor things we noticed during testing that we wanted to flag:

  • Currently the contrast ratio for the highlight colour against the background colour is too low. I would recommend picking a darker/more saturated shade. You could use Web AIM's contrast checker to test a chosen colour and confirm that it meets the accessibility standards.

  • When a language is picked to narrow down search results, the language code itself shows up as a match. Not sure if this is something that's easy to fix since I haven't dived into this PR yet.

Thanks for taking a look! I've upped the contrast, there's no warning about contrast issues in my browser's accessibility tab any more. This is what I came up with for the new styling.

improved contrast

And regarding the language, thanks for flagging that. I am ignoring i18n.languages as a highlighted field which fixes the language being shown in the highlighting, and there was some extra culture checking I needed to do to handle multi-lingual descriptions. It appears to be working correctly now.

@JBosse-Artefactual
Copy link
Copy Markdown

@danloveg Looks great!! @anvit This looks good to me!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Pull requests that have been contributed from community members outside Artefactual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants