File/program/modules/htmlpage/htmlpage_search.php

Description

/program/modules/htmlpage/htmlpage_search.php - interface to the search-part of this module

This file defines the interface with this module for searching content. The interface consists of a (temporary) table and this function:

    bool htmlpage_search(&$hits,&$results,$qwords, $limit, $offset)

The function is called whenever module content is to be searched. At that point the helper table, which is called 'search_nodes', exists and is populated.

Functions
htmlpage_search (line 135)

search all htmlpages linked to selected nodes for keywords in $qwords

TASKS

This function needs to perform these tasks.

  • If ($results < 0) on entry, the function must calculate and set $results to the number of results in this module's data (could be 0).
  • If ($limit > 0) on entry, the function must return at most $limit search hits in the $hits array.
  • If ($results > 0) on entry the function is allowed to use that number as a hint of the total # of hits in this module's data.
  • If ($results == 0) on entry the function can decide to return immediately because (according to the caller) there are no hits anyway.

KEYWORDS TO SEARCH FOR

On entry the array $qwords contains the sanitised user-supplied keywords, as follows:

    $qword[$i] = array($original, $utf8lower, $quoted); $original: exactly what the user entered into the search box. $utf8lower: lowercase version of $original $quoted: escaped/quoted $original ready for LIKE '%$quoted%'

HELPER TABLE

On entry the table 'search_nodes' [*] exists and is populated with node_id's that are qualified to be searched. The structure of this table is as follows:

    CREATE TABLE $search_nodes (node_id int(11) NOT NULL DEFAULT '0' PRIMARY KEY (node_id));

[*] Note that as with every other table the name of the table is prefixed with the prefix found in $DB->prefix or $CFG->prefix.

The search results of this module can be limited to the qualifying nodes by using an inner join, e.g.

    SELECT m.data FROM $search_nodes s INNER JOIN $module m USING (node_id) WHERE $where;

RETURNING SEARCH RESULTS

If there are hits, these are collected in $hits as follows:

    $hits[] = array('title' => $title,                 'context' => array($snippet1, $snippet2, ...),                 'url' => $url);

Eventually this yields HTML-code like this:

    <div>   <div><a href="$url">$title</a></div>   <div>$snippet1 $snippet2 ...</div>   <div><a href="$url">$url</a></div> </div>

Tip: function search_context() can be used to extract context snippets from hits.

If search is not relevant to the module, the NOP can be this:

    $results = 0; return TRUE;

See also search_nodes().

bool|array htmlpage_search (array &$hits, int &$results, array $qwords, int $limit, [int $offset = 0])
  • array &$hits: receives search results (at most $limit)
  • int &$results: receives number of hits (negative value on entry means (re-)calculate total)
  • array $qwords: holds 1 or more keywords to search for (original, utf8lower, quoted)
  • int $limit: maximum number of hits to return (could be 0)
  • int $offset: starting point within this module for returning results

Documentation generated on Tue, 28 Jun 2016 19:09:51 +0200 by phpDocumentor 1.4.0