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

[EuiHighlight] Highlight separated words #5798

Closed
pickypg opened this issue Apr 15, 2022 · 11 comments · Fixed by #7496
Closed

[EuiHighlight] Highlight separated words #5798

pickypg opened this issue Apr 15, 2022 · 11 comments · Fixed by #7496
Assignees
Labels
feature request low hanging fruit An issue, often a bug, that is lower effort and clearly ought to be fixed

Comments

@pickypg
Copy link
Member

pickypg commented Apr 15, 2022

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

@pickypg
Copy link
Member Author

pickypg commented Apr 15, 2022

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).

@thompsongl
Copy link
Contributor

string | string[]

Yeah that makes sense to me

@github-actions
Copy link

👋 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.

@pickypg
Copy link
Member Author

pickypg commented Oct 12, 2022

Still relevant.

@github-actions
Copy link

👋 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.

@pickypg
Copy link
Member Author

pickypg commented Apr 11, 2023

Still relevant.

@rtyley
Copy link

rtyley commented Jun 16, 2023

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

@MattInternet
Copy link

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

Copy link

👋 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.

@pickypg
Copy link
Member Author

pickypg commented Jan 27, 2024

Still useful.

@JasonStoltz JasonStoltz added low hanging fruit An issue, often a bug, that is lower effort and clearly ought to be fixed help wanted The EUI team is looking for community members to pick up and implement this issue labels Jan 30, 2024

This comment was marked as outdated.

@cee-chen cee-chen self-assigned this Jan 31, 2024
@cee-chen cee-chen removed the help wanted The EUI team is looking for community members to pick up and implement this issue label Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request low hanging fruit An issue, often a bug, that is lower effort and clearly ought to be fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants