We use cookies
We use cookies to optimize our website. By continuing to browse the site, you agree to our use of cookies.
New design
Control panel
  • Русский
  • Українська
  • English
  • UAH
  • USD
  • RUB
  • EUR
  • 0-800-307-307 Hotline
  • +38 (044) 392-74-33 Kiev
  • +38 (057) 728-39-00 Kharkiv
  • +38 (056) 794-38-31 Dnipro
  • +38 (032) 229-58-93 Lviv
  • +38 (048) 738-57-70 Odessa
  • +38(093) 170-15-42  Life
  • +38 (067) 400-88-44 Kievstar
  • +1(888)393-24-51  USA, Toll free
  • +44(131)507-01-14  Great Britain
  • +7 (499) 348-28-61 Moscow

2.2.6. Sphinx

Sphinx(SQL Phrase Index) is a full-text search system with support for the morphology of various languages. Allows you to quickly and flexibly search for information in the database using free text.

Important points:

  • On tariffs businesshosting Sphinx is available by default. You do not need to order it separately.
  • Only the owner of the hosting account can order Sphinx.
  • When you order Sphinx for the first time, a free 7-day trial period is available.
  1. Open the section " Hosting ».
  2. In the block " Additional services »Click« Sphinx »:
  3. In the block " Basic data »Click« To order »:
  4. Click " To order »:
  5. If this is the first time ordering the service, skip this step to use free 7-day trial period . Otherwise, pay automatically generated invoice any of available ways and wait for the payment to be credited.
  6. Wait approximately 30 minutes for the service to activate.

To use Sphinx on a site, you need to configure both Sphinx itself and the site.

After ordering Sphinx, two tabs appear on the page of this additional service:

The tab contains rules describing what data and how Sphinx should work. By default, a template with an example is substituted into the configuration:

The configuration consists of two sections:

  • Data source ( source ) - configuration of the data source and its name (in the example db_source ):
    • Data type ( type ) - data source type (in the example mysql ).
    • Database connection data ( sql_host , sql_port , sql_user , sql_pass , sql_db ) — data to connect to MySQL database where the information for indexing will come from.
    • Preliminary request ( sql_query_pre ) - a request that will be before the main request for receiving data from the database (in the example SET NAMES utf8 - setting UTF-8 encoding).
    • The main query ( sql_query ) - a request to get the necessary data from the database for indexing (in the example select id, title, content from table - columns id , title and content from the table table ).
    • Other directives - allow you to define the order of grouping, filtering, sorting (details can be found in official documentation).
  • Indexing options ( index ) - the configuration of the index and its name (in the example test_index ):
    • Data source for indexing ( source ) - the name of the data source, where the information for indexing will come from (in the example db_source - see above).
    • The path where the index data will be stored ( path ) - the absolute path to the file with indices (in the example /home/example/.system/sphinx/test_index ).
    • Morphology settings ( morphology ) - the name of the library (in the example stem_ru ), which will be used to search for a word with different word forms - for example, by the query “ dog "Will return results with options" dogs », « dog », « dogs " etc.
    • Saving words in the index in their original form ( index_exact_words ) - when used in conjunction with the directive expand_keywords allows you to return more relevant results on request (in the example 1 - included).
    • The minimum word length for indexing ( min_word_len ) - used by default 1 , but words of this length usually do not carry a semantic load (in the example 3 ).
    • Other directives - allow you to define the order of grouping, filtering, sorting (details can be found in official documentation).

A detailed description of the operation of Sphinx and a list of all its parameters can be found in official documentation(English).

Below you can:

  • Select the protocol for accessing the Sphinx search daemon (searchd):
    • « MySQL »- Access via SphinxQL, a kind of SQL similar to MySQL.
    • « Sphinx "- access via SphinxAPI, own API Sphinx.
  • Enable or disable logging of requests to Sphinx - query_log.

After clicking " Save configuration »:

  • Sphinx will restart.
  • If the configuration finds partitions describing disk search indexes:
    • Separate cron tasks will be automatically created for them on the tab “ Indexes»With a frequency of updates every 15 minutes.
    • Index creation will start immediately after saving the configuration file (it may take some time).
The tab contains a list of added indexes:

Columns:

  • « Index "- the name of the index. Indicated in configuration in the section with indexing parameters.
  • « Update frequency "- the current schedule for starting indexing in the standard cron format. By default, indexing starts every 15 minutes.
  • « The size "- the size of the index. The data is cached for 10 minutes.
  • Buttons:
    • Pause / Start - button to pause / start scheduled indexing.
    • Edit - the button for changing the indexing start schedule.
    • Delete - button to delete the index. Attention! After clicking from configuration the section with indexing parameters for this index will be deleted.

Attention!

Before using plugins to work with Sphinx, carefully read their requirements and compatibility. Most plugins have not been supported for a long time and work with Sphinx version 2.2 or lower, the hosting uses version 3.

Setting up a site to work with Sphinx is in the competence of the site developer or involved third-party specialists.

The task is reduced to the following stages:

  1. Examine the contents of the site database and determine which data you need a quick search for.
  2. Configure Sphinx with the required parameters: specify from which database you want to get data, which tables and columns you want to index, set the indexing rules.
  3. Add code to the site that, instead of a standard database search, will search for data in the created Sphinx index. The code can be written by the developer either onmyown, or ready-made plugins or modules mentioned on official website.

The site connects to Sphinx over a socket. The socket path can be found on the Sphinx control page. The port should be specified depending on the configuration of the plug-in being connected; in general, the port can be neglected by specifying it as 0 or 9312.

To view the Sphinx log do the following:

  1. Copy the path to the log from the Sphinx control section.
  2. Run one of the commands:
    • View full log:
        cat ~ / .system / sphinx / searchd.log
    • Real-time log monitoring (use the combination Ctrl + C ):
        tail  -f ~ / .system / sphinx / searchd.log
Content