Welcome to Geeklog, Anonymous Friday, November 29 2024 @ 05:02 pm EST

Geeklog Forums

Plugin updates for the new search API

Page navigation


Status: offline

suprsidr

Forum User
Full Member
Registered: 12/29/04
Posts: 555
Location:Champaign, Illinois
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
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 Quote

Status: offline

sbarakat

Forum User
Junior
Registered: 04/22/08
Posts: 27
Location:Norwich, United Kingdom
Quote by: suprsidr


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

Text 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?
 Quote

Status: offline

Laugh

Site Admin
Admin
Registered: 09/27/05
Posts: 1470
Location:Canada
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
One of the Geeklog Core Developers.
 Quote

Status: offline

suprsidr

Forum User
Full Member
Registered: 12/29/04
Posts: 555
Location:Champaign, Illinois
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
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Hello,

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

Here is my code :
Text 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
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

suprsidr

Forum User
Full Member
Registered: 12/29/04
Posts: 555
Location:Champaign, Illinois
Nothing jumps out at me, that's the beauty of COM_errorlog - the ease of adding step by step logging and troubleshooting.

-s
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 Quote

Status: offline

sbarakat

Forum User
Junior
Registered: 04/22/08
Posts: 27
Location:Norwich, United Kingdom
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)
 Quote

Status: offline

suprsidr

Forum User
Full Member
Registered: 12/29/04
Posts: 555
Location:Champaign, Illinois

(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
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
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
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

sbarakat

Forum User
Junior
Registered: 04/22/08
Posts: 27
Location:Norwich, United Kingdom
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
Text 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
Text 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.
 Quote

Status: offline

sbarakat

Forum User
Junior
Registered: 04/22/08
Posts: 27
Location:Norwich, United Kingdom
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.
Text Formatted Code
    // Bail if we aren't supppose to do our search
    if ($type <> 'all' AND $type <> 'dokuwiki') {
        return '';
    }
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
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:

Text 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
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

sbarakat

Forum User
Junior
Registered: 04/22/08
Posts: 27
Location:Norwich, United Kingdom
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
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Ok, I will remove the use of $type.

Thanks.

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

sbarakat

Forum User
Junior
Registered: 04/22/08
Posts: 27
Location:Norwich, United Kingdom
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
Text 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.
Text 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)
Text 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;
}
 Quote

Status: offline

Jokke_K

Forum User
Newbie
Registered: 02/24/04
Posts: 9
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?

Text 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;
}
 
 Quote

Alen Lee

Anonymous
sleepy
The code isn't working here guys..

Regards,
Alen Lee
 Quote

Status: offline

suprsidr

Forum User
Full Member
Registered: 12/29/04
Posts: 555
Location:Champaign, Illinois
Which version of geeklog?
these changes exist in newer versions
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 Quote

Status: offline

Laugh

Site Admin
Admin
Registered: 09/27/05
Posts: 1470
Location:Canada
This works for me for the forum version 2.7.4 but I am pretty sure I got it here in the first place.

Text 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
One of the Geeklog Core Developers.
 Quote

Page navigation

All times are EST. The time is now 05:02 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content