Skip to:
Content
Pages
Categories
Search
Top
Bottom

Highlighting Activity Search Terms

  • Avatar of Nm
    nm
    Participant

    @nahummadrid

    I’m working with an activity search template. Has anyone come across a way to highlight search terms in a activity stream search result?

Viewing 7 replies - 1 through 7 (of 7 total)
  • @nahummadrid This is something that I would want as well. I’m going to try to develop this, I’ll post something if I get something working.

    Thanks,

    @nahummadrid I wrote a way to highlight activity stream. I’m using the global unified search from @sbrajesh Also I am using wp 3.2.1 and bp 1.2.9. I went back to an older version because I needed the global search to work. The next thing I’m trying to do is see if the global search for the comments to updates as well, then highlight those results. Here is my test site here.

    http://chr313.powweb.com/1.2.9/

    In your functions file add these:

    function highlight($needle, $haystack){
    $ind = stripos($haystack, $needle);
    $len = strlen($needle);
    if($ind !== false){
    return substr($haystack, 0, $ind) . '' . substr($haystack, $ind, $len) . '' .
    highlight($needle, substr($haystack, $ind + $len));
    } else return $haystack;
    }

    function bp_activity_content_body_return($activity_body) {
    $activity_body = highlight($activity_body, bp_get_activity_content_body());
    echo $activity_body;
    }

    In your theme file under
    /themes/bp-addata/activity/entry.php replace the exising contents of div activity inner with this

    if (isset($_POST)){
    bp_activity_content_body_return($_REQUEST)
    }else{
    bp_activity_content_body()
    }

    In your css file add
    #highlighter {
    background-color: #FFEE5A;
    }

    Hope that works for you,

    Avatar of Nm
    nm
    Participant

    @nahummadrid

    @chr313 cool couldn’t get it working at first, but I modified this

    `function highlight($needle, $haystack){
    $ind = stripos($haystack, $needle);
    $len = strlen($needle);
    if($ind !== false){

    return substr($haystack, 0, $ind) . ‘‘ . substr($haystack, $ind, $len) . ‘‘ . highlight($needle, substr($haystack, $ind + $len));
    } else {
    return $haystack;
    }
    }
    `
    and was able to get it working with 3.2.1 & 1.5

    One thing though, i’m seeing now…if the keyword is found in thumbnail image url, it breaks the image and link because the highlight is inserted in the url. any ideas.

    @nahummadrid ok good, yeah it was hard to paste code here, it left out some markup. Can you give me an example? Can you send your url and a sample search?

    @nahummadrid Can I ask you if your using some sort of site wide search for your 1.5 install? I had to go back to 1.2.9 to get it working.

    Thank you,

    Avatar of Nm
    nm
    Participant

    @nahummadrid

    @chr313 no not any special sitewide search, per se. I just create a page template for searching just activity. something like this more or less.

    `

    <form name ="form1" method="post" class="profile-search-form" action="/search”>

    <input type="Submit" name="Submit1" id="searchsubmit" value="” />

    `

    `

    `

    basically that in the main body of the search page template. It’s not perfect, and probably not great at all…but it’s as far as I got and it does the job for searching the activity stream. I know when I try leave the page I get a prompt from the browser asking me if I’m sure I want to leave. So if any ideas how this can be improved…i’d love to hear it.

    @nahummadrid i see if can do something with it i will let you know. Can you send your url and a sample search? so i can see if i can fix the broken image problem?

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.