summaryrefslogtreecommitdiff
path: root/modules/search/search.api.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules/search/search.api.php')
-rw-r--r--modules/search/search.api.php43
1 files changed, 39 insertions, 4 deletions
diff --git a/modules/search/search.api.php b/modules/search/search.api.php
index a33bfaf83..da3b7b839 100644
--- a/modules/search/search.api.php
+++ b/modules/search/search.api.php
@@ -30,9 +30,16 @@
* node_form_search_form_alter() for an example.
*
* @return
- * Array with the optional keys 'title' for the tab title and 'path' for
- * the path component after 'search/'. Both will default to the module
- * name.
+ * Array with optional keys:
+ * - 'title': Title for the tab on the search page for this module. Defaults
+ * to the module name if not given.
+ * - 'path': Path component after 'search/' for searching with this module.
+ * Defaults to the module name if not given.
+ * - 'conditions_callback': Name of a callback function that is invoked by
+ * search_view() to get an array of additional search conditions to pass to
+ * search_data(). For example, a search module may get additional keywords,
+ * filters, or modifiers for the search from the query string. Sample
+ * callback function: sample_search_conditions_callback().
*
* @ingroup search
*/
@@ -40,10 +47,36 @@ function hook_search_info() {
return array(
'title' => 'Content',
'path' => 'node',
+ 'conditions_callback' => 'sample_search_conditions_callback',
);
}
/**
+ * An example conditions callback function for search.
+ *
+ * This example pulls additional search keywords out of the $_REQUEST variable,
+ * (i.e. from the query string of the request). The conditions may also be
+ * generated internally - for example based on a module's settings.
+ *
+ * @see hook_search_info()
+ * @ingroup search
+ */
+function sample_search_conditions_callback($keys) {
+ $conditions = array();
+
+ if (!empty($_REQUEST['keys'])) {
+ $conditions['keys'] = $_REQUEST['keys'];
+ }
+ if (!empty($_REQUEST['sample_search_keys'])) {
+ $conditions['sample_search_keys'] = $_REQUEST['sample_search_keys'];
+ }
+ if ($force_keys = variable_get('sample_search_force_keywords', '')) {
+ $conditions['sample_search_force_keywords'] = $force_keys;
+ }
+ return $conditions;
+}
+
+/**
* Define access to a custom search routine.
*
* This hook allows a module to define permissions for a search tab.
@@ -139,6 +172,8 @@ function hook_search_admin() {
*
* @param $keys
* The search keywords as entered by the user.
+ * @param $conditions
+ * An optional array of additional conditions, such as filters.
*
* @return
* An array of search results. To use the default search result
@@ -154,7 +189,7 @@ function hook_search_admin() {
*
* @ingroup search
*/
-function hook_search_execute($keys = NULL) {
+function hook_search_execute($keys = NULL, $conditions = NULL) {
// Build matching conditions
$query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault');
$query->join('node', 'n', 'n.nid = i.sid');