diff --git a/app/Services/Releases/ReleaseSearchService.php b/app/Services/Releases/ReleaseSearchService.php index cb290d324..586c07224 100644 --- a/app/Services/Releases/ReleaseSearchService.php +++ b/app/Services/Releases/ReleaseSearchService.php @@ -168,8 +168,8 @@ class ReleaseSearchService } } - // Fall back to MySQL if both Elasticsearch and Manticore failed - if (empty($searchResult)) { + // Fall back to MySQL if both Elasticsearch and Manticore failed (only if enabled) + if (empty($searchResult) && config('nntmux.mysql_search_fallback', false) === true) { if (config('app.debug')) { Log::debug('apiSearch: Falling back to MySQL search'); } @@ -380,8 +380,8 @@ class ReleaseSearchService } } - // Fall back to MySQL if both Elasticsearch and Manticore failed - if (empty($searchResult)) { + // Fall back to MySQL if both Elasticsearch and Manticore failed (only if enabled) + if (empty($searchResult) && config('nntmux.mysql_search_fallback', false) === true) { $searchResult = $this->performMySQLSearch(['searchname' => $searchName], $limit); } @@ -529,8 +529,8 @@ class ReleaseSearchService } } - // Fall back to MySQL if both Elasticsearch and Manticore failed - if (empty($searchResult)) { + // Fall back to MySQL if both Elasticsearch and Manticore failed (only if enabled) + if (empty($searchResult) && config('nntmux.mysql_search_fallback', false) === true) { $searchResult = $this->performMySQLSearch(['searchname' => $name], $limit); } @@ -601,8 +601,8 @@ class ReleaseSearchService } } - // Fall back to MySQL if both Elasticsearch and Manticore failed - if (empty($searchResult)) { + // Fall back to MySQL if both Elasticsearch and Manticore failed (only if enabled) + if (empty($searchResult) && config('nntmux.mysql_search_fallback', false) === true) { $searchResult = $this->performMySQLSearch(['searchname' => $name], $limit); } @@ -679,8 +679,8 @@ class ReleaseSearchService } } - // Fall back to MySQL if both Elasticsearch and Manticore failed - if (empty($searchResult)) { + // Fall back to MySQL if both Elasticsearch and Manticore failed (only if enabled) + if (empty($searchResult) && config('nntmux.mysql_search_fallback', false) === true) { $searchResult = $this->performMySQLSearch(['searchname' => $name], $limit); } @@ -874,12 +874,16 @@ class ReleaseSearchService return Arr::wrap(Arr::get($searchResult, 'id')); } - // Fallback to MySQL LIKE search when both Elasticsearch and Manticore are unavailable - if (config('app.debug')) { - Log::debug('performIndexSearch: Falling back to MySQL search'); + // Fallback to MySQL LIKE search when both Elasticsearch and Manticore are unavailable (only if enabled) + if (config('nntmux.mysql_search_fallback', false) === true) { + if (config('app.debug')) { + Log::debug('performIndexSearch: Falling back to MySQL search'); + } + + return $this->performMySQLSearch($searchFields, $limit); } - return $this->performMySQLSearch($searchFields, $limit); + return []; } /** diff --git a/config/nntmux.php b/config/nntmux.php index 7d1fbfd66..df4b74677 100644 --- a/config/nntmux.php +++ b/config/nntmux.php @@ -20,6 +20,7 @@ return [ 'purge_inactive_users' => env('PURGE_INACTIVE_USERS', false), 'purge_inactive_users_days' => env('PURGE_INACTIVE_USERS_DAYS', 180), 'elasticsearch_enabled' => env('ELASTICSEARCH_ENABLED', false), + 'mysql_search_fallback' => env('MYSQL_SEARCH_FALLBACK', false), // Disable MySQL LIKE fallback when Manticore/Elasticsearch return no results 'btcpay_webhook_secret' => env('BTCPAY_SECRET'), 'tmp_unrar_path' => env('TEMP_UNRAR_PATH', storage_path('tmp/unrar/')), 'tmp_unzip_path' => env('TEMP_UNZIP_PATH', storage_path('tmp/unzip/')),