Skip to content

[EuiHighlight] Highlight separated words #5798

Closed

Description

@pickypg

When using tools like App Search to highlight, it will highlight across words as most searches will do. For instance, searching for

Beats output

would highlight the title as shown:

Beats redis output

However, EuiHighlight only works on case insensitive matches of the entire phrase. Using the EuiHighlight example text:

The quick brown fox jumped over the lazy dog

fox dog fails to highlight anything:

image

fox jumped works

image

fox works (as does fox with a space before/after, with the space unexpectedly highlighted)

image

dog works

image

Activity

  1. pickypg commented on Apr 15, 2022

    @pickypg
    MemberAuthor

    It occurred to me after filing this that it may be helpful to simply support the search parameter as string | string[], and simply loop over all of the searches supplied to highlight, which would basically support any use case of highlighting (including phrase and individual word).

  2. thompsongl commented on Apr 15, 2022

    @thompsongl
    Contributor

    string | string[]

    Yeah that makes sense to me

  3. github-actions commented on Oct 12, 2022

    @github-actions

    👋 Hey there. This issue hasn't had any activity for 180 days. We'll automatically close it if that trend continues for another week. If you feel this issue is still valid and needs attention please let us know with a comment.

  4. added
    stale-issue
    on Oct 12, 2022
  5. pickypg commented on Oct 12, 2022

    @pickypg
    MemberAuthor

    Still relevant.

  6. removed
    stale-issue
    on Oct 12, 2022
  7. github-actions commented on Apr 11, 2023

    @github-actions

    👋 Hey there. This issue hasn't had any activity for 180 days. We'll automatically close it if that trend continues for another week. If you feel this issue is still valid and needs attention please let us know with a comment.

  8. added
    stale-issue
    on Apr 11, 2023
  9. pickypg commented on Apr 11, 2023

    @pickypg
    MemberAuthor

    Still relevant.

  10. removed
    stale-issue
    on Apr 11, 2023
  11. rtyley commented on Jun 16, 2023

    @rtyley

    It occurred to me after filing this that it may be helpful to simply support the search parameter as string | string[],

    As a workaround to achieve the desired behaviour, users can achieve multiple differing highlights without modification of EuiHighlight, because as it happens EUIHightlight internally uses a regex-based implementation to find chunks to highlight, and doesn't currently regex-escape the searchValue input:

    const regex = new RegExp(searchValue, isStrict ? 'g' : 'gi');

    ...so you can actually directly pass it any regex you like - ie you can pass it a regex alternation for all the terms you care about (eg jumped|dog|quiCK):

    image

    To construct the regex, just place a pipe symbol (|) between the different terms.

    Ideally EuiHighlight should probably either document that it accepts a regex expression, or regex-escape the input. Note that it's possible to crash any page with a 'hightlight all' EuiHighlight on it by entering .* as the search term (the page freezes before the typed * even appears):

    Screen.Recording.2023-06-16.at.15.42.29.mov
  12. MattInternet commented on Jul 30, 2023

    @MattInternet

    Was excited about this workaround until you pointed out the page-crash bug...

  13. github-actions commented on Jan 27, 2024

    @github-actions

    👋 Hi there - this issue hasn't had any activity in 6 months. If the EUI team has not explicitly expressed that this is something on our roadmap, it's unlikely that we'll pick this issue up. We would sincerely appreciate a PR/community contribution if this is something that matters to you! If not, and there is no further activity on this issue for another 6 months (i.e. it's stale for over a year), the issue will be auto-closed.

  14. added
    stale-issue
    on Jan 27, 2024
  15. pickypg commented on Jan 27, 2024

    @pickypg
    MemberAuthor

    Still useful.

  16. removed
    stale-issue
    on Jan 27, 2024
  17. added
    low hanging fruit
    help wanted
    on Jan 30, 2024
  18. github-actions commented on Jan 30, 2024

    @github-actions
  19. self-assigned this
    on Jan 31, 2024
  20. removed
    help wanted
    on Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

low hanging fruit

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions