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

Geeklog Forums

Plugin updates for the new search API

Page navigation


Status: offline

sbarakat

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

 Quote

Guest

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.
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
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
 Quote

Status: offline

sbarakat

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

Guset

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:
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
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
 Quote

Guest

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

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
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
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Minor improvement for the forum search: You don't need the 'forum=' parameter, which makes for shorter URLs:

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


bye, Dirk
 Quote

Status: offline

sbarakat

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

Status: offline

suprsidr

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

Status: offline

jmucchiello

Forum User
Full Member
Registered: 08/29/05
Posts: 985
I didn't say that specifically but the big SQL query search api was a concern of mine all those months ago.
 Quote

Status: offline

suprsidr

Forum User
Full Member
Registered: 12/29/04
Posts: 555
Location:Champaign, Illinois
So how are plugins with external apps or dependencies supposed to contribute to search results?

I guess they are not.

-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

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
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
I've just submitted a comment to file 980, 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?
 Quote

Status: offline

suprsidr

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

Status: offline

suprsidr

Forum User
Full Member
Registered: 12/29/04
Posts: 555
Location:Champaign, Illinois
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:
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.

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

Status: offline

suprsidr

Forum User
Full Member
Registered: 12/29/04
Posts: 555
Location:Champaign, Illinois
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
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
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
One of the Geeklog Core Developers.
 Quote

Page navigation

All times are EST. The time is now 02:32 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