meilisearch single setting and default search mode

This commit is contained in:
xiaomlove
2023-05-11 02:23:19 +08:00
parent 4684640dcd
commit 0fbd815a8f
12 changed files with 135 additions and 41 deletions

View File

@@ -5,8 +5,10 @@ namespace App\Filament\Resources\System\SettingResource\Pages;
use App\Filament\OptionsTrait;
use App\Filament\Resources\System\SettingResource;
use App\Models\HitAndRun;
use App\Models\SearchBox;
use App\Models\Setting;
use App\Models\Tag;
use App\Repositories\MeiliSearchRepository;
use Filament\Facades\Filament;
use Filament\Forms\ComponentContainer;
use Filament\Forms\Concerns\InteractsWithForms;
@@ -115,6 +117,13 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
Forms\Components\TextInput::make('seed_box.max_uploaded_duration')->label(__('label.setting.seed_box.max_uploaded_duration'))->helperText(__('label.setting.seed_box.max_uploaded_duration_help'))->integer(),
])->columns(2);
$id = "meilisearch";
$tabs[] = Forms\Components\Tabs\Tab::make(__("label.setting.$id.tab_header"))
->id($id)
->schema($this->getTabMeilisearchSchema($id))
->columns(2)
;
$tabs[] = Forms\Components\Tabs\Tab::make(__('label.setting.system.tab_header'))
->id('system')
->schema([
@@ -140,18 +149,6 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
->label(__('label.setting.system.maximum_upload_speed'))
->helperText(__('label.setting.system.maximum_upload_speed_help'))
,
Forms\Components\Radio::make('system.meilisearch_enabled')
->options(self::$yesOrNo)
->inline(true)
->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);
@@ -170,4 +167,35 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
return apply_filter("hit_and_run_setting_schema", $default);
}
private function getTabMeilisearchSchema($id)
{
$schema = [];
$name = "$id.enabled";
$schema[] = Forms\Components\Radio::make($name)
->options(self::$yesOrNo)
->inline(true)
->label(__('label.enabled'))
->helperText(__("label.setting.{$name}_help"))
;
$name = "$id.search_description";
$schema[] = Forms\Components\Radio::make($name)
->options(self::$yesOrNo)
->inline(true)
->label(__("label.setting.$name"))
->helperText(__("label.setting.{$name}_help"))
;
$name = "$id.default_search_mode";
$schema[] = Forms\Components\Radio::make($name)
->options(SearchBox::listSearchModes())
->inline(true)
->label(__("label.setting.$name"))
->helperText(__("label.setting.{$name}_help"))
;
return $schema;
}
}

View File

@@ -31,6 +31,14 @@ class SearchBox extends NexusModel
'section_name' => 'json',
];
const SEARCH_MODE_AND = '0';
const SEARCH_MODE_EXACT = '2';
public static array $searchModes = [
self::SEARCH_MODE_AND => ['text' => 'and'],
self::SEARCH_MODE_EXACT => ['text' => 'exact'],
];
const EXTRA_TAXONOMY_LABELS = 'taxonomy_labels';
const SECTION_BROWSE = 'browse';
const SECTION_SPECIAL = 'special';
@@ -174,6 +182,15 @@ class SearchBox extends NexusModel
}
}
public static function listSearchModes(): array
{
$result = [];
foreach (self::$searchModes as $key => $value) {
$result[$key] = nexus_trans("search.search_modes.{$value['text']}");
}
return $result;
}
public static function isSpecialEnabled(): bool
{
return Setting::get('main.spsct') == 'yes';
@@ -230,5 +247,32 @@ class SearchBox extends NexusModel
return $this->hasMany(Processing::class, 'mode');
}
public static function getDefaultSearchMode()
{
$meiliConf = get_setting("meilisearch");
if ($meiliConf['enabled'] == 'yes') {
return $meiliConf['default_search_mode'];
} else {
return self::SEARCH_MODE_AND;
}
}
public static function listSelectModeOptions($selectedValue): string
{
$options = [];
if (!is_numeric($selectedValue)) {
//set default
$selectedValue = self::getDefaultSearchMode();
}
foreach (self::listSearchModes() as $key => $text) {
$selected = "";
if ((string)$key === (string)$selectedValue) {
$selected = " selected";
}
$options[] = sprintf('<option value="%s"%s>%s</option>', $key, $selected, $text);
}
return implode('', $options);
}
}

View File

@@ -21,14 +21,6 @@ class MeiliSearchRepository extends BaseRepository
const INDEX_NAME = 'torrents';
const SEARCH_MODE_AND = '0';
const SEARCH_MODE_EXACT = '2';
private static array $searchModes = [
self::SEARCH_MODE_AND => ['text' => 'and'],
self::SEARCH_MODE_EXACT => ['text' => 'exact'],
];
const SEARCH_AREA_TITLE = '0';
const SEARCH_AREA_DESC = '1';
const SEARCH_AREA_OWNER = '3';
@@ -64,6 +56,7 @@ class MeiliSearchRepository extends BaseRepository
'9' => 'owner',
];
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",
@@ -120,7 +113,7 @@ class MeiliSearchRepository extends BaseRepository
$swapResult = $client->swapIndexes([[self::INDEX_NAME, $indexName]]);
$times = 0;
while (true) {
if ($times == 60) {
if ($times == 600) {
$msg = "total: $total, swap too long, times: $times, return false";
do_log($msg);
throw new NexusException($msg);
@@ -468,12 +461,12 @@ class MeiliSearchRepository extends BaseRepository
private function getQuery(array $params): string
{
$q = trim($params['search']);
$searchMode = self::SEARCH_MODE_AND;
if (isset($params['search_mode'], self::$searchModes[$params['search_mode']])) {
$searchMode = SearchBox::getDefaultSearchMode();
if (isset($params['search_mode'], SearchBox::$searchModes[$params['search_mode']])) {
$searchMode = $params['search_mode'];
}
do_log("search mode: " . self::$searchModes[$searchMode]['text']);
if ($searchMode == self::SEARCH_MODE_AND) {
if ($searchMode == SearchBox::SEARCH_MODE_AND) {
return $q;
}
return sprintf('"%s"', $q);

View File

@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.3');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-05-10');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-05-11');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");

View File

@@ -439,13 +439,16 @@ return array (
'not_seed_box_max_speed' => 10240,
'max_uploaded_duration' => 0,
],
'meilisearch' => [
'enabled' => 'no',
'search_description' => 'no',
'default_search_mode' => \App\Models\SearchBox::SEARCH_MODE_EXACT,
],
'system' => [
'change_username_min_interval_in_days' => '365',
'change_username_card_allow_characters_outside_the_alphabets' => 'no',
'maximum_number_of_medals_can_be_worn' => 3,
'cookie_valid_days' => 365,
'maximum_upload_speed' => 8000,
'meilisearch_enabled' => 'no',
'meilisearch_search_description' => 'no',
],
);

View File

@@ -1211,8 +1211,7 @@ if ($allsec != 1 || $enablespecial != 'yes'){ //do not print searchbox if showin
<?php echo $lang_torrents['text_with'] ?>
<select name="search_mode" style="width: 60px;">
<option value="0"><?php echo $lang_torrents['select_and'] ?></option>
<option value="2"<?php echo isset($_GET["search_mode"]) && $_GET["search_mode"] == 2 ? " selected=\"selected\"" : "" ?>><?php echo $lang_torrents['select_exact'] ?></option>
<?php echo \App\Models\SearchBox::listSelectModeOptions($_GET["search_mode"] ?? "")?>
</select>
<?php echo $lang_torrents['text_mode'] ?>

View File

@@ -85,6 +85,15 @@ return [
'max_uploaded_duration' => 'Maximum upload volume multiplier effective time range',
'max_uploaded_duration_help' => 'Unit: hours. The maximum upload volume multiplier takes effect within this time range after the torrent is published, and does not take effect beyond this range. A setting of 0 is always in effect',
],
'meilisearch' => [
'tab_header' => 'Meilisearch',
'enabled' => 'Whether to enable Meilisearch',
'enabled_help' => 'Please install and configure it and import the data before enabling it, otherwise there is no data for torrent search.',
'search_description' => 'Meilisearch whether to search for descriptions',
'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",
'default_search_mode' => 'Default search mode',
'default_search_mode_help' => "Default: 'Exact'. 'And' will be split, 'Exact' is not split",
],
'system' => [
'tab_header' => 'System',
'change_username_card_allow_characters_outside_the_alphabets' => 'Does the name change card allow characters other than English letters',
@@ -93,10 +102,6 @@ return [
'cookie_valid_days' => 'Cookie Valid days',
'maximum_upload_speed' => 'Maximum upload speed',
'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' => [

View File

@@ -10,4 +10,8 @@ return [
'3' => 'Uploader',
'4' => 'IMDB URL'
],
'search_modes' => [
'and' => 'And',
'exact' => 'Exact',
],
];

View File

@@ -85,6 +85,15 @@ return [
'max_uploaded_duration' => '最大上传量倍数有效时间范围',
'max_uploaded_duration_help' => '单位:小时。种子发布后的这个时间范围内,最大上传量倍数生效,超过此范围不生效。设置为 0 一直生效',
],
'meilisearch' => [
'tab_header' => 'Meilisearch',
'enabled' => '是否启用 Meilisearch',
'enabled_help' => '请先安装配置好并导入数据再启用,否则种子搜索无数据',
'search_description' => '是否搜索描述',
'search_description_help' => "默认:'否'。若为'是',描述中包含关键字也会返回,命中的结果可能较多。修改后需立即重新导入",
'default_search_mode' => '默认搜索模式',
'default_search_mode_help' => "默认:'准确'。'与'将进行分词,'准确'不分词",
],
'system' => [
'tab_header' => '系统',
'change_username_card_allow_characters_outside_the_alphabets' => '改名卡是否允许英文字母外的字符',
@@ -93,10 +102,6 @@ return [
'cookie_valid_days' => 'Cookie 有效天数',
'maximum_upload_speed' => '最大上传速度',
'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' => [

View File

@@ -10,4 +10,8 @@ return [
'3' => '发布者',
'4' => 'IMDB链接'
],
'search_modes' => [
'and' => '与',
'exact' => '准确',
],
];

View File

@@ -85,6 +85,15 @@ return [
'max_uploaded_duration' => '最大上傳量倍數有效時間範圍',
'max_uploaded_duration_help' => '單位:小時。種子發布後的這個時間範圍內,最大上傳量倍數生效,超過此範圍不生效。設置為 0 一直生效',
],
'meilisearch' => [
'tab_header' => 'Meilisearch',
'enabled' => '是否啟用 Meilisearch',
'enabled_help' => '請先安裝配置好並導入數據再啟用,否則種子搜索無數據',
'search_description' => '是否搜索描述',
'search_description_help' => "默認:'否'。若為'是',描述中包含關鍵字也會返回,命中的結果可能較多。修改後需立即重新導入",
'default_search_mode' => '默認搜索模式',
'default_search_mode_help' => "默認:'準確'。'與'將進行分詞,'準確'不分詞",
],
'system' => [
'tab_header' => '系統',
'change_username_card_allow_characters_outside_the_alphabets' => '改名卡是否允許英文字母外的字符',
@@ -92,10 +101,6 @@ return [
'maximum_number_of_medals_can_be_worn' => '勛章最大可佩戴數',
'cookie_valid_days' => 'Cookie 有效天數',
'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' => [

View File

@@ -10,4 +10,8 @@ return [
'3' => '發布者',
'4' => 'IMDB鏈接'
],
'search_modes' => [
'and' => '與',
'exact' => '準確',
],
];