diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2009-11-06 01:46:36 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2009-11-06 01:46:36 +0000 |
commit | 5d96c9b12fe0ea953ef95af952e588a1898ef1fc (patch) | |
tree | 0d4555c86b3d5c744f46cc37e0b7b45a106017e6 /mod/search/start.php | |
parent | 06169d33aae4d27129c77baaee9ecb064683e576 (diff) | |
download | elgg-5d96c9b12fe0ea953ef95af952e588a1898ef1fc.tar.gz elgg-5d96c9b12fe0ea953ef95af952e588a1898ef1fc.tar.bz2 |
Updated search for FTS.
git-svn-id: http://code.elgg.org/elgg/trunk@3619 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/search/start.php')
-rw-r--r-- | mod/search/start.php | 160 |
1 files changed, 142 insertions, 18 deletions
diff --git a/mod/search/start.php b/mod/search/start.php index 24b038c7a..4bd342285 100644 --- a/mod/search/start.php +++ b/mod/search/start.php @@ -1,8 +1,8 @@ <?php - /** +/** * Elgg core search. - * + * * @package Elgg * @subpackage Core * @author Curverider Ltd <info@elgg.com>, The MITRE Corporation <http://www.mitre.org> @@ -14,21 +14,13 @@ * */ function search_init() { - global $CONFIG; - // page handler for search actions and results register_page_handler('search','search_page_handler'); - // hook into the search callback to use the metadata system (this is the part that will go away!) - register_plugin_hook('search:entities', 'all', 'search_original_hook'); - - // list of available search types should include our base parts - register_plugin_hook('searchtypes', 'all', 'search_base_search_types_hook'); - // add in CSS for search elements extend_view('css', 'search/css'); } - + /** * Page handler for search * @@ -36,9 +28,9 @@ function search_init() { */ function search_page_handler($page) { global $CONFIG; - + if(!get_input('tag')) { - set_input('tag', $page[0]); + set_input('tag', $page[0]); } include_once($CONFIG->path . "mod/search/index.php"); @@ -47,13 +39,17 @@ function search_page_handler($page) { /** * Core search hook. * Returns an object with two parts: - * ->entities: an array of instantiated entities that have been decorated with + * ->entities: an array of instantiated entities that have been decorated with * volatile "search" data indicating what they matched. These are * the entities to be displayed to the user on this page. * ->total: total number of entities overall. This function can update this * limit to ask for more pages in the pagination. */ function search_original_hook($hook, $type, $returnvalue, $params) { + global $CONFIG; + + var_dump($CONFIG->hooks); + $tag = $params['tag']; $offset = $params['offset']; // starting page $limit = $params['limit']; // number per page @@ -63,9 +59,21 @@ function search_original_hook($hook, $type, $returnvalue, $params) { $owner_guid = $params['owner_guid']; $tagtype = $params['tagtype']; - $count = get_entities_from_metadata($tagtype, elgg_strtolower($tag), $object_type, $subtype, $owner_guid, $limit, $offset, "", 0, TRUE, FALSE); + $count = get_entities_from_metadata($tagtype, elgg_strtolower($tag), $object_type, $subtype, $owner_guid, $limit, $offset, "", 0, TRUE, FALSE); $ents = get_entities_from_metadata($tagtype, elgg_strtolower($tag), $object_type, $subtype, $owner_guid, $limit, $offset, "", 0, FALSE, FALSE); +// $options = array( +// 'metadata_name_value_pair' => array('name' => $params['tagtype'], 'value' => $params['tag'], 'case_sensitive' => false), +// 'offset' => $params['offset'], +// 'limit' => $params['limit'], +// 'type' => $params['object_type'], +// 'subtype' => $params['subtype'], +// 'owner_guid' => $params['owner_guid'] +// ); +// +// $count = elgg_get_entities_from_metadata(array_merge($options, array('count' => TRUE))); +// $entities = elgg_get_entities_from_metadata($options); + /* * Foreach entity * get the metadata keys @@ -99,6 +107,26 @@ function search_original_hook($hook, $type, $returnvalue, $params) { } /** + * Provides default search for registered entity subtypes. + * Entity types should be dealt with in the entity classes. (Objects are an exception). + * + * @param unknown_type $hook + * @param unknown_type $type + * @param unknown_type $returnvalue + * @param unknown_type $params + * @return unknown_type + */ +function search_registered_entities($hook, $type, $returnvalue, $params) { + $entity_types = get_registered_entity_types(); + foreach ($entity_types as $type => $subtypes) { + if (is_array($subtypes) && count($subtypes)) { + + } + + } +} + +/** * return our base search types (right now, we have none) */ function search_base_search_types_hook($hook, $type, $returnvalue, $params) { @@ -109,8 +137,104 @@ function search_base_search_types_hook($hook, $type, $returnvalue, $params) { return $returnvalue; } -/** Register init system event **/ -register_elgg_event_handler('init','system','search_init'); +/** + * Returns a matching string with $context amount of context, optionally + * surrounded by $before and $after. + * + * If no match is found, restricts string to $context*2 starting from strpos 0. + * + * @param str $haystack + * @param str $needle + * @param str $before + * @param str $after + * @param str $context + * @return str + */ +function search_get_relevant_substring($haystack, $needle, $before = '', $after = '', $context = 75) { + $haystack = strip_tags($haystack); + $needle = strip_tags($needle); + + $pos = strpos(strtolower($haystack), strtolower($needle)); + + if ($pos === FALSE) { + $str = substr($haystack, 0, $context*2); + if (strlen($haystack) > $context*2) { + $str .= '...'; + } + + return $str; + } + + $start_pos = $pos - $context; + + if ($start_pos < 0) { + $start_pos = 0; + } + + // get string from -context to +context + $matched = substr($haystack, $start_pos, $context*2); + + // add elipses to front. + if ($start_pos > 0) { + $matched = "...$matched"; + } + + // add elipses to end. + if ($start_pos + $context < strlen($haystack)) { + $matched = "$matched..."; + } + + // surround if needed + if ($before || $after) { + $matched = str_ireplace($needle, $before . $needle . $after, $matched); + } + + return $matched; +} + + + +function search_get_listing_html($entities, $count, $params) { + if (!is_array($entities) || !$count) { + return FALSE; + } + + $view_order = array(); + + // check if there's a special search view for this type:subtype + if (isset($params['type']) && $params['type'] && isset($params['subtype']) && $params['subtype']) { + $view_order[] = "search/{$params['type']}/{$params['subtype']}/listing"; + } + + // also check for the default type + if (isset($params['type']) && $params['type']) { + $view_order[] = "search/{$params['type']}/listing"; + } + + // check search types + if (isset($params['search_type']) && $params['search_type']) { + $view_order[] = "search/{$params['search_type']}/listing"; + } + + // finally default to a search listing default + $view_order[] = "search/listing"; + + $vars = array( + 'entities' => $entities, + 'count' => $count, + 'params' => $params + ); + + foreach ($view_order as $view) { + if (elgg_view_exists($view)) { + return elgg_view($view, $vars); + } + } + + return FALSE; +} + +/** Register init system event **/ -?> +register_elgg_event_handler('init','system','search_init');
\ No newline at end of file |