mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Update search code to reduce number of variables used in search function
This commit is contained in:
+16
-29
@@ -2,16 +2,16 @@
|
||||
|
||||
namespace Blacklight;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Group;
|
||||
use App\Models\Release;
|
||||
use App\Models\Category;
|
||||
use App\Models\Settings;
|
||||
use Blacklight\utility\Utility;
|
||||
use Chumper\Zipper\Zipper;
|
||||
use Illuminate\Support\Arr;
|
||||
use Blacklight\utility\Utility;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* Class Releases.
|
||||
@@ -574,28 +574,25 @@ class Releases
|
||||
* Function for searching on the site (by subject, searchname or advanced).
|
||||
*
|
||||
*
|
||||
* @param $searchName
|
||||
* @param $usenetName
|
||||
* @param $posterName
|
||||
* @param $fileName
|
||||
* @param array $searchArr
|
||||
* @param $groupName
|
||||
* @param $sizeFrom
|
||||
* @param $sizeTo
|
||||
* @param $daysNew
|
||||
* @param $daysOld
|
||||
* @param int $offset
|
||||
* @param int $limit
|
||||
* @param int $offset
|
||||
* @param int $limit
|
||||
* @param string|array $orderBy
|
||||
* @param int $maxAge
|
||||
* @param array $excludedCats
|
||||
* @param string $type
|
||||
* @param array $cat
|
||||
* @param int $minSize
|
||||
* @param array $tags
|
||||
* @param int $maxAge
|
||||
* @param array $excludedCats
|
||||
* @param string $type
|
||||
* @param array $cat
|
||||
* @param int $minSize
|
||||
* @param array $tags
|
||||
*
|
||||
* @return array|\Illuminate\Database\Eloquent\Collection|mixed
|
||||
*/
|
||||
public function search($searchName, $usenetName, $posterName, $fileName, $groupName, $sizeFrom, $sizeTo, $daysNew, $daysOld, $offset = 0, $limit = 1000, $orderBy = '', $maxAge = -1, array $excludedCats = [], $type = 'basic', array $cat = [-1], $minSize = 0, array $tags = [])
|
||||
public function search($searchArr, $groupName, $sizeFrom, $sizeTo, $daysNew, $daysOld, $offset = 0, $limit = 1000, $orderBy = '', $maxAge = -1, array $excludedCats = [], $type = 'basic', array $cat = [-1], $minSize = 0, array $tags = [])
|
||||
{
|
||||
$sizeRange = [
|
||||
1 => 1,
|
||||
@@ -618,19 +615,9 @@ class Releases
|
||||
$orderBy = $this->getBrowseOrder($orderBy);
|
||||
}
|
||||
|
||||
$searchFields = [];
|
||||
if ($searchName !== -1) {
|
||||
$searchFields['searchname'] = $searchName;
|
||||
}
|
||||
if ($usenetName !== -1) {
|
||||
$searchFields['name'] = $usenetName;
|
||||
}
|
||||
if ($posterName !== -1) {
|
||||
$searchFields['fromname'] = $posterName;
|
||||
}
|
||||
if ($fileName !== -1) {
|
||||
$searchFields['filename'] = $fileName;
|
||||
}
|
||||
$searchFields = Arr::where($searchArr, function ($value) {
|
||||
return $value !== -1;
|
||||
});
|
||||
|
||||
$results = $this->sphinxSearch->searchIndexes('releases_rt', '', [], $searchFields);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
2019-02-04 DariusIII
|
||||
* Chg: Update search code to reduce number of variables used in search function
|
||||
* Chg: Remove nfo and comments options from search function (searching for releases that are commented or have nfo)
|
||||
* Chg: Remove SphinxSearch rules description as those do not apply anymore (not using raw queries but SphinxQL query builder)
|
||||
* Chg: Update spatie/laravel-permission (2.30.0 => 2.31.0)
|
||||
|
||||
@@ -119,13 +119,16 @@ class ApiController extends BasePageController
|
||||
UserRequest::addApiRequest($apiKey, $request->getRequestUri());
|
||||
$categoryID = $api->categoryID();
|
||||
$limit = $api->limit();
|
||||
$searchArr = [
|
||||
'searchname' => $request->input('q') ?? -1,
|
||||
'name' => -1,
|
||||
'fromname' => -1,
|
||||
'filename' => -1,
|
||||
];
|
||||
|
||||
if ($request->has('q')) {
|
||||
$relData = $releases->search(
|
||||
$request->input('q'),
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
$searchArr,
|
||||
$groupName,
|
||||
-1,
|
||||
-1,
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Group;
|
||||
use App\Models\Category;
|
||||
use App\Models\Group;
|
||||
use Blacklight\Releases;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -42,15 +42,15 @@ class SearchController extends BasePageController
|
||||
);
|
||||
|
||||
if ($searchType === 'basic' && ! $request->has('searchadvr') && ($request->has('id') || $request->has('subject'))) {
|
||||
$searchString = '';
|
||||
$searchString = [];
|
||||
switch (true) {
|
||||
case $request->has('subject'):
|
||||
$searchString = (string) $request->input('subject');
|
||||
$this->smarty->assign('subject', $searchString);
|
||||
$searchString['searchname'] = (string) $request->input('subject');
|
||||
$this->smarty->assign('subject', $searchString['searchname']);
|
||||
break;
|
||||
case $request->has('id'):
|
||||
$searchString = (string) $request->input('id');
|
||||
$this->smarty->assign('search', $searchString);
|
||||
$searchString['searchname'] = (string) $request->input('id');
|
||||
$this->smarty->assign('search', $searchString['searchname']);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class SearchController extends BasePageController
|
||||
foreach ($releases->getBrowseOrdering() as $orderType) {
|
||||
$this->smarty->assign(
|
||||
'orderby'.$orderType,
|
||||
WWW_TOP.'/search?id='.htmlentities($searchString, ENT_QUOTES | ENT_HTML5).'&t='.implode(',', $categoryID).'&ob='.$orderType
|
||||
WWW_TOP.'/search?id='.htmlentities($searchString['searchname'], ENT_QUOTES | ENT_HTML5).'&t='.implode(',', $categoryID).'&ob='.$orderType
|
||||
);
|
||||
}
|
||||
|
||||
@@ -77,9 +77,6 @@ class SearchController extends BasePageController
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
$offset,
|
||||
config('nntmux.items_per_page'),
|
||||
$orderBy,
|
||||
@@ -102,10 +99,18 @@ class SearchController extends BasePageController
|
||||
}
|
||||
|
||||
$searchVars = [
|
||||
'searchadvr' => '', 'searchadvsubject' => '', 'searchadvposter' => '',
|
||||
'searchadvfilename' => '', 'searchadvdaysnew' => '', 'searchadvdaysold' => '',
|
||||
'searchadvgroups' => '', 'searchadvcat' => '', 'searchadvsizefrom' => '',
|
||||
'searchadvsizeto' => '', 'searchadvhasnfo' => '', 'searchadvhascomments' => '',
|
||||
'searchadvr' => '',
|
||||
'searchadvsubject' => '',
|
||||
'searchadvposter' => '',
|
||||
'searchadvfilename' => '',
|
||||
'searchadvdaysnew' => '',
|
||||
'searchadvdaysold' => '',
|
||||
'searchadvgroups' => '',
|
||||
'searchadvcat' => '',
|
||||
'searchadvsizefrom' => '',
|
||||
'searchadvsizeto' => '',
|
||||
'searchadvhasnfo' => '',
|
||||
'searchadvhascomments' => '',
|
||||
];
|
||||
|
||||
foreach ($searchVars as $searchVarKey => $searchVar) {
|
||||
@@ -134,11 +139,15 @@ class SearchController extends BasePageController
|
||||
);
|
||||
}
|
||||
|
||||
$searchArr = [
|
||||
'searchname' => $searchVars['searchadvr'] === '' ? -1 : $searchVars['searchadvr'],
|
||||
'name' => $searchVars['searchadvsubject'] === '' ? -1 : $searchVars['searchadvsubject'],
|
||||
'fromname' => $searchVars['searchadvposter'] === '' ? -1 : $searchVars['searchadvposter'],
|
||||
'filename' => $searchVars['searchadvfilename'] === '' ? -1 : $searchVars['searchadvfilename'],
|
||||
];
|
||||
|
||||
$rslt = $releases->search(
|
||||
($searchVars['searchadvr'] === '' ? -1 : $searchVars['searchadvr']),
|
||||
($searchVars['searchadvsubject'] === '' ? -1 : $searchVars['searchadvsubject']),
|
||||
($searchVars['searchadvposter'] === '' ? -1 : $searchVars['searchadvposter']),
|
||||
($searchVars['searchadvfilename'] === '' ? -1 : $searchVars['searchadvfilename']),
|
||||
$searchArr,
|
||||
$searchVars['searchadvgroups'],
|
||||
$searchVars['searchadvsizefrom'],
|
||||
$searchVars['searchadvsizeto'],
|
||||
|
||||
@@ -50,37 +50,37 @@
|
||||
<tr>
|
||||
<th><label for="searchadvr">Release Name:</label></th>
|
||||
<td><input class="searchadv" id="searchadvr" name="searchadvr"
|
||||
value="{$searchadvr|escape:'html'}"
|
||||
value="{$searchadvr|escape:'htmlall'}"
|
||||
type="text"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="searchadvsubject">Usenet Name:</label></th>
|
||||
<td><input class="searchadv" id="searchadvsubject" name="searchadvsubject"
|
||||
value="{$searchadvsubject|escape:'html'}" type="text"></td>
|
||||
value="{$searchadvsubject|escape:'htmlall'}" type="text"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="searchadvposter">Poster:</label></th>
|
||||
<td><input class="searchadv" id="searchadvposter" name="searchadvposter"
|
||||
value="{$searchadvposter|escape:'html'}" type="text"></td>
|
||||
value="{$searchadvposter|escape:'htmlall'}" type="text"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="searchadvfilename">Filename:</label></th>
|
||||
<td><input class="searchadv" id="searchadvfilename" name="searchadvfilename"
|
||||
value="{$searchadvfilename|escape:'html'}" type="text"/></td>
|
||||
value="{$searchadvfilename|escape:'htmlall'}" type="text"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr>
|
||||
<th><label for="searchadvdaysnew">Min age(days):</label></th>
|
||||
<td>
|
||||
<input class="searchdaysinput" id="searchadvdaysnew" name="searchadvdaysnew"
|
||||
value="{$searchadvdaysnew|escape:'html'}" type="text">
|
||||
value="{$searchadvdaysnew|escape:'htmlall'}" type="text">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="searchadvdaysold">Max age(days):</label></th>
|
||||
<td>
|
||||
<input class="searchdaysinput" id="searchadvdaysold" name="searchadvdaysold"
|
||||
value="{$searchadvdaysold|escape:'html'}" type="text">
|
||||
value="{$searchadvdaysold|escape:'htmlall'}" type="text">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
Reference in New Issue
Block a user