feat(search): search among info indexes

This commit is contained in:
Alexey Kasyanchuk
2018-08-28 21:14:49 +03:00
parent 4c2ff465f2
commit ff28e70251
4 changed files with 40 additions and 3 deletions

View File

@ -133,8 +133,19 @@ const expand = (sphinx) => {
let data = '';
const parseValues = (values) => {
if(sphinxIndex)
{
for(const k in sphinxIndex)
values[k] = values[sphinxIndex[k]]
{
if(typeof sphinxIndex[k] === 'string')
{
values[k] = values[sphinxIndex[k]]
}
else if (typeof sphinxIndex[k] === 'function')
{
values[k] = sphinxIndex[k](values)
}
}
}
let valuesData = ''
names = ''

View File

@ -138,7 +138,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
this.sphinx.replaceValues('torrents', {hash, info: data}, {
particial: true,
key: 'hash',
sphinxIndex: {nameIndex: 'name'},
sphinxIndex: {nameIndex: (obj) => buildTorrentIndex(obj)},
merge: ['info'],
mergeCallback: (n, obj) => {
if(n != 'info')
@ -442,6 +442,16 @@ module.exports = function (send, recive, dataDirectory, version, env)
return torrent
}
const buildTorrentIndex = (torrent) => {
let index = torrent.name
if(torrent.info && typeof torrent.info.name === 'string' && torrent.info.name.length > 0)
{
if(torrent.info.name.length < 800)
index += ' ' + torrent.info.name
}
return index
}
const insertTorrentToDB = (torrent, silent) => new Promise((resolve) => {
if(!torrent)
{
@ -533,7 +543,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
addFilesToDatabase()
}
torrent.nameIndex = torrent.name
torrent.nameIndex = buildTorrentIndex(torrent)
sphinxSingle.insertValues('torrents', torrent, function(err, result) {
if(result) {