feat(search): search among info indexes
This commit is contained in:
@ -302,6 +302,13 @@ export default class Torrent extends Component {
|
|||||||
node.onclick = () => { return false }
|
node.onclick = () => { return false }
|
||||||
}}>
|
}}>
|
||||||
<div className='column' style={{height: 'auto', whiteSpace: 'normal', paddingTop: '0.30em'}}>
|
<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 className='row w100p inline'>
|
||||||
<div style={{color: torrent.contentCategory != 'xxx' ? (torrent.peer ? '#5252d1' : 'black') : (torrent.peer ? '#9083e2' : 'grey')}}>
|
<div style={{color: torrent.contentCategory != 'xxx' ? (torrent.peer ? '#5252d1' : 'black') : (torrent.peer ? '#9083e2' : 'grey')}}>
|
||||||
{
|
{
|
||||||
|
@ -133,8 +133,19 @@ const expand = (sphinx) => {
|
|||||||
let data = '';
|
let data = '';
|
||||||
const parseValues = (values) => {
|
const parseValues = (values) => {
|
||||||
if(sphinxIndex)
|
if(sphinxIndex)
|
||||||
|
{
|
||||||
for(const k in 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 = ''
|
let valuesData = ''
|
||||||
names = ''
|
names = ''
|
||||||
|
@ -138,7 +138,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
this.sphinx.replaceValues('torrents', {hash, info: data}, {
|
this.sphinx.replaceValues('torrents', {hash, info: data}, {
|
||||||
particial: true,
|
particial: true,
|
||||||
key: 'hash',
|
key: 'hash',
|
||||||
sphinxIndex: {nameIndex: 'name'},
|
sphinxIndex: {nameIndex: (obj) => buildTorrentIndex(obj)},
|
||||||
merge: ['info'],
|
merge: ['info'],
|
||||||
mergeCallback: (n, obj) => {
|
mergeCallback: (n, obj) => {
|
||||||
if(n != 'info')
|
if(n != 'info')
|
||||||
@ -442,6 +442,16 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
return torrent
|
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) => {
|
const insertTorrentToDB = (torrent, silent) => new Promise((resolve) => {
|
||||||
if(!torrent)
|
if(!torrent)
|
||||||
{
|
{
|
||||||
@ -533,7 +543,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
addFilesToDatabase()
|
addFilesToDatabase()
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent.nameIndex = torrent.name
|
torrent.nameIndex = buildTorrentIndex(torrent)
|
||||||
|
|
||||||
sphinxSingle.insertValues('torrents', torrent, function(err, result) {
|
sphinxSingle.insertValues('torrents', torrent, function(err, result) {
|
||||||
if(result) {
|
if(result) {
|
||||||
|
@ -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}')
|
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() {
|
it("insert object to database", async function() {
|
||||||
const obj = {a: 1, v: 2}
|
const obj = {a: 1, v: 2}
|
||||||
const p = {id: 3, data: obj}
|
const p = {id: 3, data: obj}
|
||||||
|
Reference in New Issue
Block a user