From 2368498d14289c40f68a2bce123631efdf31c265 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Thu, 6 Apr 2023 12:19:05 +0200 Subject: [PATCH] Update manticoresearch searchIndexes function to return proper data --- Blacklight/ManticoreSearch.php | 19 +++++++++++++++---- Blacklight/NameFixer.php | 2 +- Blacklight/Releases.php | 18 ++++++++++++++++++ app/Models/Predb.php | 2 +- app/Models/Release.php | 4 ++++ 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Blacklight/ManticoreSearch.php b/Blacklight/ManticoreSearch.php index fb347b3db..8020d02e2 100644 --- a/Blacklight/ManticoreSearch.php +++ b/Blacklight/ManticoreSearch.php @@ -3,6 +3,7 @@ namespace Blacklight; use App\Models\Release; +use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; use Manticoresearch\Client; use Manticoresearch\Exceptions\ResponseException; @@ -194,7 +195,8 @@ class ManticoreSearch */ public function searchIndexes(string $rt_index, string $searchString = '', array $column = [], array $searchArray = []): array { - $result = []; + $resultId = []; + $resultData = []; $query = $this->search->setIndex($rt_index)->maxMatches(10000)->option('ranker', 'sph04')->option('sort_method', 'pq')->limit(10000)->sort('id', 'desc')->stripBadUtf8(true)->trackScores(true); if (! empty($searchArray)) { foreach ($searchArray as $key => $value) { @@ -210,17 +212,26 @@ class ManticoreSearch $results = $query->get(); foreach ($results as $doc) { if ($rt_index === 'releases_rt') { - $result[] = $doc->getId(); + $resultId[] = [ + 'id' => $doc->getId(), + ]; } else { - $result[] = $doc->getData(); + $resultId[] = [ + 'id' => $doc->getId(), + ]; } + $resultData[] = [ + 'data' => $doc->getData(), + ]; - return $result; + return array_merge(Arr::get($resultId, '0'), Arr::get($resultData, '0.data')); } } catch (ResponseException $exception) { return []; } catch (RuntimeException $exception) { return []; } + + return []; } } diff --git a/Blacklight/NameFixer.php b/Blacklight/NameFixer.php index 3d95fbf9f..3ca3f8fe3 100755 --- a/Blacklight/NameFixer.php +++ b/Blacklight/NameFixer.php @@ -1097,7 +1097,7 @@ class NameFixer if (\strlen($preTitle) >= 15 && preg_match(self::PREDB_REGEX, $preTitle)) { $titleMatch = $this->manticore->searchIndexes('releases_rt', $preTitle, ['name', 'searchname', 'filename']); if (! empty($titleMatch)) { - $join = implode(',', Arr::pluck($titleMatch, 'id')); + $join = implode(',', Arr::get($titleMatch, 'id')); } } diff --git a/Blacklight/Releases.php b/Blacklight/Releases.php index 73a81696b..42b5954ca 100644 --- a/Blacklight/Releases.php +++ b/Blacklight/Releases.php @@ -465,6 +465,9 @@ class Releases extends Release $searchResult = $this->elasticSearch->indexSearch($phrases, $limit); } else { $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', '', [], $searchFields); + if (! empty($searchResult)) { + $searchResult = Arr::wrap(Arr::get($searchResult, 'id')); + } } if (empty($searchResult)) { @@ -553,6 +556,9 @@ class Releases extends Release $searchResult = $this->elasticSearch->indexSearchApi($searchName, $limit); } else { $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', $searchName, ['searchname']); + if (! empty($searchResult)) { + $searchResult = Arr::wrap(Arr::get($searchResult, 'id')); + } } } @@ -684,6 +690,9 @@ class Releases extends Release $searchResult = $this->elasticSearch->indexSearchTMA($name, $limit); } else { $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', $name, ['searchname']); + if (! empty($searchResult)) { + $searchResult = Arr::wrap(Arr::get($searchResult, 'id')); + } } if (empty($searchResult)) { @@ -816,6 +825,9 @@ class Releases extends Release $searchResult = $this->elasticSearch->indexSearchTMA($name, $limit); } else { $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', $name, ['searchname']); + if (! empty($searchResult)) { + $searchResult = Arr::wrap(Arr::get($searchResult, 'id')); + } } if (empty($searchResult)) { @@ -888,6 +900,9 @@ class Releases extends Release $searchResult = $this->elasticSearch->indexSearchTMA($name, $limit); } else { $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', $name, ['searchname']); + if (! empty($searchResult)) { + $searchResult = Arr::wrap(Arr::get($searchResult, 'id')); + } } if (empty($searchResult)) { @@ -957,6 +972,9 @@ class Releases extends Release $searchResult = $this->elasticSearch->indexSearchTMA($name, $limit); } else { $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', $name, ['searchname']); + if (! empty($searchResult)) { + $searchResult = Arr::wrap(Arr::get($searchResult, 'id')); + } } if (empty($searchResult)) { diff --git a/app/Models/Predb.php b/app/Models/Predb.php index c157e40b1..4937aa6e6 100644 --- a/app/Models/Predb.php +++ b/app/Models/Predb.php @@ -200,7 +200,7 @@ class Predb extends Model $ids = (new ElasticSearchSiteSearch())->predbIndexSearch($search); } else { $manticore = new ManticoreSearch(); - $ids = Arr::pluck($manticore->searchIndexes('predb_rt', $search, ['title']), 'id'); + $ids = Arr::get($manticore->searchIndexes('predb_rt', $search, ['title']), 'id'); } $sql->whereIn('predb.id', $ids); } diff --git a/app/Models/Release.php b/app/Models/Release.php index 19fdcf9ef..5f2e1e908 100644 --- a/app/Models/Release.php +++ b/app/Models/Release.php @@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; +use Illuminate\Support\Arr; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; @@ -535,6 +536,9 @@ class Release extends Model $searchResult = (new ElasticSearchSiteSearch())->indexSearch($similar[1], 10); } else { $searchResult = (new ManticoreSearch())->searchIndexes('releases_rt', $similar[1]); + if (! empty($searchResult)) { + $searchResult = Arr::wrap(Arr::get($searchResult, 'id')); + } } if (empty($searchResult)) {