Update manticoresearch searchIndexes function to return proper data

This commit is contained in:
DariusIII
2023-04-06 12:19:05 +02:00
parent 8357d6708f
commit 2368498d14
5 changed files with 39 additions and 6 deletions
+15 -4
View File
@@ -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 [];
}
}
+1 -1
View File
@@ -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'));
}
}
+18
View File
@@ -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)) {
+1 -1
View File
@@ -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);
}
+4
View File
@@ -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)) {