Subject: Plugin updates for the new search API

Posted on: 25/05/09 03:26pm
By: sbarakat

This is for those people who have tried out Geeklog 1.6.0 beta 1 and are having issues with the new search engine. Many of these issues stem from variations in the search API, some work was done to provide backwards compatibility but there is only so much I can do. The old API just did not return the data that was needed. So here I have provided some patches for some of the main plugins. Hopefully this will give you a better user experience.

DISCLAIMER
Before you start make sure to take a backup of the /plugins/<plugin_name>/functions.inc file. I cannot be held responsible for any damage that's done to your websites. I am simply providing this information to help people out, its up to you whether or not you want to try it. I have not used any of these plugins before so this code has not been fully tested. The code was built upon the plugins versions that were found on this site (whether these are the latest...I don't know).

But it *should* work... Smile

To apply these patches open up the relevant /plugins/<plugin_name>/functions.inc file and find the plugin_dopluginsearch_<plugin_name> function. Then simply replace the entire function with the relevant one below.

FAQ Manager 0.8.1
PHP Formatted Code
/**
* This searches for faqs matching the user query and returns an object
* back to search.php where it will be formated and printed.
*
* @param    string  $query      Keywords user is looking for
* @param    date    $datestart  Start date to get results for (not used)
* @param    date    $dateend    End date to get results for (not used)
* @param    string  $topic      The topic they were searching in (not used)
* @param    string  $type       Type of items they are searching, or 'all' (deprecated)
* @param    int     $author     Get all results by this author (not used)
* @param    string  $keyType    search key type: 'all', 'phrase', 'any'
* @param    int     $page       page number of current search (deprecated)
* @param    int     $perpage    number of results per page (deprecated)
* @return   object              search result object
*
*/

function plugin_dopluginsearch_faqman($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage)
{
    global $_TABLES, $LANG_FAQ;

    // Make sure the query is SQL safe
    $query = trim(addslashes($query));

    $sql = "SELECT topicID AS id, question AS title, answer AS description, ";
    $sql .= "CONCAT('/faqman/index.php?op=view&amp;t=', topicID) AS url ";
    $sql .= "FROM {$_TABLES['faq_topics']} topic LEFT JOIN {$_TABLES['faq_categories']} category ON topic.catID = category.catID ";
    $sql .= "WHERE 1=1 ";

    $search = new SearchCriteria('faqman', $LANG_FAQ['searchlabel']);
    $columns = array('title' => 'question', 'answer', 'keywords');
    list($sql,$ftsql) = $search->buildSearchSQL($keyType, $query, $columns, $sql);
    $search->setSQL($sql);
    $search->setFTSQL($ftsql);
    $search->setRank(3);

    return $search;
}


File Management 1.5.3
PHP Formatted Code
/**
* This searches for files matching the user query and returns an object
* back to search.php where it will be formated and printed.
*
* @param    string  $query      Keywords user is looking for
* @param    date    $datestart  Start date to get results for
* @param    date    $dateend    End date to get results for
* @param    string  $topic      The topic they were searching in
* @param    string  $type       Type of items they are searching, or 'all' (deprecated)
* @param    int     $author     Get all results by this author
* @param    string  $keyType    search key type: 'all', 'phrase', 'any'
* @param    int     $page       page number of current search (deprecated)
* @param    int     $perpage    number of results per page (deprecated)
* @return   object              search result object
*
*/

function plugin_dopluginsearch_filemgmt($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage)
{
    global $_FM_TABLES, $LANG_FILEMGMT;

    // Make sure the query is SQL safe
    $query = trim(addslashes($query));

    $sql  = "SELECT a.lid AS id, a.submitter AS uid, a.title, a.hits, a.date, c.description, ";
    $sql .= "CONCAT('/filemgmt/index.php?id=', a.lid) AS url ";
    $sql .= "FROM {$_FM_TABLES['filemgmt_filedetail']} a ";
    $sql .= "LEFT JOIN {$_FM_TABLES['filemgmt_cat']} b ON b.cid=a.cid ";
    $sql .= "LEFT JOIN {$_FM_TABLES['filemgmt_filedesc']} c ON c.lid=a.lid ";
    $sql .= filemgmt_buildAccessSql('WHERE') . " AND a.status > 0 ";

    if (!empty($datestart) && !empty($dateend))
    {
        $delim = substr($datestart, 4, 1);
        if (!empty($delim))
        {
            $DS = explode($delim, $datestart);
            $DE = explode($delim, $dateend);
            $startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]);
            $enddate = mktime(23,59,59,$DE[1],$DE[2],$DE[0]);
            $sql .= "AND (date BETWEEN '$startdate' AND '$enddate') ";
        }
    }
    if (!empty($author)) {
        $sql .= "AND (submitter = '$author') ";
    }

    $search = new SearchCriteria('filemgmt', $LANG_FILEMGMT['searchlabel']);
    $columns = array('title' => 'a.title', 'c.description');
    list($sql,$ftsql) = $search->buildSearchSQL($keyType, $query, $columns, $sql);
    $search->setSQL($sql);
    $search->setFTSQL($ftsql);
    $search->setRank(3);

    return $search;
}


Forum 2.7.2
PHP Formatted Code
/**
* This searches for forum posts matching the user query and returns an object
* back to search.php where it will be formated and printed.
*
* @param    string  $query      Keywords user is looking for
* @param    date    $datestart  Start date to get results for
* @param    date    $dateend    End date to get results for
* @param    string  $topic      The topic they were searching in
* @param    string  $type       Type of items they are searching, or 'all' (deprecated)
* @param    int     $author     Get all results by this author
* @param    string  $keyType    search key type: 'all', 'phrase', 'any'
* @param    int     $page       page number of current search (deprecated)
* @param    int     $perpage    number of results per page (deprecated)
* @return   object              search result object
*
*/

function plugin_dopluginsearch_forum($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage)
{
    global $_TABLES, $LANG_GF00;

    // Make sure the query is SQL safe
    $query = trim(addslashes($query));

    $sql = "SELECT id, uid, date, subject AS title, comment AS description, views AS hits, ";
    $sql .= "CONCAT('/forum/viewtopic.php?forum=', forum, '&amp;showtopic=', id) AS url ";
    $sql .= "FROM {$_TABLES['gf_topic']} WHERE 1=1 ";

    if (!empty($datestart) && !empty($dateend))
    {
        $delim = substr($datestart, 4, 1);
        if (!empty($delim))
        {
            $DS = explode($delim, $datestart);
            $DE = explode($delim, $dateend);
            $startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]);
            $enddate = mktime(23,59,59,$DE[1],$DE[2],$DE[0]);
            $sql .= "AND (date BETWEEN '$startdate' AND '$enddate') ";
        }
    }
    if (!empty ($author)) {
        $sql .= "AND (uid = '$author') ";
    }

    $search = new SearchCriteria('forum', $LANG_GF00['searchlabel']);
    $columns = array('title' => 'subject', 'comment');
    list($sql,$ftsql) = $search->buildSearchSQL($keyType, $query, $columns, $sql);
    $search->setSQL($sql);
    $search->setFTSQL($ftsql);
    $search->setRank(3);

    return $search;
}


Re: Plugin updates for the new search API

Posted on: 25/05/09 03:40pm
By: Anonymous

You do realize 99% of the admins won't find this thread in the future, right? In other words, v1.6 would break every major plugin for 99% of the admins.

Re: Plugin updates for the new search API

Posted on: 25/05/09 03:50pm
By: Dirk

Quote by: Guest

You do realize 99% of the admins won't find this thread in the future, right? In other words, v1.6 would break every major plugin for 99% of the admins.


Great way to encourage people :shock:

Hint: Plugins can be updated. 1.6.0 is not out yet. Once it is, "official" updates will follow.


Sami: Thanks for those. I did actually update the search for the File Management Plugin already myself (running here on geeklog.net). Will be interesting to compare with your implementation. I'll update the plugins on here tomorrow.

bye, Dirk

Re: Plugin updates for the new search API

Posted on: 25/05/09 04:08pm
By: sbarakat

Quote by: Guest

You do realize 99% of the admins won't find this thread in the future, right? In other words, v1.6 would break every major plugin for 99% of the admins.

The idea is to get the new API tested properly before v1.6 goes final. This post should also help plugin authors update their plugins as it provides a starting point...hopefully resulting in quicker official releases.

Quote by: Dirk

Sami: Thanks for those. I did actually update the search for the File Management Plugin already myself (running here on geeklog.net). Will be interesting to compare with your implementation. I'll update the plugins on here tomorrow.

Let me know if there is anything that needs changing and I can update the first post. I wrote and tested these very quickly so I may have missed something.

-Sami

Re: Plugin updates for the new search API

Posted on: 25/05/09 07:29pm
By: Anonymous

Quote by: Dirk

Hint: Plugins can be updated. 1.6.0 is not out yet. Once it is, "official" updates will follow.


Hint: Most of Geeklog's major plugins weren't updated in years. What makes you think their AWOL authors would suddenly be back from the dead? :shock:

Re: Plugin updates for the new search API

Posted on: 26/05/09 01:53pm
By: Dirk

Quote by: Guset

Hint: Most of Geeklog's major plugins weren't updated in years.


Other than maybe the File Management Plugin - which "major" plugins are you talking about?

bye, Dirk

Re: Plugin updates for the new search API

Posted on: 26/05/09 07:21pm
By: Anonymous

Forum, Faqman, MG. Chatterblock too but it's not searchable anyway.

Re: Plugin updates for the new search API

Posted on: 27/05/09 03:54am
By: Dirk

Quote by: Guest

Forum, Faqman, MG.


They've all had updates in recent months (Media Gallery being the oldest, back in September). You're exaggerating.

bye, Dirk

Re: Plugin updates for the new search API

Posted on: 11/06/09 01:14pm
By: Dirk

Minor improvement for the forum search: You don't need the 'forum=' parameter, which makes for shorter URLs:

PHP Formatted Code
$sql .= "CONCAT('/forum/viewtopic.php?showtopic=', id) AS url ";


bye, Dirk

Re: Plugin updates for the new search API

Posted on: 30/06/09 06:51pm
By: sbarakat

A little update for the FAQ Manager plugin...
It seems to return results when searching for an author. It can be stopped by by placing this code just after the global declarations:
PHP Formatted Code
if (!empty($author)) {
    return;
}

It also may be worth doing the same with $datestart and $dateend.

I cant seem to edit my first post so this will have to do.

Sami

Re: Plugin updates for the new search API

Posted on: 30/08/09 10:37pm
By: suprsidr

Decided to add gallery search to the G2Bridge plugin.

It appears the new search API does not allow me to return results. But instead only search params for searching geeklog's tables.

So how are plugins with external apps or dependencies supposed to contribute to search results?

-s

Re: Plugin updates for the new search API

Posted on: 31/08/09 12:36am
By: jmucchiello

I didn't say that specifically but the big SQL query search api was a concern of mine all those months ago.

Re: Plugin updates for the new search API

Posted on: 01/09/09 10:24pm
By: suprsidr

So how are plugins with external apps or dependencies supposed to contribute to search results?

I guess they are not.

-s

Re: Plugin updates for the new search API

Posted on: 02/09/09 03:38pm
By: sbarakat

Quote by: suprsidr

So how are plugins with external apps or dependencies supposed to contribute to search results?

I guess they are not.

-s



hey,
your right, currently the search api does not support this, which is obviously a problem. i will look into it and hopefully get it in before the next gl release. the listfactory (which the search engine hangs off) already has to ability to set predefined results, so there will probably be an extra function to the api, eg SearchCriteria::SetResults(array)

-Sami

Re: Plugin updates for the new search API

Posted on: 08/09/09 12:15pm
By: LWC

I've just submitted a comment to file , but it just took me (without submitting the comment, mind you) to filemgmt/index.php/fileid_980, which is just filemgmt/index.php - is this related to all of this?

Re: Plugin updates for the new search API

Posted on: 04/02/10 09:43pm
By: suprsidr

Adding search for my G2Bridge plugin now that GL1.6 .1 allows for external results to be added(Yeah!)

My results are in fact included.
But notice the uid is not translated into a username->profileUrl for all results marked "media"

I am passing just the uid correct?
PHP Formatted Code
'uid'=>DB_getItem($_TABLES['users'], 'uid', "username = '{$owner->getUserName()}'")


Or am I supposed to build the url myself?

also being these are media objects I was hoping to display a tiny thumb, but it seems any html I pass gets filtered.
is it possible to pass html in the description and/or title fields?

-s

Re: Plugin updates for the new search API

Posted on: 06/02/10 08:25am
By: suprsidr

w/ the lack of a response I answered my own questions:
But notice the uid is not translated into a username->profileUrl .... I am passing just the uid correct? .... Or am I supposed to build the url myself?

using SearchCriteria->setResults
the Doc's say to format your results:
PHP Formatted Code

array(
            LF_SOURCE_NAME => 'myplugin',
            LF_SOURCE_TITLE => 'My Plugin',
            'title' => 'Custom Result 2',
            'description' => 'This is a custom result',
            'date' => '1256058000',
            'url' => '/internal/page/custom2',
            'hits' => 20000,
            'uid' => 2
        )
 

But you actually want to format the uid as an full html profile url.
http://wiki.geeklog.net/index.php/Using_Geeklog%27s_Improved_Search_Engine#Including_External_Results should be updated.

is it possible to pass html in the description and/or title fields?

I actually tacked it onto the html I passed in the uid field.
So I'm able to provide a preview image.

-s

Re: Plugin updates for the new search API

Posted on: 06/02/10 10:11am
By: Laugh

That is a good work around (though your example didn't show any images, I searched for "percy" to bring up something). I ran into a similar issue a while back which I just left. I will add this to the search feature request so it can be implemented properly in the future. (Edit: Just added the info - http://project.geeklog.net/tracking/view.php?id=1006)

By the way I like how you show your gallery images in the what's new block on your homepage.

Tom

Re: Plugin updates for the new search API

Posted on: 06/02/10 10:21am
By: suprsidr

though your example didn't show any images, I searched for "percy" to bring up something

Thanks for that, I had my session handler commented out. - fixed.



By the way I like how you show your gallery images in the what's new block on your homepage.

Thanks again... just playing with that idea at the moment - good to get some feedback.

-s

Re: Plugin updates for the new search API

Posted on: 06/02/10 10:55am
By: Laugh

Thanks again... just playing with that idea at the moment - good to get some feedback.


No problem, you do good work and I have always liked the look of your site. At some point in the future I may talk to you about hiring you to do some graphic/theme work for me.

Tom

Re: Plugin updates for the new search API

Posted on: 06/02/10 12:00pm
By: suprsidr

I have always liked the look of your site. At some point in the future I may talk to you about hiring you to do some graphic/theme work for me.

As much as I'd love to take credit for that, gdl is the graphic artist.
I'm just the mechanic :wink:

-s

Re: Plugin updates for the new search API

Posted on: 06/02/10 03:40pm
By: sbarakat

Quote by: suprsidr


using SearchCriteria->setResults
the Doc's say to format your results:

PHP Formatted Code

array(
            LF_SOURCE_NAME => 'myplugin',
            LF_SOURCE_TITLE => 'My Plugin',
            'title' => 'Custom Result 2',
            'description' => 'This is a custom result',
            'date' => '1256058000',
            'url' => '/internal/page/custom2',
            'hits' => 20000,
            'uid' => 2
        )
 

But you actually want to format the uid as an full html profile url.
http://wiki.geeklog.net/index.php/Using_Geeklog%27s_Improved_Search_Engine#Including_External_Results should be updated.



Thats odd I thought I had it working the with just the uid. I will have to get Geeklog installed again and do some testing, at the moment I'm just browsing through the source on project.geeklog.net. The only place I noticed where it might be falling over is line 674 of search.class.php where it checks that uid is a numeric value. Can you verify that there aren't any spaces lurking in there? Also it would be interesting to know if you also get the issue when using a callback function as described in the documentation.

Quote by: suprsidr


is it possible to pass html in the description and/or title fields?

I actually tacked it onto the html I passed in the uid field.
So I'm able to provide a preview image.

-s


I was not able to get any images displaying in my results Frown in fact im not getting any gallery results at all, just results from the usual story/static/forum plugins.
If you wanted to include HTML in the title/description that can be done. It will probably need to be an extra switch eg. $search->stripHtml(false);
But the issue would be when the text goes through the shortening algorithm, that centers the text around the keyword and puts it in bold. How would this be done if there is HTML involved as we need to make sure all tags are closed correctly. Or maybe if you disable the html stripping it also disables the truncation of the text? Then leave it to the plugin to deal with that? I dont know what would be the best here...ideas?

Re: Plugin updates for the new search API

Posted on: 06/02/10 04:23pm
By: Laugh

I say leave the text handling to the search class and maybe add the option of allowing the plugin to be able to insert html some where within the result (after the text description???).

Tom

Re: Plugin updates for the new search API

Posted on: 06/02/10 04:56pm
By: suprsidr

I was not able to get any images displaying in my results Sad in fact im not getting any gallery results at all, just results from the usual story/static/forum plugins.


Looks like anon users are not receiving a gallery session unless they visit gallery first.
I'll have to revisit that tonight. Thanks for the feedback.

-s

Re: Plugin updates for the new search API

Posted on: 04/05/10 01:37pm
By: ::Ben

Hello,

I try to update the dokuwiki search function and I need some help.

Here is my code :
PHP Formatted Code

function plugin_searchtypes_dokuwiki() {
    global $_CONF, $_DW_CONF, $_USER, $LANG_DW00;

    if ( COM_isAnonUser() && ( $_DW_CONF['loginrequired'] == 1 || $_CONF['loginrequired'] == 1) )  {
        return '';
    }
    if ($_DW_CONF['restrict_to_group'] != '' ) {
        if (!SEC_inGroup($_DW_CONF['restrict_to_group'])) {
            return '';
        }
    }

    $tmp['dokuwiki'] = $_DW_CONF['menulabel'];
    return $tmp;
}


/**
* this searches for pages matching the user query and returns an array of
* for the header and table rows back to search.php where it will be formated and
* printed
*
* @query            string          Keywords user is looking for
* @datestart        date/time       Start date to get results for
* @dateend          date/time       End date to get results for
* @topic            string          The topic they were searching in
* @type             string          Type of items they are searching
* @author           string          Get all results by this author
* @keyType        string          search key type: 'all', 'phrase', 'any'
* @param    int     $page       page number of current search (deprecated)
* @param    int     $perpage    number of results per page (deprecated)
*
*/


function plugin_dopluginsearch_dokuwiki($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage) {

    global $_CONF, $_DW_CONF;

    if ( $_DW_CONF['disable_search_integration'] == 1) {
        return '';
    }
    if ( COM_isAnonUser() && ( $_DW_CONF['loginrequired'] == 1 || $_CONF['loginrequired'] == 1) )  {
        return '';
    }
    if ($_DW_CONF['restrict_to_group'] != '' ) {
        if (!SEC_inGroup($_DW_CONF['restrict_to_group'])) {
            return '';
        }
    }

    // Bail if we aren't supppose to do our search
    if ($type <> 'all' AND $type <> 'dokuwiki') {
        return '';
    }

    $pages = DW_searchItems($query, $keyType);
    $search = new SearchCriteria('dokuwiki', $_DW_CONF['menulabel'],'');
    $search->setResults($pages);
    $search->setRank(4);
       
    return $search;

}

function DW_searchItems( $query, $keyType )
{
    global $_CONF, $_DW_CONF, $LANG_DW00, $formattedResults;
       
    require_once (DOKU_INC.'inc/init.php');
    require_once (DOKU_INC.'inc/common.php');
    require_once (DOKU_INC.'inc/events.php');
    require_once (DOKU_INC.'inc/pageutils.php');
    require_once (DOKU_INC.'inc/html.php');
    require_once (DOKU_INC.'inc/auth.php');
    require_once (DOKU_INC.'inc/actions.php');
    require_once ($_CONF['path_html'] . $_DW_CONF['public_dir'] . 'inc/search.php');
    require_once ($_CONF['path_html'] . $_DW_CONF['public_dir'] . 'inc/fulltext.php');
       
        if ($keyType == 'any') {
        $searchQuery = str_replace(' ', " OR ", $query);
    } else if ($keyType == 'all') {
        $searchQuery = str_replace(' ', " AND ", $query);
    } else {
        $searchQuery = '"'.$query.'"';
    }
       
        $QUERY = $searchQuery;
    //check if search is restricted to namespace
    if(preg_match('/([^@]*)@([^@]*)/',$QUERY,$match)) {
        $id = cleanID($match[1]);
        if(empty($id)) {
            return '';
        }
    } else {
        $id = cleanID($QUERY);
    }

    //do quick pagesearch
    $data = array();
    //do fulltext search
    $data = ft_pageSearch($QUERY,$poswords);

    if(count($data)){
        foreach($data as $id => $cnt){
            $fqn = wikiFN($id);
            $date = stat($fqn);
                        $formattedResults[] = array(LF_SOURCE_NAME=>$_DW_CONF['menulabel'],
                                        LF_SOURCE_TITLE=>$LANG_DW00['search_type'],
                                        'title'=>$id,
                                        'description'=>ft_snippet($id,$poswords),
                                        'date'=>$date['mtime'],
                                        'url'=>$_CONF['site_url'] . $_DW_CONF['public_dir']
                                    . 'doku.php?id=' . urlencode($id),
                                        'hits'=>$cnt,
                                        'uid'=>''
                                    );
        }
    } else {
        return '';
    }

    return $formattedResults;
}


All I get on a search (geeklog 1.7.0b1) is a 1065: Query was empty :banghead:

What I miss there?

::Ben

Re: Plugin updates for the new search API

Posted on: 05/05/10 08:00am
By: suprsidr

Nothing jumps out at me, that's the beauty of COM_errorlog - the ease of adding step by step logging and troubleshooting.

-s

Re: Plugin updates for the new search API

Posted on: 05/05/10 08:25am
By: sbarakat

I cant see anything that immediately sticks out. I haven't played round with DocuWiki yet, I will get it installed tonight and give this a go. Can I just confirm that your wanting to update the 1.5.2 version from the download section, http://www.geeklog.net/filemgmt/index.php?id=938 ?

On a related note, Dirk, is it not possible to update posts in the forum? Because I would like to update the code in the first post of this thread for the up coming 1.7.0 release.

(that's weird... this is the only post in this thread that has an Edit button for me)

Re: Plugin updates for the new search API

Posted on: 05/05/10 08:35am
By: suprsidr


(that's weird... this is the only post in this thread that has an Edit button for me)

You only have like 3 minutes to edit your post.

-s

Re: Plugin updates for the new search API

Posted on: 05/05/10 09:28am
By: ::Ben

Quote by: sbarakat

Can I just confirm that your wanting to update the 1.5.2 version from the download section, http://www.geeklog.net/filemgmt/index.php?id=938 ?



The dokuwiki update is ready (with last official dokuwiki core release and now online geeklog config). The only issue is the search function. I can send you the code if you want to play with.

::Ben

Re: Plugin updates for the new search API

Posted on: 07/05/10 06:45am
By: sbarakat

Quote by: cordiste

The dokuwiki update is ready (with last official dokuwiki core release and now online geeklog config). The only issue is the search function. I can send you the code if you want to play with.

I sent you a pm yesterday but didn't hear anything back.

I was playing around with the the API and noticed a logic error in the search engine. If using setResults() it also expects either a callback function or an SQL query. This is wrong and I will get a fix in some point soon (I'm currently in the office, so it may be tomorrow).

If you want to apply it to your current build open up system/classes/search.class.php around line 527 you have something like this
PHP Formatted Code
  $obj->setCallback($result->getLabel(), $result->getName(), $api_callback_func, $result->getRank(), $result->getTotal());
}
else
{
  if ($_CONF['search_use_fulltext'] == true && $result->getFTSQL() != '') {

Change the else to this
PHP Formatted Code
  $obj->setCallback($result->getLabel(), $result->getName(), $api_callback_func, $result->getRank(), $result->getTotal());
}
else if ($result->getSQL() != '' || $result->getFTSQL() != '')
{
  if ($_CONF['search_use_fulltext'] == true && $result->getFTSQL() != '') {



Side note: I have left the addResultArray() part on its own. I could have had all 3 statements in an 'if else' clause, eg. either addResultArray() or setCallback() or setQuery(). Which would mean plugins were only allowed to use a single method of including results. But I thought there might be a possibility that plugins might want to add one or two fixed results while also searching using an SQL query. I had sponsored listings in mind here. So the logic was to allow plugins to use either the SQL search or Callback methods while having setResults() as an optional extra. But I guess I didn't state that in the Wiki Documentation.

Re: Plugin updates for the new search API

Posted on: 07/05/10 07:00am
By: sbarakat

Just noticed something else in your code, you are making use of the $type variable which has been depreciated. You no longer need this block of code as its now handled in the core.
PHP Formatted Code
    // Bail if we aren't supppose to do our search
    if ($type <> 'all' AND $type <> 'dokuwiki') {
        return '';
    }

Re: Plugin updates for the new search API

Posted on: 07/05/10 09:57am
By: ::Ben

Hello and sorry for my late response. Private message plugin do not send me alert.

I also found a way to solve my issue :banana:

PHP Formatted Code

function plugin_dopluginsearch_dokuwiki($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage) {

    global $_CONF, $_DW_CONF;

    if ( $_DW_CONF['disable_search_integration'] == 1) {
        return '';
    }
    if ( COM_isAnonUser() && ( $_DW_CONF['loginrequired'] == 1 || $_CONF['loginrequired'] == 1) )  {
        return '';
    }
    if ($_DW_CONF['restrict_to_group'] != '' ) {
        if (!SEC_inGroup($_DW_CONF['restrict_to_group'])) {
            return '';
        }
    }

    // Bail if we aren't supppose to do our search
    if ($type <> 'all' AND $type <> 'dokuwiki') {
        return '';
    }

    $pages = DW_searchItems($query, $keyType);
    $search = new SearchCriteria('dokuwiki', $_DW_CONF['menulabel'],'text');
    $search->setSQL('--');
    $search->setFTSQL('--');
    $search->setResults($pages);
    $search->setRank(4);
       
        return $search;
}


Can I make a dokuwiki release with this solution?

::Ben

Re: Plugin updates for the new search API

Posted on: 07/05/10 10:17am
By: sbarakat

Yeah that would work, a nice way to get around the bug Smile

Again though it would be best to remove the use of $type

Re: Plugin updates for the new search API

Posted on: 07/05/10 12:39pm
By: ::Ben

Ok, I will remove the use of $type.

Thanks.

::Ben

Re: Plugin updates for the new search API

Posted on: 31/05/10 02:09pm
By: sbarakat

I've had these snippets prepared for some time, sorry its taken a while to post them here. Since the release of 1.7.0 there have been some bug fixes in the search. These code snippets fix a few more issues and have taken into account some updates mentioned previously in this thread. I haven't tested them fully so lets hope they work for you. For details on how to apply them read the first post.

FAQ Manager 0.8.1
* Disable when searching by date or author
* Fix crash when sorting by date
* Hide hits from search results
PHP Formatted Code
function plugin_dopluginsearch_faqman($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage)
{
    global $_TABLES, $LANG_FAQ;

    // Dont search when any of these are set
    if (!(empty($author) && empty($datestart) && empty($dateend))) {
        return;
    }

    // Make sure the query is SQL safe
    $query = trim(addslashes($query));

    $sql = "SELECT topicID AS id, question AS title, answer AS description, 0 AS date, 0 AS uid, 0 AS hits, ";
    $sql .= "CONCAT('/faqman/index.php?op=view&amp;t=', topicID) AS url ";
    $sql .= "FROM {$_TABLES['faq_topics']} topic LEFT JOIN {$_TABLES['faq_categories']} category ON topic.catID = category.catID ";
    $sql .= "WHERE 1=1 ";

    $search = new SearchCriteria('faqman', $LANG_FAQ['searchlabel']);

    $columns = array('title' => 'question', 'answer', 'keywords');
    list($sql,$ftsql) = $search->buildSearchSQL($keyType, $query, $columns, $sql);

    $search->setSQL($sql);
    $search->setFTSQL($ftsql);
    $search->setRank(3);

    return $search;
}


File Management 1.5.3
* Now searches file comments too.
PHP Formatted Code
function plugin_dopluginsearch_filemgmt($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage)
{
    global $_FM_TABLES, $LANG_FILEMGMT, $_TABLES, $LANG09;

    // Make sure the query is SQL safe
    $query = trim(addslashes($query));

    $sql  = "SELECT a.lid AS id, a.title, c.description, a.date, a.submitter AS uid, a.hits, ";
    $sql .= "CONCAT('/filemgmt/index.php?id=', a.lid) AS url ";
    $sql .= "FROM {$_FM_TABLES['filemgmt_filedetail']} a ";
    $sql .= "LEFT JOIN {$_FM_TABLES['filemgmt_cat']} b ON b.cid=a.cid ";
    $sql .= "LEFT JOIN {$_FM_TABLES['filemgmt_filedesc']} c ON c.lid=a.lid ";
    $sql .= filemgmt_buildAccessSql('WHERE') . " AND a.status > 0 ";

    if (!empty($datestart) && !empty($dateend))
    {
        $delim = substr($datestart, 4, 1);
        if (!empty($delim))
        {
            $DS = explode($delim, $datestart);
            $DE = explode($delim, $dateend);
            $startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]);
            $enddate = mktime(23,59,59,$DE[1],$DE[2],$DE[0]);
            $sql .= "AND (date BETWEEN '$startdate' AND '$enddate') ";
        }
    }
    if (!empty($author)) {
        $sql .= "AND (submitter = '$author') ";
    }

    $search_f = new SearchCriteria('filemgmt', $LANG_FILEMGMT['searchlabel']);

    $columns = array('title' => 'a.title', 'c.description');
    list($sql,$ftsql) = $search_f->buildSearchSQL($keyType, $query, $columns, $sql);

    $search_f->setSQL($sql);
    $search_f->setFTSQL($ftsql);
    $search_f->setRank(3);

    // Search file listing comments
    $sql = 'SELECT c.cid AS id, c.title AS title, c.comment AS description, ';
    $sql .= 'UNIX_TIMESTAMP(c.date) AS date, c.uid AS uid, \'0\' AS hits, ';

    // MSSQL has a problem when concatenating numeric values
    if ($_DB_dbms == 'mssql') {
        $sql .= '\'/comment.php?mode=view&amp;cid=\' + CAST(c.cid AS varchar(10)) AS url ';
    } else {
        $sql .= 'CONCAT(\'/comment.php?mode=view&amp;cid=\',c.cid) AS url ';
    }

    $sql .= 'FROM '.$_TABLES['comments'].' AS c ';
    $sql .= 'LEFT JOIN '.$_FM_TABLES['filemgmt_filedetail'].' AS f ON (\'fileid_\' + f.lid) = c.sid ';
    $sql .= 'WHERE (c.sid LIKE \'fileid_%\') ';

    $search_c = new SearchCriteria('comments', array($LANG_FILEMGMT['searchlabel'],$LANG09[66]));

    $columns = array('title' => 'c.title', 'comment');
    $sql .= $search_c->getDateRangeSQL('AND', 'c.date', $datestart, $dateend);
    list($sql, $ftsql) = $search_c->buildSearchSQL($keyType, $query, $columns, $sql);

    $search_c->setSQL($sql);
    $search_c->setFTSQL($ftsql);
    $search_c->setRank(2);

    return array($search_f, $search_c);
}


Forum 2.7.2
* Shorter urls (thanks Dirk)
PHP Formatted Code
function plugin_dopluginsearch_forum($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage)
{
    global $_TABLES, $LANG_GF00;

    // Make sure the query is SQL safe
    $query = trim(addslashes($query));

    $sql = "SELECT id, subject AS title, comment AS description, date, uid, views AS hits, ";
    $sql .= "CONCAT('/forum/viewtopic.php?showtopic=', id) AS url ";
    $sql .= "FROM {$_TABLES['gf_topic']} WHERE 1=1 ";

    if (!empty($datestart) && !empty($dateend))
    {
        $delim = substr($datestart, 4, 1);
        if (!empty($delim))
        {
            $DS = explode($delim, $datestart);
            $DE = explode($delim, $dateend);
            $startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]);
            $enddate = mktime(23,59,59,$DE[1],$DE[2],$DE[0]);
            $sql .= "AND (UNIX_TIMESTAMP(date) BETWEEN UNIX_TIMESTAMP('$startdate') AND UNIX_TIMESTAMP('$enddate')) ";
        }
    }
    if (!empty ($author)) {
        $sql .= "AND (uid = '$author') ";
    }

    $search = new SearchCriteria('forum', $LANG_GF00['searchlabel']);

    $columns = array('title' => 'subject', 'comment');
    list($sql,$ftsql) = $search->buildSearchSQL($keyType, $query, $columns, $sql);

    $search->setSQL($sql);
    $search->setFTSQL($ftsql);
    $search->setRank(3);

    return $search;
}

Re: Plugin updates for the new search API

Posted on: 01/11/10 05:34pm
By: Jokke_K

I tried to update forum's search function with patch in sbarakat's message. I pasted it over the code below, but after patching I noticed that Anonymous users get search results from restricted/access denied forum areas which they are not allowed to read.

Is this the right part of code to be replaced?

PHP Formatted Code
/**
* this searches for files matching the user query and returns an array of
* for the header and table rows back to search.php where it will be formated and
* printed
*
* @query            string          Keywords user is looking for
* @datestart        date/time       Start date to get results for
* @dateend          date/time       End date to get results for
* @topic            string          The topic they were searching in
* @type             string          Type of items they are searching
* @author           string          Get all results by this author
*
*/

function plugin_dopluginsearch_forum($query, $datestart, $dateend, $topic, $type, $author,$keyType,$page, $perpage)
{
    global $LANG_GF00, $LANG_GF01, $_TABLES, $_CONF, $CONF_FORUM;

    if (empty($type)) {
        $type = 'all';
    }
    // Bail if we aren't supppose to do our search
    if ($type <> 'all' AND $type <> 'forum') {
        $plugin_results = new Plugin();
        $plugin_results->plugin_name = $LANG_GF00['plugin_name'];
        $plugin_results->searchlabel = $LANG_GF00['searchlabel'];
        return $plugin_results;
    }

    // Build search SQL

    $sqltmp = " WHERE 1=1 ";

    if ( $keyType == 'phrase' ) {
        $sqltmp .= "AND (comment LIKE '%$query%' OR subject LIKE '%$query%')";
    } else  if ( $keyType == 'any' ) {
        $sqltmp .= 'AND ';
        $tmp = '';
        $mywords = explode( ' ', $query );
        foreach( $mywords AS $mysearchitem ) {
            $mysearchitem = addslashes( $mysearchitem );
            $tmp .= "( comment LIKE '%$mysearchitem%' OR subject LIKE '%$mysearchitem%' ) OR ";
        }
        $tmp = substr($tmp, 0, strlen($tmp) - 3);  // pulls off the last OR
        $sqltmp .= "($tmp)";
    } else if ( $keyType == 'all' ) {
        $sqltmp .= 'AND ';
        $tmp = '';
        $mywords = explode( ' ', $query );
        foreach( $mywords AS $mysearchitem ) {
            $mysearchitem = addslashes( $mysearchitem );
            $tmp .= "( comment LIKE '%$mysearchitem%' ) AND ";
        }
        $tmp = substr($tmp, 0, strlen($tmp) - 4);
        $sqltmp .= "($tmp)";

        $sqltmp .= 'OR ';
        $tmp = '';
        $mywords = explode( ' ', $query );
        foreach( $mywords AS $mysearchitem ) {
            $mysearchitem = addslashes( $mysearchitem );
            $tmp .= "( subject LIKE '%$mysearchitem%' ) AND ";
        }
        $tmp = substr($tmp, 0, strlen($tmp) - 4);
        $sqltmp .= "($tmp)";

    } else {
        $sqltmp = "WHERE (comment LIKE '%$query%' OR subject LIKE '%$query%')";
    }

    if ( $author != 0 ) {
        $sqltmp .= " AND uid='" . $author . "'";
    }

    // handle date ranges

    if (!empty($datestart) && !empty($dateend)) {
        $delim = substr($datestart, 4, 1);
        $sd = explode($delim,$datestart);
        $ed = explode($delim,$dateend);
        $startdate = mktime(0,0,0,$sd[1],$sd[2],$sd[0]);
        $enddate = mktime(0,0,0,$ed[1],$ed[2],$ed[0]) + 3600;
        $sqltmp .= " AND date BETWEEN '$startdate' AND '$enddate'";
    }

    $sql = "SELECT id,name,forum,date,subject,comment,views,uid FROM {$_TABLES['gf_topic']} "
           . $sqltmp . " ORDER BY date DESC";

    // limit what we are searching for...
    if ( $perpage < 1 ) {
        $perpage = 10;
    }
    $limitStart = ($page-1) * $perpage;
    $limitEnd   = $limitStart + $perpage;
    $sql .= " LIMIT " . $limitStart . "," . $limitEnd;

    // Perform search
    $result = DB_query($sql);

    // OK, now return coma delmited string of table header labels
    // Need to use language variables
    require_once($_CONF['path_system'] . 'classes/plugin.class.php');
    $plugin_results = new Plugin();
    $plugin_results->plugin_name = 'forum';
    if (!empty($author)) {
       $username = DB_getItem($_TABLES['users'],"username","uid = {$author}");
       $plugin_results->searchlabel = sprintf($LANG_GF00['searchresults'],$LANG_GF01['FOR'] . '&nbsp;' . $username);
    } else {
       $plugin_results->searchlabel = sprintf($LANG_GF00['searchresults'],"");
    }
    $plugin_results->addSearchHeading($LANG_GF01['FORUM']);
    $plugin_results->addSearchHeading($LANG_GF01['SUBJECT']);
    $plugin_results->addSearchHeading($LANG_GF01['DATE']);
    $plugin_results->addSearchHeading($LANG_GF01['VIEWS'] );
    $totalsearched = DB_numRows($result);
    $searchcount=0;
    // NOTE if any of your data items need to be links then add them here!
    // make sure data elements are in an array and in the same order as your
    // headings above!
    for ($i = 1; $i <= $totalsearched; $i++) {
        $A = DB_fetchArray($result);
        $grp_id = DB_getItem($_TABLES['gf_forums'],'grp_id',"forum_id='{$A['forum']}'");
        $groupname = DB_getItem($_TABLES['groups'],'grp_name',"grp_id='$grp_id'");
        if (SEC_inGroup($groupname) OR $grp_id == 2) {
            if ($CONF_FORUM['use_censor']) {
                $A['subject'] = COM_checkWords($A['subject']);
            }
            $searchcount++;
            $forumname = DB_getItem($_TABLES['gf_forums'],"forum_name","forum_id='{$A['forum']}'");
            $subject = wordwrap($A['subject'],40,"<br>");
            $date = strftime('%b %d %Y @ %I:%M %p', $A['date']);
            $url = $_CONF['site_url']. "/forum/viewtopic.php?forum={$A['forum']}&amp;showtopic={$A['id']}";
            $row = array($forumname, "<a href=\"$url\">" . COM_truncate($subject,$CONF_FORUM['show_subject_length'],'...') . "</a>",$date,$A['views']);
            $plugin_results->addSearchResult($row);
        }
    }
    $plugin_results->num_searchresults = $searchcount;
    $plugin_results->num_itemssearched = DB_count($_TABLES['gf_topic']);

    return $plugin_results;
}
 

Re: Plugin updates for the new search API

Posted on: 25/06/11 07:23am
By: Anonymous

The code isn't working here guys..

Regards,
Alen Lee

Re: Plugin updates for the new search API

Posted on: 25/06/11 08:28am
By: suprsidr

Which version of geeklog?
these changes exist in newer versions

Re: Plugin updates for the new search API

Posted on: 25/06/11 08:29am
By: Laugh

This works for me for the forum version 2.7.4 but I am pretty sure I got it here in the first place.

PHP Formatted Code

/**
* this searches for files matching the user query and returns an array of
* for the header and table rows back to search.php where it will be formated and
* printed
*
* @query            string          Keywords user is looking for
* @datestart        date/time       Start date to get results for
* @dateend          date/time       End date to get results for
* @topic            string          The topic they were searching in
* @type             string          Type of items they are searching
* @author           string          Get all results by this author
*
*/

function plugin_dopluginsearch_forum($query, $datestart, $dateend, $topic, $type, $author,$keyType,$page, $perpage)
{
    global $LANG_GF00, $LANG_GF01, $_TABLES, $_CONF, $CONF_FORUM;

    if (empty($type)) {
        $type = 'all';
    }
    // Bail if we aren't supppose to do our search
    if ($type <> 'all' AND $type <> 'forum') {
        $plugin_results = new Plugin();
        $plugin_results->plugin_name = $LANG_GF00['plugin_name'];
        $plugin_results->searchlabel = $LANG_GF00['searchlabel'];
        return $plugin_results;
    }

    // Build search SQL

    $sqltmp = " WHERE 1=1 ";

    if ( $keyType == 'phrase' ) {
        $sqltmp .= "AND (comment LIKE '%$query%' OR subject LIKE '%$query%')";
    } else  if ( $keyType == 'any' ) {
        $sqltmp .= 'AND ';
        $tmp = '';
        $mywords = explode( ' ', $query );
        foreach( $mywords AS $mysearchitem ) {
            $mysearchitem = addslashes( $mysearchitem );
            $tmp .= "( comment LIKE '%$mysearchitem%' OR subject LIKE '%$mysearchitem%' ) OR ";
        }
        $tmp = substr($tmp, 0, strlen($tmp) - 3);  // pulls off the last OR
        $sqltmp .= "($tmp)";
    } else if ( $keyType == 'all' ) {
        $sqltmp .= 'AND ';
        $tmp = '';
        $mywords = explode( ' ', $query );
        foreach( $mywords AS $mysearchitem ) {
            $mysearchitem = addslashes( $mysearchitem );
            $tmp .= "( comment LIKE '%$mysearchitem%' ) AND ";
        }
        $tmp = substr($tmp, 0, strlen($tmp) - 4);
        $sqltmp .= "($tmp)";

        $sqltmp .= 'OR ';
        $tmp = '';
        $mywords = explode( ' ', $query );
        foreach( $mywords AS $mysearchitem ) {
            $mysearchitem = addslashes( $mysearchitem );
            $tmp .= "( subject LIKE '%$mysearchitem%' ) AND ";
        }
        $tmp = substr($tmp, 0, strlen($tmp) - 4);
        $sqltmp .= "($tmp)";

    } else {
        $sqltmp = "WHERE (comment LIKE '%$query%' OR subject LIKE '%$query%')";
    }

    if ( $author != 0 ) {
        $sqltmp .= " AND uid='" . $author . "'";
    }

    // handle date ranges

    if (!empty($datestart) && !empty($dateend)) {
        $delim = substr($datestart, 4, 1);
        $sd = explode($delim,$datestart);
        $ed = explode($delim,$dateend);
        $startdate = mktime(0,0,0,$sd[1],$sd[2],$sd[0]);
        $enddate = mktime(0,0,0,$ed[1],$ed[2],$ed[0]) + 3600;
        $sqltmp .= " AND date BETWEEN '$startdate' AND '$enddate'";
    }

    $sql = "SELECT id,name,forum,date,subject,comment,views,uid FROM {$_TABLES['gf_topic']} "
           . $sqltmp . " ORDER BY date DESC";

    // limit what we are searching for...
    if ( $perpage < 1 ) {
        $perpage = 10;
    }
    $limitStart = ($page-1) * $perpage;
    $limitEnd   = $limitStart + $perpage;
    $sql .= " LIMIT " . $limitStart . "," . $limitEnd;

    // Perform search
    $result = DB_query($sql);

    // OK, now return coma delmited string of table header labels
    // Need to use language variables
    require_once($_CONF['path_system'] . 'classes/plugin.class.php');
    $plugin_results = new Plugin();
    $plugin_results->plugin_name = 'forum';
    if (!empty($author)) {
       $username = DB_getItem($_TABLES['users'],"username","uid = {$author}");
       $plugin_results->searchlabel = sprintf($LANG_GF00['searchresults'],$LANG_GF01['FOR'] . '&nbsp;' . $username);
    } else {
       $plugin_results->searchlabel = sprintf($LANG_GF00['searchresults'],"");
    }
    $plugin_results->addSearchHeading($LANG_GF01['FORUM']);
    $plugin_results->addSearchHeading($LANG_GF01['SUBJECT']);
    $plugin_results->addSearchHeading($LANG_GF01['DATE']);
    $plugin_results->addSearchHeading($LANG_GF01['VIEWS'] );
    $totalsearched = DB_numRows($result);
    $searchcount=0;
    // NOTE if any of your data items need to be links then add them here!
    // make sure data elements are in an array and in the same order as your
    // headings above!
    for ($i = 1; $i <= $totalsearched; $i++) {
        $A = DB_fetchArray($result);
        $grp_id = DB_getItem($_TABLES['gf_forums'],'grp_id',"forum_id='{$A['forum']}'");
        $groupname = DB_getItem($_TABLES['groups'],'grp_name',"grp_id='$grp_id'");
        if (SEC_inGroup($groupname) OR $grp_id == 2) {
            if ($CONF_FORUM['use_censor']) {
                $A['subject'] = COM_checkWords($A['subject']);
            }
            $searchcount++;
            $forumname = DB_getItem($_TABLES['gf_forums'],"forum_name","forum_id='{$A['forum']}'");
            $subject = wordwrap($A['subject'],40,"<br>");
            $date = strftime('%b %d %Y @ %I:%M %p', $A['date']);
            $url = $_CONF['site_url']. "/forum/viewtopic.php?forum={$A['forum']}&amp;showtopic={$A['id']}";
            $row = array($forumname, "<a href=\"$url\">" . COM_truncate($subject,$CONF_FORUM['show_subject_length'],'...') . "</a>",$date,$A['views']);
            $plugin_results->addSearchResult($row);
        }
    }
    $plugin_results->num_searchresults = $searchcount;
    $plugin_results->num_itemssearched = DB_count($_TABLES['gf_topic']);

    return $plugin_results;
}
 


Also. version 2.8.0 of the forum is out in beta at the moment which supports the Geeklog search out of the box

Geeklog - Forum
https://www.geeklog.net/forum/viewtopic.php?showtopic=87624