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

Highlight search results #205

Closed
nodiscc opened this issue Apr 27, 2015 · 4 comments · Fixed by #1588
Closed

Highlight search results #205

nodiscc opened this issue Apr 27, 2015 · 4 comments · Fixed by #1588
Labels
enhancement filter datastore queries
Milestone

Comments

@nodiscc
Copy link
Member

nodiscc commented Apr 27, 2015

When doing a full text search, return the results with matching text highlighted.

Implemented in the https://github.com/broncowdd/Shinterest fork

@alexisju
Copy link

Great idea!

@nodiscc nodiscc added this to the 1.1 milestone May 6, 2015
@virtualtam virtualtam modified the milestones: 1.1, 0.8.0 Jul 30, 2015
@ArthurHoaro
Copy link
Member

+1

@alexisju
Copy link

alexisju commented Dec 8, 2015

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

@virtualtam virtualtam added the filter datastore queries label Jan 8, 2016
@ArthurHoaro
Copy link
Member

I have something more or less working: ArthurHoaro/Shaarli:search-highlight
Except this is not doable with the current Markdown plugin. I started to work toward a modulable formatter for links, but data link fields and displayable link fields got mixed up and the result isn't really satisfying.

I think this should be put on hold for now. #445 could help.

@ArthurHoaro ArthurHoaro modified the milestones: 0.11.0, 0.9.0 Mar 12, 2017
@ArthurHoaro ArthurHoaro modified the milestones: 0.11.0, 0.11.1 Jul 27, 2019
@ArthurHoaro ArthurHoaro modified the milestones: 0.11.1, 0.11.2 Aug 7, 2019
@ArthurHoaro ArthurHoaro modified the milestones: 0.12.0, 0.12.1 Sep 3, 2020
ArthurHoaro added a commit to ArthurHoaro/Shaarli that referenced this issue Oct 12, 2020
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
ArthurHoaro added a commit to ArthurHoaro/Shaarli that referenced this issue Oct 16, 2020
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
ArthurHoaro added a commit to ArthurHoaro/Shaarli that referenced this issue Oct 16, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement filter datastore queries
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants