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

@ -302,6 +302,13 @@ export default class Torrent extends Component {
node.onclick = () => { return false }
}}>
<div className='column' style={{height: 'auto', whiteSpace: 'normal', paddingTop: '0.30em'}}>
{
torrent.info && torrent.info.name
&&
<div className='row w100p inline fs0-85' style={{color: 'grey', padding: '4px 0px 5px'}}>
{torrent.info.name}
</div>
}
<div className='row w100p inline'>
<div style={{color: torrent.contentCategory != 'xxx' ? (torrent.peer ? '#5252d1' : 'black') : (torrent.peer ? '#9083e2' : 'grey')}}>
{

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) {

View File

@ -35,6 +35,15 @@ describe("big table for check", () => {
assert.equal((await sphinx.query(`select data from feed where id = 1`))[0].data, '{"a":1,"b":2,"c":3,"d":6,"e":5}')
})
it("replace text index as function", async function() {
await sphinx.replaceValues('feed', {id: 1, data: {a: 6}}, {particial: true, sphinxIndex: { feedIndex: (obj) => {
assert.equal(obj.data.a, 6)
return "aabbccdd"
}} })
assert.equal((await sphinx.query(`select data from feed where id = 1`))[0].data, '{"a":6}')
assert.equal((await sphinx.query(`select id from feed where match('aabbccdd')`))[0].id, 1)
})
it("insert object to database", async function() {
const obj = {a: 1, v: 2}
const p = {id: 3, data: obj}