Extending Search to Include Posts and Comments

Jason Denang Posted in Beginning Developers 3 months ago

Hi All,
I'm having a lot of trouble with this one. I would like to also make search consider wall posts and comments. Where should I be working?

Thank you,

German ~Z~ Man Replied 3 months ago

Thank you so much for making a complete component available, Jason.

I think this may not only motivate other members to contribute their own Ossn enhancements, but also helps to find bugs, optimize the code, or discuss completely different solutions.

us Jason Denang Replied 3 months ago

Hi Z-man,
I tried to add a response with examples, but I got an error message stating "Can not add reply". I also tried wrapping my code examples in the code braces atop this editor, but it was breaking in the preview.

I have created a repository on github. I added the component here


German ~Z~ Man Replied 3 months ago

You may edit my posts, yes, but I doubt you can save your edition.

BTW I would like to take this opportunity to remind you of the terms and conditions of this forum that you agreed to when you registered. In particular:

If you solved your issue you should post the steps you followed to
solve issue.

Of course we're all happy that you solved your idea "in surprisingly a very short period of time", but we would be happier if you would have told us HOW you did it.

us Jason Denang Replied 3 months ago

Also, Z-Man... I'm able to edit your posts. Once I'm logged in I have the ability to edit anyone's post or response. ** Edit ** I am trying to show the image, but this editor is making the following entry instead https://imgur.com/PM7gc2b
! [ Screen Sho t ][ 1 ]

us Jason Denang Replied 3 months ago

Thanks everyone for the input and help (Rishi). I was able to get this done in surprisingly a very short period of time. Working great and exactly what I wanted. Thanks again.


German ~Z~ Man Replied 3 months ago

You asked what you're missing.
Reading the documentation in first place, perhaps? As explained in https://www.opensource-socialnetwork.org/wiki/view/704/should-i-modify-core-files
altering of core files is a no-go.

Thanks to the modular concept of Ossn any new feature or improvement can be achieved by additional components. Aside from that: Any Database operation needs extra care and understanding - without results may be dangerous and unpredictable. Thus instead of blindly 'cloning' existing code I'd recommend to

  • start with a clean new Ossn
  • use PHPMyAdmin and note already existing rows of data
  • Do one action (like adding a post or a comment)
  • grab PHPMyAdmin again and compare the changes
  • study the classes/methods responsible for these changes
  • develop a new component extending the class you found in the last step and add your own method to retrieve what you need.
us Jason Denang Replied 3 months ago

Hi Bansh Rishi. I have just sent an email to you. I also just downloaded a copy of Who is Online to begin working. Should be pretty easy, but we shall see.

Thank you!

us Bansh33 - Replied 3 months ago

you can email me about this if you want, I was able to modify the free WhoIsOnline component pretty easily to search post contents. Should be simple enough to add comments to that if you are so inclined. rishi[at]rishisco.de

us Jason Denang Replied 3 months ago

While I feel like I'm getting closer to working this out, I'm getting some results that I just don't understand. So far I have cloned into /components/OssnComments/classes/OssnComments.php

        public function searchComments($q, array $args = array()) {
            $params["from"]    = "ossn_object";
            $params["type"]    = "user";
            $params["subtype"] = "wall";
            $params["wheres"]  = array(
                    "(title LIKE "%{$q}%" OR description LIKE "%{$q}%")"
            $vars              = array_merge($params, $args);
            $search            = $this->searchObject($vars, true);
            if(!$search) {
                    return false;
            if($vars["count"] === true) {
                    return $search;
            foreach($search as $comment) {
                    $commententity[] = ossn_get_comment($comment->guid);
            $data = $commententity;
            return $data;

In /components/OssnComments/ossn_com.php I have added

ossn_add_hook("search", "type:wall", "comment_search_handler");
    function comment_search_handler($hook, $type, $return, $params) {
        $comments = new OssnComments;
        $data   = $comments->searchComments($params["q"]);
        $count  = $comments->searchComments($params["q"], array(
                "count" => true

        $comment["user"] = $data;
        $search          = ossn_plugin_view("user/search/view", $comment);
        $search .= ossn_view_pagination($count);
        if(empty($data)) {
                return ossn_print("ossn:search:no:result");
        return $search;

and when my url is http://www.site,com/search?type=wall&q=hello

I get this

Exception: Call to undefined method OssnComments:searchObject in /home/hostname/public_html/classes/OssnBase.php:74 Stack trace:#0 /home/hostname/public_html/components/OssnComments/classes/OssnComments.php(27): OssnBase->__call("searchObject", Array)#1 /home/hostname/public_html/components/OssnComments/ossn_com.php(58): OssnComments->searchComments("hello")#2 /home/hostname/public_html/libraries/ossn.lib.system.php(223): comment_search_handler("search", "type:wall", NULL, Array)#3 /home/hostname/public_html/components/OssnSearch/ossn_com.php(45): ossn_call_hook("search", "type:wall", Array)#4 /home/hostname/public_html/libraries/ossn.lib.page.php(67): ossn_search_page(Array, "search")#5 /home/hostname/public_html/index.php(22): ossn_load_page("search, Array)#6 {main}

What am I missing or doing wrong? Please.

Thank You,