поиск среди остаточных результатов, отображения списка файлов

This commit is contained in:
Alexey Kasyanchuk 2017-01-23 22:13:26 +03:00
parent e2611706b5
commit ccfd5f4734
4 changed files with 129 additions and 14 deletions

View File

@ -247,6 +247,7 @@ io.on('connection', function(socket)
const index = navigation.index || 0;
const limit = navigation.limit || 10;
let search = {};
//socketMysql.query('SELECT * FROM `torrents` WHERE `name` like \'%' + text + '%\' LIMIT ?,?', [index, limit], function (error, rows, fields) {
sphinx.query('SELECT * FROM `torrents_index`,`torrents_index_delta` WHERE MATCH(?) ' + (safeSearch ? "and contentcategory != 'xxx'" : '') + ' LIMIT ?,?', [text, index, limit], function (error, rows, fields) {
if(!rows) {
callback(undefined)
@ -276,14 +277,18 @@ 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 files.path like \'%' + text + '%\' LIMIT ?,?', [index, limit], function (error, rows, fields) {
sphinx.query('SELECT * FROM `files_index`,`files_index_delta` WHERE MATCH(?) ' + (safeSearch ? "and contentcategory != 'xxx'" : '') + ' LIMIT ?,?', [text, index, limit], function (error, rows, fields) {
if(!rows) {
callback(undefined)
return;
}
rows.forEach((row) => {
search[row.hash] = baseRowData(row);
search[row.hash].path = row.path;
if(!(row.hash in search))
search[row.hash] = baseRowData(row);
if(!search[row.hash].path)
search[row.hash].path = []
search[row.hash].path.push(row.path);
});
callback(Object.keys(search).map(function(key) {
return search[key];

View File

@ -3,22 +3,24 @@ import React, { Component } from 'react';
import TorrentLine from './torrent'
import {List, ListItem} from 'material-ui/List';
import Subheader from 'material-ui/Subheader';
import Divider from 'material-ui/Divider';
export default class SearchResults extends Component {
render() {
return (
<List style={{minWidth: '20em'}}>
{
this.props.results && this.props.results.length > 0
(this.props.torrentsSearchResults && this.props.torrentsSearchResults.length > 0)
|| (this.props.filesSearchResults && this.props.filesSearchResults.length > 0)
?
<Subheader inset={true}>Search results</Subheader>
:
null
}
{
this.props.results && this.props.results.length > 0
this.props.torrentsSearchResults && this.props.torrentsSearchResults.length > 0
?
this.props.results.map((torrent, index) =>{
this.props.torrentsSearchResults.map((torrent, index) =>{
return(
<TorrentLine torrent={torrent} key={index} />
);
@ -26,6 +28,43 @@ export default class SearchResults extends Component {
:
null
}
{
this.props.moreTorrentsEnabled
?
<div>
<ListItem innerDivStyle={{textAlign: 'center', padding: '1em'}} primaryText={<span>More Torrents</span>} onClick={() => {
if(this.props.onMoreTorrents)
this.props.onMoreTorrents();
}} />
<Divider />
</div>
:
null
}
{
this.props.filesSearchResults && this.props.filesSearchResults.length > 0
?
this.props.filesSearchResults.map((torrent, index) =>{
return(
<TorrentLine torrent={torrent} key={index} />
);
})
:
null
}
{
this.props.moreFilesEnabled
?
<div>
<ListItem innerDivStyle={{textAlign: 'center', padding: '1em'}} primaryText='More Files' onClick={() => {
if(this.props.onMoreFiles)
this.props.onMoreFiles();
}} />
<Divider />
</div>
:
null
}
</List>
);
}

View File

@ -20,17 +20,27 @@ export default class Search extends Component {
safeSearchText: 'safe search enabled',
safeSearchColor: 'rgb(0, 188, 212)'
}
this.searchLimit = 10
}
search() {
this.setState({
searchingIndicator: true
});
this.searchData = [];
this.searchTorrents = [];
this.moreSearchTorrents = true;
this.searchFiles = [];
this.moreSearchFiles = true;
this.currentSearch = this.searchValue;
let queries = 2;
window.torrentSocket.emit('searchTorrent', this.searchValue, {limit: 10, safeSearch: !this.notSafeSearch}, window.customLoader((torrents) => {
window.torrentSocket.emit('searchTorrent', this.searchValue, {
limit: this.searchLimit,
safeSearch: !this.notSafeSearch
}, window.customLoader((torrents) => {
if(torrents) {
this.searchData = this.searchData.concat(torrents);
this.searchTorrents = torrents;
if(torrents.length != this.searchLimit)
this.moreSearchTorrents = false;
}
if(--queries == 0) {
this.setState({
@ -40,9 +50,19 @@ export default class Search extends Component {
this.forceUpdate();
}
}));
window.torrentSocket.emit('searchFiles', this.searchValue, {limit: 10, safeSearch: !this.notSafeSearch}, window.customLoader((torrents) => {
window.torrentSocket.emit('searchFiles', this.searchValue, {
limit: this.searchLimit,
safeSearch: !this.notSafeSearch
}, window.customLoader((torrents) => {
if(torrents) {
this.searchData = this.searchData.concat(torrents);
this.searchFiles = torrents;
let files = 0;
torrents.forEach((torrent) => {
if(torrent.path && torrent.path.length > 0)
files += torrent.path.length
});
if(files != this.searchLimit)
this.moreSearchFiles = false;
}
if(--queries == 0) {
this.setState({
@ -53,6 +73,47 @@ export default class Search extends Component {
}
}));
}
moreTorrents() {
window.torrentSocket.emit('searchTorrent', this.currentSearch, {
index: this.searchTorrents.length,
limit: this.searchLimit,
safeSearch: !this.notSafeSearch
}, window.customLoader((torrents) => {
if(torrents) {
this.searchTorrents = this.searchTorrents.concat(torrents);
if(torrents.length != this.searchLimit)
this.moreSearchTorrents = false;
this.forceUpdate();
}
}));
}
moreFiles() {
let index = 0;
this.searchFiles.forEach((torrent) => {
if(torrent.path && torrent.path.length > 0)
index += torrent.path.length;
});
window.torrentSocket.emit('searchFiles', this.currentSearch, {
index: index,
limit: this.searchLimit,
safeSearch: !this.notSafeSearch
}, window.customLoader((torrents) => {
if(torrents) {
this.searchFiles = this.searchFiles.concat(torrents);
let files = 0;
torrents.forEach((torrent) => {
if(torrent.path && torrent.path.length > 0)
files += torrent.path.length
});
if(files != this.searchLimit)
this.moreSearchFiles = false;
this.forceUpdate();
}
}));
}
componentDidMount() {
this.newStatisticFunc = (statistic) => {
if(statistic) {
@ -139,7 +200,15 @@ export default class Search extends Component {
:
null
}
<SearchResults results={this.searchData} />
<SearchResults
torrentsSearchResults={this.searchTorrents}
filesSearchResults={this.searchFiles}
moreTorrentsEnabled={this.moreSearchTorrents}
moreFilesEnabled={this.moreSearchFiles}
onMoreTorrents={() => this.moreTorrents()}
onMoreFiles={() => this.moreFiles()}
/>
</div>
);
}

View File

@ -27,7 +27,7 @@ return (
if(node)
node.onclick = () => { return false }
}}>
<div className='column' style={{height: 'auto', whiteSpace: 'normal'}}>
<div className='column' style={{height: 'auto', whiteSpace: 'normal', paddingTop: '0.30em'}}>
<div>
{
formatBytes(torrent.size, 1) + ' (' + torrent.files + ' files)'
@ -36,14 +36,16 @@ return (
{
torrent.path && torrent.path.length > 0
?
<div className='break-word fs0-75' style={{paddingTop: '0.3em'}}>{torrent.path}</div>
torrent.path.map((path, index) => {
return <div key={index} className='break-word fs0-75' style={{paddingTop: '0.3em', marginLeft: '0.6em'}}>{path}</div>
})
:
null
}
{
torrent.seeders || torrent.leechers || torrent.completed
?
<div className='break-word fs0-85' style={{paddingTop: '0.3em'}}>
<div className='break-word fs0-85' style={{paddingTop: '0.35em'}}>
<span style={{color: (torrent.seeders > 0 ? '#00C853' : 'grey')}}>{torrent.seeders} seeders</span>
<span style={{color: (torrent.leechers > 0 ? '#AA00FF' : 'grey'), marginLeft: '12px'}}>{torrent.leechers} leechers</span>
<span style={{color: (torrent.completed > 0 ? '#FF6D00' : 'grey'), marginLeft: '12px'}}>{torrent.completed} completed</span>