Extending Search to Include Posts and Comments

Jason Denang Posted in Beginning Developers 5 years 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,
Jason

Replies
ma Melo lobo Replied 2 years ago

.

ma Melo lobo Replied 2 years ago

I think I found a solution but that requires your approval of course. I modified the ossn_com file as follows:

    $wall = new OssnWall;
    $query = input('q');
    $search_options = array("search_type" => true, "description" => $query, 'type' => 'user',
            'distinct' => true);

    //if not admin user add where caluse to limit reach
    if(!ossn_isAdminLoggedin()){

    $posts = $wall->SearchPosts($search_options);       
    $search_options['count'] = true;      
    $count = $wall->SearchPosts($search_options);

    }else{

$posts = $wall->getAllPosts(array('search_type' => true,
                                    'description' => $query,
                                    'type' => 'user',
                                    'distinct' => true));
$count = $wall->getAllPosts(array(
        'search_type' => true,
        'description' => $query,
        'type' => 'user',
        'distinct' => true,
        'count' => true,

));     


    }

    $found['users'] = $posts;
    $search = ossn_plugin_view('searchposts/search/view', $found);
    $search .= ossn_view_pagination($count);
    if(empty($posts)) {
        return ossn_print('ossn:search:no:result');
     }
        return $search;
German Michael Zülsdorff Replied 5 years 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 5 years 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

Best,
Jason

German Michael Zülsdorff Replied 5 years 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 5 years 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 5 years 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.

Jason

German Michael Zülsdorff Replied 5 years 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 5 years 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!
Jason

us Rishi B Replied 5 years 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. [emailremoved]