использование sphinx

This commit is contained in:
Alexey Kasyanchuk 2017-01-08 23:29:25 +03:00
parent 95e16d78a3
commit d801b042e6
2 changed files with 115 additions and 6 deletions

View File

@ -17,6 +17,11 @@ const mysqlSettings = {
database : 'btsearch' database : 'btsearch'
}; };
const sphinxSettings = {
host : 'localhost',
port : 9306
};
// Start server // Start server
server.listen(8095); server.listen(8095);
@ -28,6 +33,12 @@ let socketMysql = mysql.createPool({
database : mysqlSettings.database database : mysqlSettings.database
}); });
let sphinx = mysql.createPool({
connectionLimit: 30,
host : sphinxSettings.host,
port : sphinxSettings.port
});
const udpTrackers = [ const udpTrackers = [
{ {
host: 'tracker.coppersurfer.tk', host: 'tracker.coppersurfer.tk',
@ -90,15 +101,15 @@ io.on('connection', function(socket)
function baseRowData(row) function baseRowData(row)
{ {
return { return {
hash: row.hash, hash: row.hash || row.id,
name: row.name, name: row.name,
size: row.size, size: row.size,
files: row.files, files: row.files,
filesList: row.filesList, filesList: row.filesList,
piecelength: row.piecelength, piecelength: row.piecelength,
added: row.added.getTime(), added: row.added ? row.added.getTime() : (new Date()).getTime(),
contentType: row.contentType, contentType: row.contentType || row.contenttype,
contentCategory: row.contentCategory, contentCategory: row.contentCategory || row.contentcategory,
seeders: row.seeders, seeders: row.seeders,
completed: row.completed, completed: row.completed,
leechers: row.leechers, leechers: row.leechers,
@ -182,7 +193,7 @@ io.on('connection', function(socket)
const index = navigation.index || 0; const index = navigation.index || 0;
const limit = navigation.limit || 10; const limit = navigation.limit || 10;
let search = {}; let search = {};
socketMysql.query('SELECT * FROM `torrents` WHERE MATCH(`name`) AGAINST(?) LIMIT ?,?', [text, index, limit], function (error, rows, fields) { sphinx.query('SELECT * FROM `torrents_index` WHERE MATCH(?) LIMIT ?,?', [text, index, limit], function (error, rows, fields) {
if(!rows) { if(!rows) {
callback(undefined) callback(undefined)
return; return;
@ -209,7 +220,7 @@ io.on('connection', function(socket)
const index = navigation.index || 0; const index = navigation.index || 0;
const limit = navigation.limit || 10; const limit = navigation.limit || 10;
let search = {}; let search = {};
socketMysql.query('SELECT * FROM `files` INNER JOIN torrents ON(torrents.hash = files.hash) WHERE MATCH(`path`) AGAINST(?) LIMIT ?,?', [text, index, limit], function (error, rows, fields) { sphinx.query('SELECT * FROM `files_index` WHERE MATCH(?) LIMIT ?,?', [text, index, limit], function (error, rows, fields) {
if(!rows) { if(!rows) {
callback(undefined) callback(undefined)
return; return;

98
sphinx.conf Normal file
View File

@ -0,0 +1,98 @@
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
source files_index
{
type = mysql
sql_host = localhost
sql_user = btsearch
sql_pass = pirateal100x
sql_db = btsearch
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT fls.fileid, fls.path, fls.size as filesize, \
torrents.hash as hash, torrents.name as name, torrents.size as size, \
torrents.seeders, torrents.leechers, torrents.completed, \
torrents.files, torrents.contentType, torrents.contentCategory \
FROM files as fls INNER JOIN torrents ON(torrents.hash = fls.hash)
sql_field_string = path
sql_attr_string = hash
sql_attr_bigint = filesize
sql_attr_string = name
sql_attr_bigint = size
sql_attr_uint = files
sql_attr_uint = seeders
sql_attr_uint = leechers
sql_attr_uint = completed
sql_attr_string = contentType
sql_attr_string = contentCategory
}
index files_index
{
source = files_index
path = /var/lib/sphinx/btsearch
min_word_len = 3
}
source torrents_index
{
type = mysql
sql_host = localhost
sql_user = btsearch
sql_pass = pirateal100x
sql_db = btsearch
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT torrents.hash as hash, torrents.name as name, torrents.size as size, \
torrents.seeders, torrents.leechers, torrents.completed, \
torrents.files, torrents.contentType, torrents.contentCategory \
FROM torrents
sql_field_string = name
sql_attr_bigint = size
sql_attr_uint = files
sql_attr_uint = seeders
sql_attr_uint = leechers
sql_attr_uint = completed
sql_attr_string = contentType
sql_attr_string = contentCategory
}
index torrents_index
{
source = torrents_index
path = /var/lib/sphinx/btsearch
min_word_len = 3
}
indexer
{
mem_limit = 128M
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = /var/log/sphinx/searchd.log
query_log = /var/log/sphinx/query.log
read_timeout = 5
max_children = 30
pid_file = /var/run/sphinx/searchd.pid
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = /var/lib/sphinx/
}