использование sphinx
This commit is contained in:
parent
95e16d78a3
commit
d801b042e6
23
index.js
23
index.js
@ -17,6 +17,11 @@ const mysqlSettings = {
|
||||
database : 'btsearch'
|
||||
};
|
||||
|
||||
const sphinxSettings = {
|
||||
host : 'localhost',
|
||||
port : 9306
|
||||
};
|
||||
|
||||
// Start server
|
||||
server.listen(8095);
|
||||
|
||||
@ -28,6 +33,12 @@ let socketMysql = mysql.createPool({
|
||||
database : mysqlSettings.database
|
||||
});
|
||||
|
||||
let sphinx = mysql.createPool({
|
||||
connectionLimit: 30,
|
||||
host : sphinxSettings.host,
|
||||
port : sphinxSettings.port
|
||||
});
|
||||
|
||||
const udpTrackers = [
|
||||
{
|
||||
host: 'tracker.coppersurfer.tk',
|
||||
@ -90,15 +101,15 @@ io.on('connection', function(socket)
|
||||
function baseRowData(row)
|
||||
{
|
||||
return {
|
||||
hash: row.hash,
|
||||
hash: row.hash || row.id,
|
||||
name: row.name,
|
||||
size: row.size,
|
||||
files: row.files,
|
||||
filesList: row.filesList,
|
||||
piecelength: row.piecelength,
|
||||
added: row.added.getTime(),
|
||||
contentType: row.contentType,
|
||||
contentCategory: row.contentCategory,
|
||||
added: row.added ? row.added.getTime() : (new Date()).getTime(),
|
||||
contentType: row.contentType || row.contenttype,
|
||||
contentCategory: row.contentCategory || row.contentcategory,
|
||||
seeders: row.seeders,
|
||||
completed: row.completed,
|
||||
leechers: row.leechers,
|
||||
@ -182,7 +193,7 @@ io.on('connection', function(socket)
|
||||
const index = navigation.index || 0;
|
||||
const limit = navigation.limit || 10;
|
||||
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) {
|
||||
callback(undefined)
|
||||
return;
|
||||
@ -209,7 +220,7 @@ io.on('connection', function(socket)
|
||||
const index = navigation.index || 0;
|
||||
const limit = navigation.limit || 10;
|
||||
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) {
|
||||
callback(undefined)
|
||||
return;
|
||||
|
98
sphinx.conf
Normal file
98
sphinx.conf
Normal 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/
|
||||
}
|
Loading…
Reference in New Issue
Block a user