diff --git a/README-EN.md b/README-EN.md index 6fb46438..37b46ad6 100644 --- a/README-EN.md +++ b/README-EN.md @@ -17,6 +17,7 @@ Complete PT website building solution. Based on NexusPHP + Laravel + Filament. - Medal - Props - Custom tags +- Third-party full-text search - SeedBox rule - Forum - Complain diff --git a/README.md b/README.md index 4f7d953a..582c678c 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ - 勋章 - 道具 - 自定义标签 +- 第三方全文搜索 - 盒子规则 - 论坛 - 申诉 diff --git a/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php b/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php index ba9cca92..f2407a57 100644 --- a/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php +++ b/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php @@ -146,6 +146,12 @@ class EditSetting extends Page implements Forms\Contracts\HasForms ->label(__('label.setting.system.meilisearch_enabled')) ->helperText(__('label.setting.system.meilisearch_enabled_help')) , + Forms\Components\Radio::make('system.meilisearch_search_description') + ->options(self::$yesOrNo) + ->inline(true) + ->label(__('label.setting.system.meilisearch_search_description')) + ->helperText(__('label.setting.system.meilisearch_search_description_help')) + , ])->columns(2); $tabs = apply_filter('nexus_setting_tabs', $tabs); diff --git a/app/Repositories/MeiliSearchRepository.php b/app/Repositories/MeiliSearchRepository.php index 1c419162..16fa5e3c 100644 --- a/app/Repositories/MeiliSearchRepository.php +++ b/app/Repositories/MeiliSearchRepository.php @@ -65,8 +65,6 @@ class MeiliSearchRepository extends BaseRepository '9' => 'owner', ]; - private static array $searchableAttributes = ["name", "small_descr", "descr", "url"]; - private static array $filterableAttributes = [ "id", "category", "source", "medium", "codec", "standard", "processing", "team", "audiocodec", "owner", "sp_state", "visible", "banned", "approval_status", "size", "leechers", "seeders", "times_completed", "added", @@ -157,7 +155,7 @@ class MeiliSearchRepository extends BaseRepository $settings = [ "distinctAttribute" => "id", "displayedAttributes" => $this->getRequiredFields(), - "searchableAttributes" => self::$searchableAttributes, + "searchableAttributes" => $this->getSearchableAttributes(), "filterableAttributes" => self::$filterableAttributes, "sortableAttributes" => self::$sortableAttributes, "rankingRules" => [ @@ -178,7 +176,7 @@ class MeiliSearchRepository extends BaseRepository public function getRequiredFields(): array { return array_values(array_unique(array_merge( - self::$filterableAttributes, self::$searchableAttributes, self::$sortableAttributes + self::$filterableAttributes, self::$sortableAttributes, $this->getSearchableAttributes() ))); } @@ -554,6 +552,15 @@ class MeiliSearchRepository extends BaseRepository return ['*']; } + private function getSearchableAttributes(): array + { + $attributes = ["name", "small_descr", "url"]; + if (Setting::get("system.meilisearch_search_description") == 'yes') { + $attributes[] = "descr"; + } + return $attributes; + } + diff --git a/app/Repositories/ToolRepository.php b/app/Repositories/ToolRepository.php index 47d2aefa..b1921ade 100644 --- a/app/Repositories/ToolRepository.php +++ b/app/Repositories/ToolRepository.php @@ -439,4 +439,55 @@ class ToolRepository extends BaseRepository return $this->generateUniqueInviteHash($hashArr, $total, $total - count($hashArr), ++$deep); } + + public function removeDuplicateSnatch() + { + $size = 2000; + $stickyPromotionParticipatorsTable = 'sticky_promotion_participators'; + $stickyPromotionExists = NexusDB::hasTable($stickyPromotionParticipatorsTable); + while (true) { + $snatchRes = NexusDB::select("select userid, torrentid, group_concat(id) as ids from snatched group by userid, torrentid having(count(*)) > 1 limit $size"); + if (empty($snatchRes)) { + break; + } + do_log("[DELETE_DUPLICATED_SNATCH], count: " . count($snatchRes)); + foreach ($snatchRes as $snatchRow) { + $torrentId = $snatchRow['torrentid']; + $userId = $snatchRow['userid']; + $idArr = explode(',', $snatchRow['ids']); + sort($idArr, SORT_NUMERIC); + $remainId = array_pop($idArr); + $delIdStr = implode(',', $idArr); + do_log("[DELETE_DUPLICATED_SNATCH], torrent: $torrentId, user: $userId, snatchIdStr: $delIdStr"); + NexusDB::statement("delete from snatched where id in ($delIdStr)"); + NexusDB::statement("update claims set snatched_id = $remainId where torrent_id = $torrentId and uid = $userId"); + NexusDB::statement("update hit_and_runs set snatched_id = $remainId where torrent_id = $torrentId and uid = $userId"); + if ($stickyPromotionExists) { + NexusDB::statement("update $stickyPromotionParticipatorsTable set snatched_id = $remainId where torrent_id = $torrentId and uid = $userId"); + } + } + } + } + + public function removeDuplicatePeer() + { + $size = 2000; + while (true) { + $results = NexusDB::select("select torrent, peer_id, userid, group_concat(id) as ids from peers group by torrent, peer_id, userid having(count(*)) > 1 limit $size"); + if (empty($results)) { + break; + } + do_log("[DELETE_DUPLICATED_PEERS], count: " . count($results)); + foreach ($results as $row) { + $torrentId = $row['torrent']; + $userId = $row['userid']; + $idArr = explode(',', $row['ids']); + sort($idArr, SORT_NUMERIC); + $remainId = array_pop($idArr); + $delIdStr = implode(',', $idArr); + do_log("[DELETE_DUPLICATED_PEERS], torrent: $torrentId, user: $userId, snatchIdStr: $delIdStr"); + NexusDB::statement("delete from peers where id in ($delIdStr)"); + } + } + } } diff --git a/app/Repositories/TorrentRepository.php b/app/Repositories/TorrentRepository.php index ae7363e3..7f74182c 100644 --- a/app/Repositories/TorrentRepository.php +++ b/app/Repositories/TorrentRepository.php @@ -703,34 +703,7 @@ HTML; return $input; } - public function removeDuplicateSnatch() - { - $size = 2000; - $stickyPromotionParticipatorsTable = 'sticky_promotion_participators'; - $stickyPromotionExists = NexusDB::hasTable($stickyPromotionParticipatorsTable); - while (true) { - $snatchRes = NexusDB::select("select userid, torrentid, group_concat(id) as ids from snatched group by userid, torrentid having(count(*)) > 1 limit $size"); - if (empty($snatchRes)) { - break; - } - do_log("[DELETE_DUPLICATED_SNATCH], count: " . count($snatchRes)); - foreach ($snatchRes as $snatchRow) { - $torrentId = $snatchRow['torrentid']; - $userId = $snatchRow['userid']; - $idArr = explode(',', $snatchRow['ids']); - sort($idArr, SORT_NUMERIC); - $remainId = array_pop($idArr); - $delIdStr = implode(',', $idArr); - do_log("[DELETE_DUPLICATED_SNATCH], torrent: $torrentId, user: $userId, snatchIdStr: $delIdStr"); - NexusDB::statement("delete from snatched where id in ($delIdStr)"); - NexusDB::statement("update claims set snatched_id = $remainId where torrent_id = $torrentId and uid = $userId"); - NexusDB::statement("update hit_and_runs set snatched_id = $remainId where torrent_id = $torrentId and uid = $userId"); - if ($stickyPromotionExists) { - NexusDB::statement("update $stickyPromotionParticipatorsTable set snatched_id = $remainId where torrent_id = $torrentId and uid = $userId"); - } - } - } - } + public function getPaidIcon(array $torrentInfo, $size = 16, $verticalAlign = 'sub') { diff --git a/include/constants.php b/include/constants.php index 7250549e..ff040b91 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ isSnatchedTableTorrentUserUnique()) { - $torrentRep = new TorrentRepository(); - $torrentRep->removeDuplicateSnatch(); + $toolRep->removeDuplicateSnatch(); $this->runMigrate('database/migrations/2023_03_29_021950_handle_snatched_user_torrent_unique.php'); $this->doLog("removeDuplicateSnatch and migrate 2023_03_29_021950_handle_snatched_user_torrent_unique"); } + if (!NexusDB::hasIndex("peers", "unique_torrent_peer_user")) { + $toolRep->removeDuplicatePeer(); + $this->runMigrate('database/migrations/2023_04_01_005409_add_unique_torrent_peer_user_to_peers_table.php'); + $this->doLog("removeDuplicatePeer and migrate 2023_04_01_005409_add_unique_torrent_peer_user_to_peers_table"); + } + + } public function runExtraMigrate() diff --git a/nexus/Install/settings.default.php b/nexus/Install/settings.default.php index 51aca458..ff49c364 100644 --- a/nexus/Install/settings.default.php +++ b/nexus/Install/settings.default.php @@ -443,5 +443,7 @@ return array ( 'maximum_number_of_medals_can_be_worn' => 3, 'cookie_valid_days' => 365, 'maximum_upload_speed' => 8000, + 'meilisearch_enabled' => 'no', + 'meilisearch_search_description' => 'no', ], ); diff --git a/resources/lang/en/label.php b/resources/lang/en/label.php index 2efcf48d..5797ef50 100644 --- a/resources/lang/en/label.php +++ b/resources/lang/en/label.php @@ -95,6 +95,8 @@ return [ 'maximum_upload_speed_help' => 'A single torrent upload speed exceeding this value is instantly disabled for the account, in Mbps. For example: 100 Mbps = 12.5 MB/s', 'meilisearch_enabled' => 'Whether to enable Meilisearch', 'meilisearch_enabled_help' => 'Please install and configure it and import the data before enabling it, otherwise there is no data for torrent search.', + 'meilisearch_search_description' => 'Meilisearch whether to search for descriptions', + 'meilisearch_search_description_help' => "Default: 'No'. If 'Yes', description containing keywords will also be returned, and the number of hits may be higher. Need to re-import immediately after change", ], ], 'user' => [ diff --git a/resources/lang/zh_CN/label.php b/resources/lang/zh_CN/label.php index 7469218e..2f4cbefa 100644 --- a/resources/lang/zh_CN/label.php +++ b/resources/lang/zh_CN/label.php @@ -94,7 +94,9 @@ return [ 'maximum_upload_speed' => '最大上传速度', 'maximum_upload_speed_help' => '单种上传速度超过此值账号即刻禁用,单位 Mbps。如:100 Mbps = 12.5 MB/s', 'meilisearch_enabled' => '是否启用 Meilisearch', - 'meilisearch_enabled_help' => '请先安装配置好并导入数据再启用,否则种子搜索无数据。', + 'meilisearch_enabled_help' => '请先安装配置好并导入数据再启用,否则种子搜索无数据', + 'meilisearch_search_description' => 'Meilisearch 是否搜索描述', + 'meilisearch_search_description_help' => "默认:'否'。若为'是',描述中包含关键字也会返回,命中的结果可能较多。修改后需立即重新导入", ], ], 'user' => [ diff --git a/resources/lang/zh_TW/label.php b/resources/lang/zh_TW/label.php index a382a9a4..c1e6ac0a 100644 --- a/resources/lang/zh_TW/label.php +++ b/resources/lang/zh_TW/label.php @@ -94,6 +94,8 @@ return [ 'maximum_upload_speed_help' => '單種上傳速度超過此值賬號即刻禁用,單位 Mbps。如:100 Mbps = 12.5 MB/s', 'meilisearch_enabled' => '是否啟用 Meilisearch', 'meilisearch_enabled_help' => '請先安裝配置好並導入數據再啟用,否則種子搜索無數據。', + 'meilisearch_search_description' => 'Meilisearch 是否搜索描述', + 'meilisearch_search_description_help' => "默認:'否'。若為'是',描述中包含關鍵字也會返回,命中的結果可能較多。修改後需立即重新導入", ], ], 'user' => [