glFusion Wiki

Site Tools


glfusion:development:api:search:plugin_dopluginsearch_plugin_name

plugin_dopluginsearch_{plugin_name}

(glFusion v1.1.0)

plugin_dopluginsearch_{plugin_name} – returns a SearchCriteria() object

Description

array plugin_dopluginsearch_{plugin_name}($query,$datestart,$dateend,$topic,$author,$keyType)

returns the search SQL query back to glFusion.

Parameters

query

A string containing the search term - it is the responsibility of the plugin
to filter the query string prior to using in an SQL query.

datestart

Starting date to begin search.

dateend

Ending date to end search.  If this parameter is empty, no
date restrictions will be used on the query.

topic

Topic the item is assigned to.

author

The user id of the author.  If this parameter is empty, no
author restrictions will be used on the query.

keyType

Search key type:
  * all
  * phrase
  * any

Return Value

Returns a SearchCriteria() object.

The search API requires the following information to be returned by the plugin_dopluginsearch_{plugin_name}() function:

  $search = new SearchCriteria('myplugin', 'My Plugin');
  $search->setSQL($sql);
  $search->setFTSQL($ftsql);
  $search->setRank(4);

Example

function plugin_dopluginsearch_links($query, $datestart, $dateend, $type, $author, $keyType ) {
    global $_TABLES, $LANG_LINKS, $inputHandler;

    // Make sure the query is SQL safe
    $query = trim($inputHandler->prepareForDB($query));

    $sql = "SELECT lid AS id, 
            title, description, 
            UNIX_TIMESTAMP(date) AS date, 
            owner_id AS uid, 
            hits, 
            CONCAT('/links/portal.php?what=link&item=',lid) AS url ";

    $sql .= "FROM {$_TABLES['links']} WHERE date <> 1 ";
    $sql .= COM_getPermSQL('AND') . ' ';

    /* Check to see if there are date range restrictions */

    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 '$startdate' AND '$enddate') ";
        }
    }

    /* Check to see if there is an author restriction */

    if (!empty ($author))
        $sql .= "AND (owner_id = '$author') ";

    /* build the SearchCriteria() Object */

    $search = new SearchCriteria('links', $LANG_LINKS[14]);
    $columns = array('description','title');
    list($sql,$ftsql) = $search->buildSearchSQL($keyType, $query, $columns, $sql);
    $search->setSQL($sql);
    $search->setFTSQL($ftsql);
    $search->setRank(3);

    return $search;
}

Notes

All SQL queries returned should be without the LIMIT and ORDER BY clauses. The SQL query must have the following column names and look like:

  SELECT id, title, description, date, user, hits, url FROM ... WHERE ...

If a column does not exist in the table then another value should be substituted, for example: '0' AS hits, …

The url is where to take the user when they have clicked a result. It should start with a single slash if the target is within the current domain. Otherwise the result with be printed, as is, in the href attribute of the link. For example this url belongs to the glFusion site

  CONCAT('/staticpages/index.php?page=', sp.sp_id) AS url

However the Links plugin needs to direct users to external sites when clicked, so providing the url from the database will suffice.

Full-Text SQL Query (optional)

  • An query for MySQL DBMS using the Full-Text search method.

This search method will take advantage of Full-Text indexes which will reduce search times. This should only be returned if the columns being searched have been properly indexed. The Full-Text SQL Query will only be executed if Full-Text searches have been enabled by the admin during the installation or upgrading process, otherwise the core will always fall back to the Standard SQL Query.

See Also

glfusion/development/api/search/plugin_dopluginsearch_plugin_name.txt · Last modified: 2017/04/12 21:15 (external edit)

Page Tools