mirror of
https://github.com/benbusby/whoogle-search.git
synced 2026-04-25 12:15:50 +03:00
[GH-ISSUE #904] [BUG] Most of the search terms are not bold in Chinese results #562
Labels
No labels
Fixed (Pending PR Merge)
Stale
bug
enhancement
enhancement
good first issue
help wanted
keep-open
needs more info
pull-request
question
theme
unfortunate
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/whoogle-search#562
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ghost on GitHub (Dec 11, 2022).
Original GitHub issue: https://github.com/benbusby/whoogle-search/issues/904
Describe the bug
Most of the search terms are not bold in Chinese results.
Whoogle results:

Google results for reference:

To Reproduce
Search "新聞" or any other term in Chinese.
Deployment Method
Version of Whoogle Search
Desktop (please complete the following information):
@ahmad-alkadri commented on GitHub (Jan 6, 2023):
I managed to duplicate this issue on my local and other public instances of Whoogle.
I think the problem stems from the regex expression on this line:
github.com/benbusby/whoogle-search@ccf9f06f2f/app/utils/results.py (L74)Basically what this regex does is it looks for words matching the query, but only if the words stand on their own or there are no other characters before or after it (other than whitespaces). Then, if it found matches, the function will modify those matches with bold text.
This is why the characters
新聞in the stringGoogle 新聞will be made into bold like this:Google <b>新聞</b>while in匯集了世界各地的新聞來源it will not be touched at all.I think a simple fix would be removing the
\bin\b((?![{{}}<>-]){target_word}(?![{{}}<>-]))\b, so it'll become((?![{{}}<>-]){target_word}(?![{{}}<>-])). I've tested this fix on my local instance and it seems to work for even the other Chinese characters:Comparison with the search result from a public instance with the original regex expression:
The implication of this change would be, of course, modifying other words/queries to bold even if they are not standing on their own. For example: with the query
murakami, the stringthismurakamiisanauthorwill also be modified intothis<b>murakami</b>isanauthor. This could thus be a design change.I would like your opinion, @benbusby, on this subject. if you agree with this modification, I can push it and open a PR. What do you think?
@benbusby commented on GitHub (Jan 7, 2023):
@ahmad-alkadri I think the best approach would be to look up the user's configured language and use a separate regex command if that language is part of predefined list of languages (Chinese, Japanese, etc) that should ignore whitespace on either side of the search term (your proposed solution). Otherwise it should continue to use the existing regex.
I'm not a language expert by any stretch, but at least with English searches, I don't think the expected behavior would be to bold every search term on the result page regardless of where it appears (i.e. a search containing "a" or "the" would bold a lot of terms that the user probably wouldn't care about). The way around this would be to support separate, language-dependent behaviors.
@ahmad-alkadri commented on GitHub (Jan 7, 2023):
Thank you for your reply @benbusby and yes I agree with you on this part:
On the other hand, taking into account merely the user's configured language might not be enough I think. There could be certain scenarios where the user's using English as their configured language but the query isn't. Example: I sometimes searched for things like
Kanji 友達 how to write. Some results are as follow:On that page, as you see, if we want to modify the instances of the queries to bold we need to apply the normal regex and the one that ignores the whitespace.
Ideally, the app should detect whether each word on the result page contains Chinese characters or not, probably by using some kind of Unicode detection. The app should then implement the normal regex for the words that do not contain Chinese characters (thus, not ignoring whitespace) while for the words that contain Chinese characters, it would use the regex that ignores the whitespace. What do you think?
@benbusby commented on GitHub (Jan 7, 2023):
That sounds great. Rather than searching the result page though, you could actually just check if
target_wordinbold_search_terms.replace_any_caseis Chinese and apply the regex that doesn't check for whitespace. That way each search term would be bolded differently. Maybe that's what you already meant, just wanted to clarify.@ahmad-alkadri commented on GitHub (Jan 7, 2023):
@benbusby completely agree with this approach of yours. I'll try to implement this and push for a PR ASAP. I'll tag you once it's done. Thanks!
@ahmad-alkadri commented on GitHub (Jan 9, 2023):
Hi @benbusby ; I’ve made the PR last night at #928. I’ve included finally not only Chinese characters but also Japanese and Korean. I’m available for any follow-up discussions on this. Thanks.