new_rotation_sphinx
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| new_rotation_sphinx [2025/02/15 11:34] – [Sphinx search] admin | new_rotation_sphinx [2026/03/21 10:11] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Sphinx | + | ====== Sphinx |
| - | Basically script uses mysql to search DB, but with large DB mysql is too slow. It also doesn' | + | When your database exceeds 100,000 galleries, standard MySQL search becomes |
| - | Sphinx | + | Sphinx is a fast search |
| - | **Workflow:** | + | Sphinx extracts keywords from your database, creating an optimized search index. The process works like this: your script queries Sphinx, which returns gallery IDs, and then the script retrieves full data from MySQL. This means that when your MySQL database changes, the Sphinx index needs updating too. |
| - | * You have a DB with galleries | + | Sphinx creates a search index by analyzing |
| - | * Sphinx creates a " | + | |
| - | * SmartCJ queries | + | |
| - | * Sphinx does a search and returns results | + | |
| - | * SmartCJ outputs results | + | |
| - | **Setup:** | + | Full reindexing of large databases is resource-intensive, |
| - | * Ask admin to setup sphinx | + | You can also index your search |
| - | * switch from regular | + | |
| - | * ask admin to add scj index into sphinx config. (Copy config from Rotation - Settings - Site Search config example | + | |
| - | * Run indexer (or ask admin to do it) < | + | |
| - | * In Rotation - Settings - Site search make sure you added Sphinx settings (Sphinx Host, Port, index name - add you real data, ask admin if you don't know it) | + | |
| - | That's it. | + | Sphinx offers different search modes (Sphinx Search Mod) and result ranking options (Sphinx Ranker Mod). See the Sphinx documentation for details. |
| - | **Note** if you change DB (add\remove content) - please, run indexer every day to keep it's base up to date. | + | Common search terms can return huge result sets with excessive pagination. Sphinx Max Matches lets you limit the maximum number of results returned. |
| - | Add to cron something like (ask admin) | ||
| + | |||
| + | ===== Sphinx installation ===== | ||
| + | |||
| + | * Ask your admin to install Sphinx | ||
| + | * Create the directory scj/sphinx | ||
| + | * Add the index configuration to Sphinx config (usually done by admin). Find the configuration in Rotation Settings - Site Search | ||
| + | * Run database indexing (usually done by admin): `indexer --all --rotate` | ||
| + | * You only need to configure the settings in Rotation Settings, which you can get from your admin | ||
| + | |||
| + | That's it. | ||
| + | |||
| + | |||
| + | You need to periodically run database indexing: | ||
| < | < | ||
| indexer --all --rotate | indexer --all --rotate | ||
| Line 32: | Line 36: | ||
| - | ====== Sphinx | + | ===== Sphinx |
| - | Please, open Rotation Settings - Site Search , change search engine to sphinx and the script will generate | + | The Sphinx index captures your database at a point in time. Any changes made after indexing won't be discoverable by Sphinx. |
| + | This means you'd need to reindex after every database change, but full reindexing is time-consuming and resource-intensive on large databases. | ||
| - | ====== Sphinx | + | Delta indexing solves this. A delta index captures changes made since the last full index, and since it contains only new data, it builds very quickly. |
| - | If you have a large DB it might take time to reindex | + | Sphinx searches both the main index and delta index together, showing all changes. You can create delta indexes as frequently as needed. |
| - | Now you have to add a new crontab task that will reindex | + | |
| + | Result: | ||
| + | |||
| + | in the main part which you already | ||
| + | |||
| + | sql_query_pre = SET NAMES utf8 | ||
| + | |||
| + | line | ||
| + | |||
| + | sql_query_pre = UPDATE rot_settings SET value = (SELECT MAX(gallery_id) FROM rot_gallery_info) WHERE name = ' | ||
| + | |||
| + | |||
| + | Now you need to add the creation of a delta index | ||
| + | |||
| + | < | ||
| + | |||
| + | source delta : your_name_source | ||
| + | { | ||
| + | sql_query_pre = SET NAMES utf8 | ||
| + | |||
| + | sql_query = SELECT gi.gallery_id, | ||
| + | (SELECT group_concat(name) FROM rot_groups | ||
| + | (SELECT group_concat(gss.group_id) FROM rot_gallery_stats1 as gss WHERE gss.gallery_id = gi.gallery_id AND group_id != 0) as categories FROM rot_gallery_info AS gi JOIN rot_gallery_data1 AS gd ON gi.gallery_id = gd.gallery_id JOIN rot_gallery_stats1 AS gs ON gs.gallery_id = gi.gallery_id WHERE gi.gallery_id > ( SELECT value FROM rot_settings WHERE name = ' | ||
| + | |||
| + | } | ||
| + | |||
| + | |||
| + | index delta : your_name_index | ||
| + | { | ||
| + | source = delta | ||
| + | path = / | ||
| + | } | ||
| + | |||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | As you can see the query is the same, the only difference is the presence of sphinx_max_gallery_id in the selection. | ||
| + | |||
| + | After that you need to add indexing of new records to the cron as often as you like | ||
| indexer --rotate delta | indexer --rotate delta | ||
| - | Now you have to add 'delta' into | + | After creating the index you need to specify |
| - | once a day you can marge main index and delta index | + | and once a day for example |
| indexer --rotate --merge your_name_index delta | indexer --rotate --merge your_name_index delta | ||
| - | That's it. | + | All. |
| - | ====== Sphinx and slave sites ====== | ||
| - | Slave site automatically | + | ===== Search Log ===== |
| + | |||
| + | When users search on your site (domain.com/? | ||
| + | |||
| + | To do this add to the Sphinx config | ||
| + | |||
| + | < | ||
| + | source search_queries | ||
| + | { | ||
| + | type = mysql | ||
| + | |||
| + | sql_host = YOUR_HOST | ||
| + | sql_user = USERNAME | ||
| + | sql_pass = PASSWORD | ||
| + | sql_db = DB_NAME | ||
| + | sql_port = 3306 # optional, default is 3306 | ||
| + | |||
| + | sql_query_pre = SET NAMES utf8 | ||
| + | |||
| + | sql_query = SELECT sq_id, search_query, | ||
| + | |||
| + | sql_attr_uint | ||
| + | sql_attr_uint | ||
| + | |||
| + | } | ||
| + | |||
| + | |||
| + | index search_queries_index | ||
| + | { | ||
| + | source = search_queries | ||
| + | path = / | ||
| + | docinfo = extern | ||
| + | morphology | ||
| + | } | ||
| + | |||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | Specify this in Rotation Settings - Sphinx Search Log Index. The script will use this index to find similar queries for display. For example, when searching for a keyword, you can show a list of similar searches using `<thumb search_log=all filter=GET_search> | ||
| + | |||
| + | Don't forget | ||
| + | ===== Sphinx settings ===== | ||
| + | |||
| + | Sphinx Search Index main index | ||
| + | |||
| + | Sphinx Delta Index - delta index | ||
| + | |||
| + | Sphinx Search Log Index | ||
| + | |||
| + | Sphinx Search Mod | ||
| + | for advanced user only, do not change if you are not sure | ||
| + | Sphinx Ranker Mod | ||
| + | for advanced user only, do not change if you are not sure | ||
| + | Sphinx Max Matches | ||
| + | for advanced user only, do not change if you are not sure | ||
| + | default 20000 | ||
| + | |||
| + | |||
| + | |||
| + | ===== Sphinx for child (slave) sites ===== | ||
| + | |||
| + | Slaves use Sphinx data from the master' | ||
| + | |||
| + | One issue to watch for: Sphinx host is typically set to localhost. If a slave is on a different server, localhost won't work. Instead, specify the actual IP address of the Sphinx server. Also verify that connections to this port are allowed from the slave server to the Sphinx server. | ||
| + | |||
| + | |||
| + | ===== Sphinx Search CTR ===== | ||
| + | |||
| + | Sphinx search defaults to relevance sorting (domain/? | ||
| + | |||
| + | |||
| + | ===== Sphinx settings ===== | ||
| + | |||
| + | Sphinx has great capabilities for tuning indexing and search. For example, it's a good idea to add these optional lines to the config. | ||
| + | |||
| + | min_word_len = 3 # Minimum length of indexed word | ||
| + | min_infix_len = 2 # Minimum infix length (prefix included) | ||
| + | enable_star = 1 # Use truncation operator " | ||
| + | |||
| + | |||
| + | But of course it's best to go through the Sphinx documentation and choose the parameters for yourself. | ||
| + | |||
| + | |||
| + | ===== Sphinx Reindex ===== | ||
| + | |||
| + | Sphinx is not magic—it searches using its index. The index is created when you index your database. If you change the database (add, delete galleries, etc.) without reindexing Sphinx, it won't see those changes. | ||
| + | |||
| + | Reindex periodically. The best approach: schedule reindexing via cron during your lowest-traffic periods. | ||
| + | ===== Mysql Search ===== | ||
| + | |||
| + | By default, search uses `WHERE description LIKE ' | ||
| + | |||
| + | If you don't use Sphinx, the script uses MySQL' | ||
| + | |||
| + | Sphinx is the best option and is described above. | ||
| + | |||
| + | A middle-ground option is FullText Search for MySQL (the last item in the Search fields options). MySQL can search using morphology, though before version 5.6 this only worked with MyISAM tables. | ||
| + | |||
| + | To use this option (easier than Sphinx to set up), add a fulltext index to the rot_gallery_data* tables: | ||
| + | |||
| + | < | ||
| + | ALTER TABLE `rot_gallery_data1` ADD FULLTEXT ( | ||
| + | `alt` , | ||
| + | `description` | ||
| + | ) | ||
| + | </ | ||
| + | |||
| + | And switch in settings the option to FullText search. | ||
new_rotation_sphinx.1739619278.txt.gz · Last modified: by admin
