mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 23:01:29 +00:00
Index categories_id
This commit is contained in:
@@ -11,11 +11,11 @@ use sspat\ESQuerySanitizer\Sanitizer;
|
||||
class ElasticSearchSiteSearch
|
||||
{
|
||||
/**
|
||||
* @param string|array $phrases
|
||||
* @param array|string $phrases
|
||||
* @param int $limit
|
||||
* @return mixed
|
||||
*/
|
||||
public function indexSearch($phrases, int $limit)
|
||||
public function indexSearch(array|string $phrases, int $limit): mixed
|
||||
{
|
||||
$keywords = $this->sanitize($phrases);
|
||||
try {
|
||||
@@ -70,11 +70,11 @@ class ElasticSearchSiteSearch
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $searchName
|
||||
* @param array|string $searchName
|
||||
* @param int $limit
|
||||
* @return array
|
||||
*/
|
||||
public function indexSearchApi($searchName, int $limit)
|
||||
public function indexSearchApi(array|string $searchName, int $limit): array
|
||||
{
|
||||
$keywords = $this->sanitize($searchName);
|
||||
try {
|
||||
@@ -131,11 +131,11 @@ class ElasticSearchSiteSearch
|
||||
/**
|
||||
* Search function used in TV, TV API, Movies and Anime searches.
|
||||
*
|
||||
* @param string|array $name
|
||||
* @param array|string $name
|
||||
* @param int $limit
|
||||
* @return array
|
||||
*/
|
||||
public function indexSearchTMA($name, $limit)
|
||||
public function indexSearchTMA(array|string $name, int $limit): array
|
||||
{
|
||||
$keywords = $this->sanitize($name);
|
||||
try {
|
||||
@@ -190,10 +190,10 @@ class ElasticSearchSiteSearch
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $search
|
||||
* @param array|string $search
|
||||
* @return array|\Illuminate\Support\Collection
|
||||
*/
|
||||
public function predbIndexSearch($search)
|
||||
public function predbIndexSearch(array|string $search): array|\Illuminate\Support\Collection
|
||||
{
|
||||
try {
|
||||
$search = [
|
||||
@@ -253,6 +253,7 @@ class ElasticSearchSiteSearch
|
||||
'searchname' => $parameters['searchname'],
|
||||
'plainsearchname' => $searchNameDotless,
|
||||
'fromname' => $parameters['fromname'],
|
||||
'categories_id' => $parameters['categories_id'],
|
||||
'filename' => $parameters['filename'] ?? '',
|
||||
'add_date' => now()->format('Y-m-d H:i:s'),
|
||||
'post_date' => $parameters['postdate'],
|
||||
@@ -267,12 +268,12 @@ class ElasticSearchSiteSearch
|
||||
/**
|
||||
* @param int $id
|
||||
*/
|
||||
public function updateRelease(int $id)
|
||||
public function updateRelease(int $id): void
|
||||
{
|
||||
$new = Release::query()
|
||||
->where('releases.id', $id)
|
||||
->leftJoin('release_files as rf', 'releases.id', '=', 'rf.releases_id')
|
||||
->select(['releases.id', 'releases.name', 'releases.searchname', 'releases.fromname', DB::raw('IFNULL(GROUP_CONCAT(rf.name SEPARATOR " "),"") filename')])
|
||||
->select(['releases.id', 'releases.name', 'releases.searchname', 'releases.fromname', 'releases.categories_id', DB::raw('IFNULL(GROUP_CONCAT(rf.name SEPARATOR " "),"") filename')])
|
||||
->groupBy('releases.id')
|
||||
->first();
|
||||
if ($new !== null) {
|
||||
@@ -285,6 +286,7 @@ class ElasticSearchSiteSearch
|
||||
'searchname' => $new->searchname,
|
||||
'plainsearchname' => $searchNameDotless,
|
||||
'fromname' => $new->fromname,
|
||||
'categories_id' => $new->categories_id,
|
||||
'filename' => $new->filename,
|
||||
],
|
||||
'doc_as_upsert' => true,
|
||||
@@ -302,7 +304,7 @@ class ElasticSearchSiteSearch
|
||||
* @param $searchTerm
|
||||
* @return array
|
||||
*/
|
||||
public function searchPreDb($searchTerm)
|
||||
public function searchPreDb($searchTerm): array
|
||||
{
|
||||
$search = [
|
||||
'index' => 'predb',
|
||||
@@ -333,9 +335,9 @@ class ElasticSearchSiteSearch
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $parameters
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function insertPreDb($parameters)
|
||||
public function insertPreDb(array $parameters): void
|
||||
{
|
||||
$data = [
|
||||
'body' => [
|
||||
@@ -352,9 +354,9 @@ class ElasticSearchSiteSearch
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $parameters
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function updatePreDb($parameters)
|
||||
public function updatePreDb(array $parameters): void
|
||||
{
|
||||
$data = [
|
||||
'body' => [
|
||||
@@ -378,7 +380,7 @@ class ElasticSearchSiteSearch
|
||||
* @param array|string $phrases
|
||||
* @return string
|
||||
*/
|
||||
private function sanitize($phrases): string
|
||||
private function sanitize(array|string $phrases): string
|
||||
{
|
||||
if (! is_array($phrases)) {
|
||||
$wordArray = explode(' ', str_replace('.', ' ', $phrases));
|
||||
|
||||
+17
-17
@@ -19,27 +19,27 @@ class SphinxSearch
|
||||
/**
|
||||
* @var \Foolz\SphinxQL\SphinxQL
|
||||
*/
|
||||
public $sphinxQL;
|
||||
public SphinxQL $sphinxQL;
|
||||
|
||||
/**
|
||||
* @var \Foolz\SphinxQL\Drivers\Pdo\Connection
|
||||
*/
|
||||
protected $connection;
|
||||
protected Connection $connection;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Config\Repository|mixed
|
||||
*/
|
||||
protected $config;
|
||||
protected mixed $config;
|
||||
|
||||
/**
|
||||
* @var \Foolz\SphinxQL\Helper
|
||||
*/
|
||||
protected $helper;
|
||||
protected Helper $helper;
|
||||
|
||||
/**
|
||||
* @var \Blacklight\ColorCLI
|
||||
*/
|
||||
private $cli;
|
||||
private ColorCLI $cli;
|
||||
|
||||
/**
|
||||
* Establish connection to SphinxQL.
|
||||
@@ -59,19 +59,19 @@ class SphinxSearch
|
||||
/**
|
||||
* Insert release into Sphinx RT table.
|
||||
*
|
||||
* @param $parameters
|
||||
* @param array $parameters
|
||||
*
|
||||
* @throws \Foolz\SphinxQL\Exception\ConnectionException
|
||||
* @throws \Foolz\SphinxQL\Exception\DatabaseException
|
||||
* @throws \Foolz\SphinxQL\Exception\SphinxQLException
|
||||
*/
|
||||
public function insertRelease($parameters): void
|
||||
public function insertRelease(array $parameters): void
|
||||
{
|
||||
if ($this->sphinxQL !== null && $parameters['id']) {
|
||||
$this->sphinxQL
|
||||
->replace()
|
||||
->into($this->config['indexes']['releases'])
|
||||
->set(['id' => $parameters['id'], 'name' => $parameters['name'], 'searchname' => $parameters['searchname'], 'fromname' => $parameters['fromname'], 'filename' => empty($parameters['filename']) ? "''" : $parameters['filename']])
|
||||
->set(['id' => $parameters['id'], 'name' => $parameters['name'], 'searchname' => $parameters['searchname'], 'fromname' => $parameters['fromname'], 'categories_id' => $parameters['categories_id'], 'filename' => empty($parameters['filename']) ? "''" : $parameters['filename']])
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
@@ -79,13 +79,13 @@ class SphinxSearch
|
||||
/**
|
||||
* Insert release into Sphinx RT table.
|
||||
*
|
||||
* @param $parameters
|
||||
* @param array $parameters
|
||||
*
|
||||
* @throws \Foolz\SphinxQL\Exception\ConnectionException
|
||||
* @throws \Foolz\SphinxQL\Exception\DatabaseException
|
||||
* @throws \Foolz\SphinxQL\Exception\SphinxQLException
|
||||
*/
|
||||
public function insertPredb($parameters): void
|
||||
public function insertPredb(array $parameters): void
|
||||
{
|
||||
if ($this->sphinxQL !== null && $parameters['id']) {
|
||||
$this->sphinxQL
|
||||
@@ -101,7 +101,7 @@ class SphinxSearch
|
||||
*
|
||||
* @param array $identifiers ['g' => Release GUID(mandatory), 'id' => ReleaseID(optional, pass false)]
|
||||
*/
|
||||
public function deleteRelease($identifiers): void
|
||||
public function deleteRelease(array $identifiers): void
|
||||
{
|
||||
if ($identifiers['i'] === false) {
|
||||
$identifiers['i'] = Release::query()->where('guid', $identifiers['g'])->first(['id']);
|
||||
@@ -120,7 +120,7 @@ class SphinxSearch
|
||||
* @param string $string unescaped string
|
||||
* @return string Escaped string.
|
||||
*/
|
||||
public static function escapeString($string): string
|
||||
public static function escapeString(string $string): string
|
||||
{
|
||||
$from = ['\\', '(', ')', '|', '-', '!', '@', '~', '"', '&', '/', '^', '$', '=', "'"];
|
||||
$to = ['\\\\', '\(', '\)', '\|', '\-', '\!', '\@', '\~', '\"', '\&', '\/', '\^', '\$', '\=', "\'"];
|
||||
@@ -135,12 +135,12 @@ class SphinxSearch
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateRelease($releaseID): void
|
||||
public function updateRelease(int $releaseID): void
|
||||
{
|
||||
$new = Release::query()
|
||||
->where('releases.id', $releaseID)
|
||||
->leftJoin('release_files as rf', 'releases.id', '=', 'rf.releases_id')
|
||||
->select(['releases.id', 'releases.name', 'releases.searchname', 'releases.fromname', DB::raw('IFNULL(GROUP_CONCAT(rf.name SEPARATOR " "),"") filename')])
|
||||
->select(['releases.id', 'releases.name', 'releases.searchname', 'releases.fromname', 'releases.categories_id', DB::raw('IFNULL(GROUP_CONCAT(rf.name SEPARATOR " "),"") filename')])
|
||||
->groupBy('releases.id')
|
||||
->first();
|
||||
|
||||
@@ -156,7 +156,7 @@ class SphinxSearch
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updatePreDb($parameters): void
|
||||
public function updatePreDb(array $parameters): void
|
||||
{
|
||||
if (! empty($parameters)) {
|
||||
$this->insertPredb($parameters);
|
||||
@@ -169,7 +169,7 @@ class SphinxSearch
|
||||
* @param array $indexes
|
||||
* @return bool
|
||||
*/
|
||||
public function truncateRTIndex($indexes = []): bool
|
||||
public function truncateRTIndex(array $indexes = []): bool
|
||||
{
|
||||
if (empty($indexes)) {
|
||||
$this->cli->error('You need to provide index name to truncate');
|
||||
@@ -210,7 +210,7 @@ class SphinxSearch
|
||||
* @throws \Foolz\SphinxQL\Exception\DatabaseException
|
||||
* @throws \Foolz\SphinxQL\Exception\SphinxQLException
|
||||
*/
|
||||
public function searchIndexes(string $rt_index, $searchString = '', $column = [], array $searchArray = []): array
|
||||
public function searchIndexes(string $rt_index, string $searchString = '', array $column = [], array $searchArray = []): array
|
||||
{
|
||||
$query = $this->sphinxQL->select()->from($rt_index)->option('max_matches', 10000)->option('ranker', 'sph04')->option('sort_method', 'pq')->limit(0, 10000)->orderBy('id', 'desc');
|
||||
if (! empty($searchArray)) {
|
||||
|
||||
@@ -28,6 +28,7 @@ class ReleaseFactory extends Factory
|
||||
'postdate' => $this->faker->date(),
|
||||
'adddate' => $this->faker->date(),
|
||||
'guid' => $this->faker->sha1(),
|
||||
'categories_id' => '2080',
|
||||
'nzbstatus' => 1,
|
||||
'passwordstatus' => 0,
|
||||
'isrenamed' => 1,
|
||||
|
||||
@@ -35,10 +35,23 @@ $releases_index = [
|
||||
],
|
||||
],
|
||||
],
|
||||
'fromname' => ['type' => 'text'],
|
||||
'filename' => ['type' => 'text'],
|
||||
'add_date' => ['type' => 'date', 'format' => 'yyyy-MM-dd HH:mm:ss'],
|
||||
'post_date' => ['type' => 'date', 'format' => 'yyyy-MM-dd HH:mm:ss'],
|
||||
'categories_id' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'fromname' => [
|
||||
'type' => 'text',
|
||||
],
|
||||
'filename' => [
|
||||
'type' => 'text',
|
||||
],
|
||||
'add_date' => [
|
||||
'type' => 'date',
|
||||
'format' => 'yyyy-MM-dd HH:mm:ss',
|
||||
],
|
||||
'post_date' => [
|
||||
'type' => 'date',
|
||||
'format' => 'yyyy-MM-dd HH:mm:ss',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
@@ -22,7 +22,7 @@ function populate_indexes($table, $max)
|
||||
if (\in_array($table, $allowedIndexes, true)) {
|
||||
if ($table === 'releases') {
|
||||
DB::statement('SET SESSION group_concat_max_len=16384;');
|
||||
$query = 'SELECT r.id, r.name, r.searchname, r.fromname, r.adddate, r.postdate, IFNULL(GROUP_CONCAT(rf.name SEPARATOR " "),"") filename
|
||||
$query = 'SELECT r.id, r.name, r.searchname, r.fromname, r.categories_id, r.adddate, r.postdate, IFNULL(GROUP_CONCAT(rf.name SEPARATOR " "),"") filename
|
||||
FROM releases r
|
||||
LEFT JOIN release_files rf ON r.id = rf.releases_id
|
||||
WHERE r.id > %d
|
||||
@@ -84,6 +84,7 @@ function populate_indexes($table, $max)
|
||||
'searchname' => $row->searchname,
|
||||
'plainsearchname' => $searchName,
|
||||
'fromname' => $row->fromname,
|
||||
'categories_id' => $row->categories_id,
|
||||
'filename' => $row->filename,
|
||||
'add_date' => $row->adddate,
|
||||
'post_date' => $row->postdate,
|
||||
|
||||
@@ -10,7 +10,7 @@ if ($argc === 3 && is_numeric($argv[2])) {
|
||||
} elseif ($argc === 2) {
|
||||
// Checks that argv[1] exists AND that there are no other arguments, which would be an error.
|
||||
$socket = preg_replace('#^(?:unix://)?(.*)$#', '$1', $argv[1]);
|
||||
if (strpos($socket, '/') === 0) {
|
||||
if (str_starts_with($socket, '/')) {
|
||||
// Make sure the socket path is fully qualified (and using correct separator).
|
||||
$sphinxConnection = sprintf('unix://%s:', $socket);
|
||||
}
|
||||
@@ -27,6 +27,7 @@ CREATE TABLE releases_se
|
||||
name VARCHAR(255) NOT NULL DEFAULT '',
|
||||
searchname VARCHAR(255) NOT NULL DEFAULT '',
|
||||
fromname VARCHAR(255) NULL,
|
||||
categories_id INT UNSIGNED NOT NULL DEFAULT 10,
|
||||
filename VARCHAR(1000) NULL,
|
||||
INDEX(query)
|
||||
) ENGINE=SPHINX CONNECTION="%sreleases_rt"
|
||||
|
||||
@@ -45,6 +45,7 @@ index releases_rt
|
||||
rt_field = searchname
|
||||
rt_field = fromname
|
||||
rt_field = filename
|
||||
rt_field = categories_id
|
||||
rt_attr_uint = dummy
|
||||
|
||||
}
|
||||
@@ -177,7 +178,7 @@ searchd
|
||||
# client read timeout, seconds
|
||||
# optional, default is 5
|
||||
# !*: http://sphinxsearch.com/docs/current.html#conf-read-timeout
|
||||
read_timeout = 5
|
||||
network_timeout = 5
|
||||
|
||||
# request timeout, seconds
|
||||
# optional, default is 5 minutes
|
||||
@@ -278,7 +279,8 @@ searchd
|
||||
# optional, default is fork
|
||||
# !*: Do not change this.
|
||||
# !*: http://sphinxsearch.com/docs/current.html#conf-workers
|
||||
workers = threads
|
||||
# workers are deprecated in latest manticore version
|
||||
# workers = threads
|
||||
|
||||
# max threads to create for searching local parts of a distributed index
|
||||
# optional, default is 0, which means disable multi-threaded searching
|
||||
|
||||
@@ -30,7 +30,7 @@ function populate_rt($table, $max)
|
||||
$sphinx->truncateRTIndex(Arr::wrap($table));
|
||||
if ($table === 'releases_rt') {
|
||||
DB::statement('SET SESSION group_concat_max_len=16384;');
|
||||
$query = 'SELECT r.id, r.name, r.searchname, r.fromname, IFNULL(GROUP_CONCAT(rf.name SEPARATOR " "),"") filename
|
||||
$query = 'SELECT r.id, r.name, r.searchname, r.fromname, r.categories_id, IFNULL(GROUP_CONCAT(rf.name SEPARATOR " "),"") filename
|
||||
FROM releases r
|
||||
LEFT JOIN release_files rf ON r.id = rf.releases_id
|
||||
WHERE r.id > %d
|
||||
@@ -82,6 +82,7 @@ function populate_rt($table, $max)
|
||||
'name' => $row->name,
|
||||
'searchname' => $row->searchname,
|
||||
'fromname' => $row->fromname,
|
||||
'categories_id' => (string) $row->categories_id,
|
||||
'filename' => $row->filename,
|
||||
]);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user