Dru Documentation

Go to front page

developer/hooks/core.php, строка 1493 Версии 5 – 6 hook_search($op = 'search', $keys = null) » Перевод» Оригинал Определяет пользовательскую функцию поиска. Этот хук позволяет модулю выполнять поиск по контенту, который он определяет (свои типы нод, пользователи или комментарии, например), когда поиск на сайте выполняется. Note that you can use form API to extend the search. You will need to use hook_form_alter() to add any additional required form elements. You can process their values on submission using a custom validation function. You will need to merge any custom search values into the search keys using a key:value syntax. This allows all search queries to have a clean and permanent URL. See node_form_alter() for an example. The example given here is for node.module, which uses the indexed search capabilities. To do this, node module also implements hook_update_index() which is used to create and maintain the index. We call do_search() with the keys, the module name and extra SQL fragments to use when searching. See hook_update_index() for more information. Параметры $op A string defining which operation to perform: * 'name': the hook should return a translated name defining the type of items that are searched for with this module ('content', 'users', ...) * 'reset': the search index is going to be rebuilt. Modules which use hook_update_index() should update their indexing bookkeeping so that it starts from scratch the next time hook_update_index() is called. * 'search': the hook should perform a search using the keywords in $keys * 'status': if the module implements hook_update_index(), it should return an array containing the following keys: o remaining: the amount of items that still need to be indexed o total: the total amount of items (both indexed and unindexed) $keys The search keywords as entered by the user. Возвращаемое значение An array of search results. Each item in the result set array may contain whatever information the module wishes to display as a search result. To use the default search result display, each item should be an array which can have the following keys: * link: the URL of the found item * type: the type of item * title: the name of the item * user: the author of the item * date: a timestamp when the item was last modified * extra: an array of optional extra information items * snippet: an excerpt or preview to show with the result (can be generated with search_excerpt()) Only 'link' and 'title' are required, but it is advised to fill in as many of these fields as possible. Define a custom search routine. This hook allows a module to perform searches on content it defines (custom node types, users, or comments, for example) when a site search is performed. Note that you can use form API to extend the search. You will need to use hook_form_alter() to add any additional required form elements. You can process their values on submission using a custom validation function. You will need to merge any custom search values into the search keys using a key:value syntax. This allows all search queries to have a clean and permanent URL. See node_form_alter() for an example. The example given here is for node.module, which uses the indexed search capabilities. To do this, node module also implements hook_update_index() which is used to create and maintain the index. We call do_search() with the keys, the module name and extra SQL fragments to use when searching. See hook_update_index() for more information. Parameters $op A string defining which operation to perform: * 'name': the hook should return a translated name defining the type of items that are searched for with this module ('content', 'users', ...) * 'reset': the search index is going to be rebuilt. Modules which use hook_update_index() should update their indexing bookkeeping so that it starts from scratch the next time hook_update_index() is called. * 'search': the hook should perform a search using the keywords in $keys * 'status': if the module implements hook_update_index(), it should return an array containing the following keys: o remaining: the amount of items that still need to be indexed o total: the total amount of items (both indexed and unindexed) $keys The search keywords as entered by the user. Return value An array of search results. Each item in the result set array may contain whatever information the module wishes to display as a search result. To use the default search result display, each item should be an array which can have the following keys: * link: the URL of the found item * type: the type of item * title: the name of the item * user: the author of the item * date: a timestamp when the item was last modified * extra: an array of optional extra information items * snippet: an excerpt or preview to show with the result (can be generated with search_excerpt()) Only 'link' and 'title' are required, but it is advised to fill in as many of these fields as possible. Связанные темы Хуки Позволяет модулям взаимодействовать с ядром Drupal. Поисковый интерфейс Управляет механизмом глобального поиска по сайту. ? 3 функции вызывают hook_search()