fix(search): error on sorting files in search

This commit is contained in:
Alexey Kasyanchuk 2018-05-02 13:06:48 +03:00
parent 526c1d0b7d
commit 6a59744f73

View File

@ -2,6 +2,7 @@ const ipaddr = require('ipaddr.js');
const forBigTable = require('./forBigTable') const forBigTable = require('./forBigTable')
const compareVersions = require('compare-versions'); const compareVersions = require('compare-versions');
const getTorrent = require('./gettorrent') const getTorrent = require('./gettorrent')
const _ = require('lodash')
module.exports = ({ module.exports = ({
sphinx, sphinx,
@ -317,12 +318,14 @@ module.exports = ({
let order = ''; let order = '';
let where = ''; let where = '';
/*
if(orderBy && orderBy.length > 0) if(orderBy && orderBy.length > 0)
{ {
const orderDesc = navigation.orderDesc ? 'DESC' : 'ASC'; const orderDesc = navigation.orderDesc ? 'DESC' : 'ASC';
args.splice(1, 0, orderBy); args.splice(1, 0, orderBy);
order = 'ORDER BY ?? ' + orderDesc; order = 'ORDER BY ?? ' + orderDesc;
} }
*/
/* /*
if(safeSearch) if(safeSearch)
{ {
@ -386,7 +389,14 @@ module.exports = ({
delete search[torrent.hash] delete search[torrent.hash]
} }
callback(Object.values(search)); let searchResult = Object.values(search)
if(orderBy && orderBy.length > 0 && searchResult.length > 0)
{
searchResult = _.orderBy(searchResult, [orderBy], [navigation.orderDesc ? 'desc' : 'asc'])
}
callback(searchResult);
}) })
}); });
} }