Search

The module displays a form for site search and search results.

Indexing

Indexing

The administrative part of the module is required for manual work with the search index. You can re-index the content of all or individual modules, as well as delete the entire index or the index of the individual modules. Handmade index is required only in the following cases:

  • content entered from outside: imported from a CSV-file, manually added to the database;
  • module "Search" was set to a working site;
  • because the content was not indexed failure. It is necessary that the content of a unit not involved in the search results. In this case, except for the removal of the index of the module must also change modules/модуль/модуль.search.php:

    class Модуль_search_config
    {
        public
    $config = array();
    }

When adding / editing content from the administrative part of the content will be reindexed automatically without manual intervention. The need to index the content of a particular module and the indexing settings are described in the file modules/module_name/module_name.search.php. File format:

Example:

class Модуль_search_config
{
    public
$config = array(
        
'table' => array(
            
'fields' => array('field_name_for_search', ...),
            
'rating' => module_rating_in_search_results
        
),
        
'second_table' => array(
            ...
        ),
        ...
    );
}

You can set the field "param", then there will be indexed by all the values ​​of additional features for the module elements. For example, additional information items in the store.

In the search results on the site search results are made the same way as in the list of elements of the module. For this function elements() the data is processed from the model module modules/module_name/module_name.model.php and template output modules/module_name/views/module_name.view.list.php.

You can specify your search for data processing. To do this, you need to define function search() in the file modules/module_name/views/module_name.view.list.php.

Example:

Since the data processing of the goods is found by the function search() in the file modules/shop/shop.model.php.

And the news about the found data process is by the function elements() in the file modules/news/news.model.php, since the function in this file is not described.

The template can be also used other than the default template. To do this, create file modules/module_name/views/module_name.view.list_search.php.

Example:

Products found drawn up in the search results template modules/shop/views/shop.view.list_search.php.

A Point of news also documented how in the news list template modules/news/views/news.view.list.php.

The above features only apply to the elements of modules (news, products, articles and so forth.). Categories and manufacturers in the module, as well as the pages of the site are displayed included as a standard template modules/search/views/search.view.show.php.

Connection

Подключаемая часть – файл modules/search/search.inc.php. В нем описан класс Search_inc. В модуле к объекту класса можно обратиться через переменную $this->diafan->_search. Экземпляр класса создается при первом вызове переменной.

Методы

void index_all () – Индексирует весь сайт.

Example:

// index all pages on the site, which are defined for indexing in the file of settings
$this->diafan->_search->index_all();

void index_module (string $module_name) – Индексирует модуль.

  • string $module_name: название модуля

Example:

// index module "Online shop"
$this->diafan->_search->index_module('shop');

void index_site_module (array $site, [boolean $out = true], [integer $count_sites = 0]) – Индексирует страницы модуля, прикрепленного к странице сайта.

  • array $site: данные о странице сайта
  • boolean $out: функция используется как внешняя
  • integer $count_sites: количество страниц, к которым прикреплен модуль

Example:

$site = array(
    
"id" => 13,
    
"module_name" => "shop",
);
// index site page with attached module
$this->diafan->_search->index_site_module($site);

void index_elements (array $rows, strign $table_name) – Индексирует группу элементов.

  • array $rows: массив данных об индексируемых элементах
  • strign $table_name: таблица элементов

Example:

$rows = array(
    array(
        
"id" => 1,
            
"search_no_show" => 0,
            
"act1" = 1,
            
"act2" => 0,
            
"access" => 0,
            
"name" => "Electric mower",
            
"anons" => "A good lawn mower at an affordable price.",
            
"text" => "The service life is usually 3-4 years, height adjustable mowing, long cord.",
            
"article" => "K1200"
    
),
    array(
        
"id" => 2,
            
"search_no_show" => 0,
            
"act1" = 1,
            
"act2" => 1,
            
"access" => 0,
            
"name" => "Lawn mowers",
            
"name2" => "Газонокосилка бензиновая",
            
"anons" => "Best lawn mower, but more expensive.",
            
"anons2" => "Лучшая газонокосилка, но дороже.",
            
"text" => "Life is normally 5-6 years, you need to fill petrol, height adjustable mowing, long cord.",
            
"text2" => "Срок службы обычно 5-6 лет, нужно заправлять бензином, регулируемая высота покоса, длинный шнур.",
            
"article" => "K1200"
    
),
);
// index more products
$this->diafan->_search->index_elements($rows, "shop");

void index_element (array $row, strign $table_name) – Индексирует один элемент.

  • array $row: данные об индексируемом элементе
  • strign $table_name: таблица элемента

Example:

$row = array(
    
"id" => 1,
    
"search_no_show" => 0,
    
"act1" = 1,
    
"act2" => 0,
    
"access" => 0,
    
"name" => "Electric mower",
    
"anons" => "A good lawn mower at an affordable price.",
    
"text" => "The service life is usually 3-4 years, height adjustable mowing, long cord.",
    
"article" => "K1200"
);
// index product
$this->diafan->_search->index_element($row, "shop");

void delete (integer|array $element_ids, string $table_name) – Удаляет один или несколько элементов.

  • integer|array $element_ids: номер одного или нескольких элементов
  • string $table_name: table

Example:

// delete products brand from index
$this->diafan->_search->delete(2, "shop", "brand");

void delete_module (string $module_name) – Удаляет весь индекс модуля.

  • string $module_name: название модуля

Example:

// delete news and news categories from the index
$this->diafan->_search->delete_module("news");

void delete_sites (array $site_ids) – Удаляет индекс модулей, прикрепленных к страницам сайта.

  • array $site_ids: идентификаторы страниц сайта

Example:

// delete index for module attached to site page ID=3,4,6
$this->diafan->_search->delete_sites(array(3, 4, 6));

array|boolean false check_module_config (string $module_name, [string $table_name = '']) – Проверяет есть ли настройки поиска для модуля и таблицы модуля.

  • string $module_name: модуль
  • string $table_name: table

Example:

$config = $this->diafan->_search->check_module_config("shop", "shop_brand");
if(
$config)
{
    
// index products brand
}

Search history

Search history

Searches have the following characteristics:

List of recent searches. The number of queries in search history is defined in the module settings.

Settings

Settings

Template tags

Для работы с модулем «Search» служат следующие шаблонные теги:

show_search – выводит форму поиска по сайту.

Атрибуты:

button – значение кнопки «Найти». Для неосновной языковой версии значение можно перевести в административной части в меню «Языки сайта» – «Перевод интерфейса»;

ajax – подгружать результаты поиска без перезагрузки страницы.: true – результаты поиска подгружаются, по умолчанию будет перезагружена вся страница.;

defer – deferred load tag template tag: event – load content only at the request of the user when you click "Upload", emergence – load content only when the client window appears in the browser window, async – asynchronous (simultaneous) content loading together with the content of template tags with the same marker, sync – synchronous (sequential) load of content in conjunction with the content of template tags with the same marker, by default, downloading content only at the request of the user;

defer_title – text string displayed at the point where the loadable content appears with the help of delayed loading of the template tag;

template – tag template (file modules/search/views/search.view.show_search_template.php; default - file modules/search/views/search.view.show_search.php).

Example:

<insert name="show_search" module="search" button="найти">

выведет форму поиска по сайту. "button" - необязательный атрибут названия кнопки поиска

В шаблоне тега можно получить значение любого атрибута через переменную $result["attributes"]["название атрибута"].

Database

{search_history} – Search history

{search_index} – Links of words and indexed items for searching

{search_keywords} – Indexed to search for words

{search_results} – Indexed items for search

Files

  1. modules/search/admin/search.admin.php – Работа с поисковым индексом;

  2. modules/search/admin/search.admin.config.php – Module settings;

  3. modules/search/admin/search.admin.history.php – Search history;

  4. modules/search/admin/search.admin.inc.php – Connecting the module to the administrative part of other modules;

  5. modules/search/js/search.show_search_top.js – JS-сценарий формы поиска;

  6. modules/search/search.php – Controller;

  7. modules/search/search.action.php – Processes the received data from the form;

  8. modules/search/search.history.php – Экспорт истории поиска;

  9. modules/search/search.inc.php – Подключение модуля;

  10. modules/search/search.install.php – Module installation;

  11. modules/search/search.model.php – Model;

  12. modules/search/views/search.view.rows.php – Шаблон результатов поиска по сайту;

  13. modules/search/views/search.view.show.php – Шаблон результатов поиска по сайту;

  14. modules/search/views/search.view.show_search.php – Шаблон формы поиска по сайту;

  15. modules/search/views/search.view.show_search_404.php – Шаблон формы поиска по сайту, template=404;

  16. modules/search/views/search.view.show_search_top.php – Template of site search form, template=top.