You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I currently have a company called "MyCompany", if I search it, it finds it:
Now if I add any keyword (from the tag of in the tagOptions), it will find it and highlight it:
OR
And this can be cumulated, so if I put multiple key words. Which is really bad because everytime you put another keyword it will exponentially re-appear and be re-highlighted. This can lead to out of memory on the server (only 7 keywords makes my server crash).
But, no one will search those keywords, right ?
Actually, yes it can happen more easily then you think. In the above examples I have the config wholeWord set to true to prevent the current issue. But if set to false, things can be even more sensitive.
Now I have a company called "Fire Wire", I simply search "f w" for a quick search, the issues arrises :
Why is this happening ?
This is because when you search and have spaces, each "term" are separately highlighted in This foreach:
One the first term has been highlighted, is proceeds to the seconds term, but now the highlighter is working on the newly changed string containing the highlighted word so considers it when searching.
How to resolve ?
When the search is performed is should be done without the previous highlighter, so either :
Each found result is replaced by a unique token. So only after when each search is done, it replaces the words. But this might lead to the same issue when you search small words like "lat" and the token contains it.
Each result removes the result from the string and keeps track of the position in the string, all added at the end. But the issue is that the position will change when proceeding to the next search term (same applies when inserting each needle back to the string).
Before performing the search, use regex to exclude previous tokens/needles. The only thing I can think of is that if a user is crazy enough to name its item the same name as the token, it wont be highlighted.
The text was updated successfully, but these errors were encountered:
stein-j
changed the title
The highlighter highlight itself
The highlighter highlights itself
Sep 12, 2022
Description:
In certain situations, the highlighter will highlight itself which creates two big issues:
I have in my config file (Note the tag and the tagOptions):
I currently have a company called "MyCompany", if I search it, it finds it:
Now if I add any keyword (from the tag of in the tagOptions), it will find it and highlight it:
OR
And this can be cumulated, so if I put multiple key words. Which is really bad because everytime you put another keyword it will exponentially re-appear and be re-highlighted. This can lead to out of memory on the server (only 7 keywords makes my server crash).
But, no one will search those keywords, right ?
Actually, yes it can happen more easily then you think. In the above examples I have the config
wholeWord
set to true to prevent the current issue. But if set to false, things can be even more sensitive.Now I have a company called "Fire Wire", I simply search "f w" for a quick search, the issues arrises :
Why is this happening ?
This is because when you search and have spaces, each "term" are separately highlighted in This foreach:
tntsearch/src/Support/Highlighter.php
Line 72 in 645f20c
One the first term has been highlighted, is proceeds to the seconds term, but now the highlighter is working on the newly changed string containing the highlighted word so considers it when searching.
How to resolve ?
When the search is performed is should be done without the previous highlighter, so either :
Each found result is replaced by a unique token. So only after when each search is done, it replaces the words. But this might lead to the same issue when you search small words like "lat" and the token contains it.
Each result removes the result from the string and keeps track of the position in the string, all added at the end. But the issue is that the position will change when proceeding to the next search term (same applies when inserting each needle back to the string).
Before performing the search, use regex to exclude previous tokens/needles. The only thing I can think of is that if a user is crazy enough to name its item the same name as the token, it wont be highlighted.
The text was updated successfully, but these errors were encountered: