search_service.module in Services 5
Same filename and directory in other branches
The module which exposes services related to searching
File
services/search_service/search_service.moduleView source
<?php
/**
* @file
* The module which exposes services related to searching
*/
/**
* Implementation of hook_help().
*/
function search_service_help($section) {
switch ($section) {
case 'admin/help#services_search':
return t('<p>Provides search methods to services applications. Requires services.module.</p>');
case 'admin/modules#description':
return t('Provides search methods to services applications. Requires services.module.');
}
}
/**
* Implementation of hook_service().
*/
function search_service_service() {
return array(
array(
'#method' => 'search.searchNodes',
'#callback' => 'search_service_search_nodes',
'#key' => FALSE,
'#access arguments' => array(
'search content',
),
'#args' => array(
array(
'#name' => 'search_keys',
'#type' => 'string',
'#description' => t('Search keys.'),
),
array(
'#name' => 'simple',
'#type' => 'string',
'#optional' => TRUE,
'#description' => t('If set, returns only the main search fields (link, type, title, user, date, snippet) and no additional data.'),
),
),
'#return' => 'array',
'#help' => t('Searches nodes according to keys via hook_search.'),
),
array(
'#method' => 'search.searchUsers',
'#callback' => 'search_service_search_users',
'#key' => FALSE,
'#access arguments' => array(
'search content',
),
'#args' => array(
array(
'#name' => 'search_keys',
'#type' => 'string',
'#description' => t('Search keys.'),
),
),
'#return' => 'array',
'#help' => t('Searches users according to keys via hook_search.'),
),
);
}
/*
* Callback for search.searchNodes service.
*/
function search_service_search_nodes($keys, $simple = FALSE) {
// define standard keys for simple set
$stdkeys = array(
'link',
'type',
'title',
'user',
'date',
'snippet',
);
// invoke the search hook to generate results
$results = module_invoke('node', 'search', 'search', $keys);
if ($results && is_array($results) && count($results)) {
// if simple results requested, remove extra data
if ($simple) {
$num = count($results);
for ($i = 0; $i < $num; $i++) {
$keys = array_keys($results[$i]);
foreach ($keys as $key) {
if (!in_array($key, $stdkeys)) {
unset($results[$i][$key]);
}
}
}
}
return $results;
}
return services_error(t('Search returned no results.'));
}
/*
* Callback for search.searchNodes service.
*/
function search_service_search_users($keys) {
// invoke the search hook to generate results
$results = module_invoke('user', 'search', 'search', $keys);
if ($results && is_array($results) && count($results)) {
return $results;
}
return services_error(t('Search returned no results.'));
}
Functions
Name | Description |
---|---|
search_service_help | Implementation of hook_help(). |
search_service_search_nodes | |
search_service_search_users | |
search_service_service | Implementation of hook_service(). |