new_rotation_sphinx
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| new_rotation_sphinx [2017/04/07 16:24] – [1.51] admin | new_rotation_sphinx [2026/03/21 10:11] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Sphinx for Rotation\Tube sites ====== | ====== Sphinx for Rotation\Tube sites ====== | ||
| - | Basically script uses mysql to search DB, but on large DB mysql too slow. + it doesnt use morphology. | + | When your database exceeds 100,000 galleries, standard MySQL search becomes |
| - | Sphinx | + | Sphinx is a fast search |
| + | 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. | ||
| - | Setup | + | Sphinx creates a search index by analyzing your entire database, enabling fast and accurate searching. However, this index must be periodically refreshed. Database changes only appear in the Sphinx index after reindexing. |
| - | * Ask admin to setup sphinx | + | Full reindexing of large databases is resource-intensive, |
| - | * create folder scj/ | + | |
| - | * ask admin to add scj index into sphinx config. (See config example below ) | + | |
| - | * Run indexer (or ask admin to do it) < | + | |
| - | * In Rotation - Settings edit sphinx options. | + | |
| - | That's it. | + | You can also index your search query log with Sphinx to find similar searches (Sphinx Search Log Index). |
| - | **Note** if you change DB (add\remove content) - please, run indexer every day to keep it's base up to date. | + | Sphinx offers different search modes (Sphinx Search Mod) and result ranking options (Sphinx Ranker Mod). See the Sphinx documentation for details. |
| - | Add to cron something like (ask admin) | + | Common search terms can return huge result sets with excessive pagination. Sphinx Max Matches lets you limit the maximum number of results returned. |
| + | |||
| + | |||
| + | ===== 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 25: | Line 36: | ||
| - | ====== Sphinx | + | ===== Sphinx |
| - | ===== TCMS (version 2.X) ===== | + | 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. |
| + | 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. | ||
| - | searchd | + | Sphinx searches both the main index and delta index together, showing all changes. You can create delta indexes as frequently as needed. |
| - | { | + | |
| - | listen | + | |
| - | addition of mysql41 is the most important part. It's called SphinxQL | ||
| + | Result: | ||
| + | in the main part which you already have you need to add after | ||
| - | source your_name_source | + | sql_query_pre |
| - | { | + | |
| - | type = mysql | + | |
| - | sql_host = localhost | + | line |
| - | sql_user = | + | |
| - | sql_pass = | + | |
| - | sql_db = | + | |
| - | sql_port = 3306 # optional, default is 3306 | + | |
| - | sql_query_pre = SET NAMES utf8 | + | |
| - | sql_query = SELECT gi.gallery_id, | ||
| - | (SELECT group_concat(tag_name) FROM rot_gal2tag g2t \ | ||
| - | LEFT JOIN rot_tags as t on t.tag_id = g2t.tag_id \ | ||
| - | WHERE g2t.gallery_id = gi.gallery_id) as tags, \ | ||
| - | (SELECT group_concat(tag_id) FROM rot_gal2tag g2t \ | ||
| - | WHERE g2t.gallery_id = gi.gallery_id) as tag_ids, \ | ||
| - | (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 gallery_status = ' | ||
| - | and gs.best_thumb = ' | ||
| + | Now you need to add the creation of a delta index | ||
| - | sql_attr_timestamp = date | + | < |
| - | sql_attr_uint | + | |
| - | sql_attr_uint | + | |
| - | sql_attr_float | + | |
| - | sql_attr_uint | + | |
| - | sql_attr_multi = uint categories from field; | + | |
| - | sql_attr_multi = uint tag_ids from field; | + | |
| + | 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 your_name_index | + | index delta : your_name_index |
| { | { | ||
| - | source = your_name_source | + | |
| - | path = /your_path | + | path = /your_full_path/ |
| - | docinfo = extern | + | |
| - | morphology | + | |
| - | charset_type = utf-8 | + | |
| } | } | ||
| + | |||
| </ | </ | ||
| - | ===== 1.52 ===== | + | |
| + | 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 | ||
| + | |||
| + | After creating the index you need to specify delta in the Sphinx Delta Index settings of rotation. | ||
| + | |||
| + | and once a day for example you can attach the delta index to the main one | ||
| + | |||
| + | indexer --rotate --merge your_name_index delta | ||
| + | |||
| + | |||
| + | All. | ||
| + | |||
| + | |||
| + | |||
| + | ===== Search Log ===== | ||
| + | |||
| + | When users search on your site (domain.com/? | ||
| + | |||
| + | To do this add to the Sphinx config | ||
| < | < | ||
| - | source | + | source |
| { | { | ||
| type = mysql | type = mysql | ||
| - | sql_host = | + | sql_host = |
| - | sql_user = | + | sql_user = |
| - | sql_pass = | + | sql_pass = |
| - | sql_db = | + | sql_db = |
| sql_port = 3306 # optional, default is 3306 | sql_port = 3306 # optional, default is 3306 | ||
| - | sql_query = SELECT id, date, tags, alt, description, | + | sql_query_pre |
| - | | + | |
| - | // for version 49 | + | |
| - | // | + | |
| - | // | + | |
| - | sql_attr_timestamp = date | + | sql_query = SELECT sq_id, search_query, |
| - | sql_attr_uint | + | |
| - | sql_attr_uint | + | sql_attr_uint |
| - | sql_attr_uint | + | sql_attr_uint |
| - | sql_query_info | ||
| } | } | ||
| - | index scj_index | + | index search_queries_index |
| { | { | ||
| - | source = | + | source = |
| - | path = /path_to_data/ | + | path = /WHERE_TO_STORE |
| docinfo = extern | docinfo = extern | ||
| - | morphology | + | morphology |
| } | } | ||
| </ | </ | ||
| - | ===== 1.51 ===== | ||
| - | < | ||
| - | source scj | ||
| - | { | ||
| - | type = mysql | ||
| - | sql_host = | + | 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> |
| - | sql_user = | + | |
| - | sql_pass = .............. | + | |
| - | sql_db = | + | |
| - | sql_port = 3306 # optional, default is 3306 | + | |
| - | sql_query = SELECT id, crc32(g.gallery_md5) | + | Don't forget to reindex regularly. For example: you search for " |
| - | | + | ===== Sphinx settings |
| - | | + | |
| - | | + | |
| - | | + | |
| - | sql_attr_timestamp = date | + | |
| - | sql_attr_uint | + | |
| - | sql_attr_uint | + | |
| - | sql_attr_uint | + | |
| - | sql_attr_float | + | |
| - | sql_attr_uint | + | |
| - | sql_attr_uint = gallery_md5_crc | + | |
| - | sql_attr_multi = uint categories from field; | + | |
| - | sql_query_info = SELECT * FROM rot_galleries WHERE id=$id | + | 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 | ||
| - | You have to edit here: | ||
| - | scj_mysql_login | + | ===== Sphinx |
| - | scj_mysql_password | + | |
| - | scj_db | + | |
| - | path_to_data | + | |
| - | </ | + | |
| - | ===== Sphinx | + | |
| - | For Version 2.X | + | Slaves use Sphinx data from the master' |
| - | This part make sense only if you have a really big DB (1M+ , for example | + | 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. |
| - | When Sphinx creates an index it takes a snapshot of a current state of a DB. So if something has been changed since then - it won't be reflected in index. And if you have a big DB it takes a lot of time to reindex it. | ||
| - | So the good idea is to just reindex those parts that have been changed. That's why you need so called delta index | + | ===== Sphinx Search CTR ===== |
| - | To make use of it you need to add after | + | Sphinx search defaults |
| - | sql_query_pre = SET NAMES utf8 | ||
| - | a new line | + | ===== Sphinx settings ===== |
| - | sql_query_pre = UPDATE rot_settings SET value = (SELECT MAX(gallery_id) FROM rot_gallery_info) WHERE name = ' | + | 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 " | ||
| - | And add a new source | ||
| - | < | + | But of course it's best to go through the Sphinx documentation and choose the parameters for yourself. |
| - | source delta : your_name_source | ||
| - | { | ||
| - | sql_query_pre = SET NAMES utf8 | ||
| - | sql_query = SELECT gi.gallery_id, | + | ===== Sphinx Reindex |
| - | (SELECT group_concat(tag_name) FROM rot_gal2tag g2t \ | + | |
| - | LEFT JOIN rot_tags as t on t.tag_id | + | |
| - | WHERE g2t.gallery_id | + | |
| - | (SELECT group_concat(gss.group_id) FROM rot_gallery_stats1 as gss \ | + | |
| - | WHERE gss.gallery_id | + | |
| - | FROM rot_gallery_info AS gi \ | + | |
| - | JOIN rot_gallery_data1 AS gd ON gi.gallery_id | + | |
| - | JOIN rot_gallery_stats1 AS gs ON gs.gallery_id | + | |
| - | WHERE gi.gallery_id > ( SELECT value FROM rot_settings WHERE name = ' | + | |
| - | AND gallery_status | + | |
| - | and gs.best_thumb = ' | + | |
| - | + | ||
| - | } | + | |
| + | 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. | ||
| - | index delta : your_name_index | + | Reindex periodically. The best approach: schedule reindexing via cron during your lowest-traffic periods. |
| - | { | + | ===== Mysql Search ===== |
| - | source | + | |
| - | path = / | + | |
| - | } | + | |
| + | 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. | ||
| - | You can note that it has the same query with an addition of sphinx_max_gallery_id. | + | 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 |
| - | Now you have to add a new crontab task that will reindex new parts | + | To use this option (easier than Sphinx |
| - | indexer --rotate delta | + | < |
| + | ALTER TABLE `rot_gallery_data1` ADD FULLTEXT ( | ||
| + | `alt` , | ||
| + | `description` | ||
| + | ) | ||
| + | </ | ||
| - | Now you have to add ' | + | And switch in settings |
| - | once a day you can marge main index and delta index | ||
| - | |||
| - | indexer --rotate --merge your_name_index delta | ||
| - | |||
| - | |||
| - | That's it. | ||
new_rotation_sphinx.1491582266.txt.gz · Last modified: by admin
