/**
* Returns array of items which contain contact information
*
* @param string $type The search type; ['gal'|'mailbox']
* @param array $query The search query. An array containing:
* - query: (array) The search query. Contains at least:
* 'query' and 'range'. The rest depends on the type of
* search being performed.
* DEFAULT: none, REQUIRED
* - range: (string) A range limiter.
* DEFAULT: none (No range used).
* - rebuildresults: (boolean) If true, invalidate any cached search.
* DEFAULT: Use cached search results if available.
* - deeptraversal: (boolean) If true, traverse sub folders.
* @todo NOT IMPLEMENTED YET.
*
* @return array An array containing:
* - rows: An array of search results, limited by $query['range'].
* - status: The search store status code.
* - total: The total number of matches (not limited by $query['range']
*/
public function getSearchResults($type, array $query)
{
switch (Horde_String::lower($type)) {
case 'gal':
return $this->_searchGal($query);
case 'mailbox':
if (!empty($this->_cache)) {
$clear_cache = !empty($query['rebuildresults']);
unset($query['rebuildresults']);
$cache_key = $GLOBALS['registry']->getAuth() . ':HCASD:' . hash('md5', serialize($query));
if ($clear_cache) {
$this->_cache->expire($cache_key);
}
}
if (!empty($this->_cache) && $this->_cache->exists($cache_key, 0)) {
$results = json_decode($this->_cache->get($cache_key, 0), true);
} else {
try {
$results = $this->_searchMailbox($query);
if (!empty($this->_cache)) {
$this->_cache->set($cache_key, json_encode($results));
}
} catch (Horde_ActiveSync_Exception $e) {
$this->_logger->err($e->getMessage());
$results = array();
}
}
$count = count($results);
if (!empty($query['range'])) {
$range = explode('-', $query['range']);
$results = array_slice($results, $range[0], $range[1] - $range[0] + 1);
}
return array('rows' => $results, 'total' => $count, 'status' => Horde_ActiveSync_Request_Search::STORE_STATUS_SUCCESS);
case 'documentlibrary':
foreach ($query['query'][0] as $q) {
if (!empty($q['DocumentLibrary:LinkId'])) {
$results = $this->_connector->files_browse($q['DocumentLibrary:LinkId']);
}
}
return array('rows' => $results, 'total' => count($results), 'status' => Horde_ActiveSync_Request_Search::STORE_STATUS_SUCCESS);
}
}