-
Notifications
You must be signed in to change notification settings - Fork 296
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
Highlight search results #205
Comments
Great idea! |
+1 |
function highLightSearchTerms($string,$searchterm){
if (is_array($searchterm)){$searchterm=implode('', $searchterm); }
$repl='<em class="highlight_term">'.$searchterm.'</em>';
$replreg='\\1<em class="highlight_term">\\2</em>';
$rule='(?<!href="|src=")(.+)('.$searchterm.')';
return mb_eregi_replace($rule,$replreg,parse($string));
} https://github.com/broncowdd/Shinterest/blob/master/inc/functions.php |
I have something more or less working: ArthurHoaro/Shaarli:search-highlight I think this should be put on hold for now. #445 could help. |
How it works: 1. when a fulltext search is made, Shaarli looks for the first occurence position of every term matching the search. No change here, but we store these positions in an array, in Bookmark's additionalContent. 2. when formatting bookmarks (through BookmarkFormatter implementation): 1. first we insert specific tokens at every search result positions 2. we format the content (escape HTML, apply markdown, etc.) 3. as a last step, we replace our token with displayable span elements Cons: this tightens coupling between search filters and formatters Pros: it was absolutely necessary not to perform the search twice. this solution has close to no impact on performances. Fixes shaarli#205
How it works: 1. when a fulltext search is made, Shaarli looks for the first occurence position of every term matching the search. No change here, but we store these positions in an array, in Bookmark's additionalContent. 2. when formatting bookmarks (through BookmarkFormatter implementation): 1. first we insert specific tokens at every search result positions 2. we format the content (escape HTML, apply markdown, etc.) 3. as a last step, we replace our token with displayable span elements Cons: this tightens coupling between search filters and formatters Pros: it was absolutely necessary not to perform the search twice. this solution has close to no impact on performances. Fixes shaarli#205
How it works: 1. when a fulltext search is made, Shaarli looks for the first occurence position of every term matching the search. No change here, but we store these positions in an array, in Bookmark's additionalContent. 2. when formatting bookmarks (through BookmarkFormatter implementation): 1. first we insert specific tokens at every search result positions 2. we format the content (escape HTML, apply markdown, etc.) 3. as a last step, we replace our token with displayable span elements Cons: this tightens coupling between search filters and formatters Pros: it was absolutely necessary not to perform the search twice. this solution has close to no impact on performances. Fixes shaarli#205
When doing a full text search, return the results with matching text highlighted.
Implemented in the https://github.com/broncowdd/Shinterest fork
The text was updated successfully, but these errors were encountered: