Implementing Sphinx

MageStack natively supports Sphinx, though we would recommend Elasticsearch for most stores as it is more straightforward to configure and maintain.

To configure Sphinx, you will need to:

  1. Enable Sphinx for the vhost (please raise a support ticket in the Sonassi control panel to do this)
  2. Ensure that you have placed the Sphinx configuration files in the correct directory (see below)

Sphinx Configuration Details

Hostname:  sphinx1.i
Port:      9315

SphinxQL Configuration Details

Hostname:  sphinx1.i
Port:      9316

Sphinx configuration file locations

! Your configuration file is usually generated by your Extension, please refer to the extensions documentation for instructions on how to do this.

There are 3 main configuration files we observe when building a Sphinx core for your vhost

The following directory must exist (adjust example and example.com to suit),

/microcloud/domains/example/domains/example.com/http/lib/Sphinx

Then within that, the following configuration files are valid,

wordforms.txt
stopwords.txt
synonyms.txt
sphinx.conf

Mirasvit Sphinx module

Mirasvit modules do not use unique index names; so only 1 vhost on the stack can use Sphinx (for example: either a development site or a live site, not both)

Other Sphinx modules that can use unique indexes per store/vhost do not have this limitation.

The Mirasvit generated Sphinx configs require modification before they are used:

The indexer { } config section must be removed from the sphinx.conf that the module generates.

The searchd { } config section must also be removed from the same sphinx.conf.

The path variables that are generated in sphinx.conf may also need to be updated, as their default values will be incorrect - for example::

path          = /domains/example.com/http/var/sphinx/catalogsearch_fulltext_scope2

should be the following instead, using the %%SPHINXDIR%% variable:

path          = %%SPHINXDIR%%/catalogsearch_fulltext_scope2

Please note that for Magento 2 stores in particular, you should use port 9316 with a Mirasvit Sphinx module, rather than the default port 9315.

Once you have added/updated these files, you can reload Sphinx by running:

/etc/init.d/sphinx reload

Default Sphinx configuration

! This configuration should only be used if you are developing your own extension that utilizes Sphinx

If you haven't specified your own Sphinx configuration, we use the following defaults (as is used on the example.com demo store on MageStack), the fields

source magento_examplecom {
  type = mysql
  sql_host = %%DBHOST%%
  sql_user = %%DBUSER%%
  sql_pass = %%DBPASS%%
  sql_db   = %%DBNAME%%
  sql_port = 3306
  sql_sock = /var/lib/mysql/mysql.sock
  sql_query_pre = SET NAMES utf8;
  sql_query     = SELECT CONCAT(product_id, store_id) AS id, catalogsearch_fulltext.* FROM catalogsearch_fulltext
  sql_attr_uint = product_id
  sql_attr_uint = store_id
}

index examplecom {
  source = magento_examplecom
  path = %%SPHINXDIR%%/sphinx.index
  morphology   = stem_en, metaphone
  min_word_len = 1
  charset_type = utf-8
  blend_chars  = -
  blend_mode   = trim_both
  html_strip   = 1
  stopwords     = /microcloud/data/mysql/sphinx/examplecom/stopwords.txt
  exceptions    = /microcloud/data/mysql/sphinx/examplecom/synonyms.txt
  wordforms     = /microcloud/data/mysql/sphinx/examplecom/wordforms.txt
}

Using Variables in Configuration file

There are a number of pre-defined variables so that you can use to make management easier, they should be wrapped in %% characters as shown:

  • %%DBHOST%% - The database host (as stored in your local.xml)
  • %%DBNAME%% - The database name (as stored in your local.xml)
  • %%DBUSER%% - The database username (as stored in your local.xml)
  • %%DBPASS%% - The database password (as stored in your local.xml)
  • %%CLEANTLD%% - This is the vhost domain name, with all non a-zA-Z0-9 characters removed (Eg. examplecom)
  • %%INDEX_NAME%% - Same as the CLEANTLD variable
  • %%GROUP%% - The domain group name (eg. example)
  • %%TLD%% - The vhost top level domain, as defined in its directory path (eg. example.com)
  • %%SPHINXDIR%% - This is the path to the Sphinx index, it is automatically populated based on the index name (eg. examplecom)