mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
MeiliSearch + Peers&Snatched table swip
This commit is contained in:
@@ -16,54 +16,88 @@ if ($approvalStatusNoneVisible == 'no' && !user_can('torrent-approval')) {
|
||||
$approvalStatus = \App\Models\Torrent::APPROVAL_STATUS_ALLOW;
|
||||
}
|
||||
|
||||
//section
|
||||
$modeArr = [\App\Models\SearchBox::getBrowseMode()];
|
||||
if (\App\Models\SearchBox::isSpecialEnabled() && user_can('view_special_torrent')) {
|
||||
$modeArr[] = \App\Models\SearchBox::getSpecialMode();
|
||||
}
|
||||
|
||||
//see banned
|
||||
$banned = null;
|
||||
if (!isset($CURUSER) || !user_can('seebanned')) {
|
||||
$banned = "no";
|
||||
}
|
||||
|
||||
$meilisearchEnabled = get_setting('system.meilisearch_enabled') == 'yes';
|
||||
$shouldUseMeili = $meilisearchEnabled && !empty($search);
|
||||
|
||||
$count = 0;
|
||||
$rows = [];
|
||||
if ($search) {
|
||||
$search = str_replace(".", " ", $search);
|
||||
$searchArr = preg_split("/[\s]+/", $search, 10,PREG_SPLIT_NO_EMPTY);
|
||||
$tableTorrent = "torrents";
|
||||
$tableUser = "users";
|
||||
$tableCategory = "categories";
|
||||
$torrentQuery = \Nexus\Database\NexusDB::table($tableTorrent)->join($tableCategory, "$tableTorrent.category", "=", "$tableCategory.id");
|
||||
if (get_setting('main.spsct') == 'yes' && !user_can('view_special_torrent')) {
|
||||
$torrentQuery->where("$tableCategory.mode", get_setting('main.browsecat'));
|
||||
}
|
||||
if ($searchArea == \App\Repositories\SearchRepository::SEARCH_AREA_TITLE) {
|
||||
foreach ($searchArr as $queryString) {
|
||||
$q = "%{$queryString}%";
|
||||
$torrentQuery->where(function (\Illuminate\Database\Query\Builder $query) use ($q, $tableTorrent) {
|
||||
return $query->where("$tableTorrent.name", 'like', $q)->orWhere("$tableTorrent.small_descr", "like", $q);
|
||||
});
|
||||
if ($shouldUseMeili) {
|
||||
$searchRep = new \App\Repositories\MeiliSearchRepository();
|
||||
$searchParams = $_GET;
|
||||
if ($approvalStatus != null) {
|
||||
$searchParams['approval_status'] = $approvalStatus;
|
||||
}
|
||||
} elseif ($searchArea == \App\Repositories\SearchRepository::SEARCH_AREA_DESC) {
|
||||
foreach ($searchArr as $queryString) {
|
||||
$q = "%{$queryString}%";
|
||||
$torrentQuery->where("$tableTorrent.descr", "like", $q);
|
||||
}
|
||||
} elseif ($searchArea == \App\Repositories\SearchRepository::SEARCH_AREA_OWNER) {
|
||||
$torrentQuery->join($tableUser, "$tableTorrent.owner", "=", "$tableUser.id");
|
||||
foreach ($searchArr as $queryString) {
|
||||
$q = "%{$queryString}%";
|
||||
$torrentQuery->where("$tableUser.username", "like", $q);
|
||||
}
|
||||
} elseif ($searchArea == \App\Repositories\SearchRepository::SEARCH_AREA_IMDB) {
|
||||
foreach ($searchArr as $queryString) {
|
||||
$q = "%{$queryString}%";
|
||||
$torrentQuery->where("$tableTorrent.url", "like", $q);
|
||||
if ($banned != null) {
|
||||
$searchParams['banned'] = $banned;
|
||||
}
|
||||
//Include dead
|
||||
$searchParams['incldead'] = 0;
|
||||
$searchParams['mode'] = $modeArr;
|
||||
$resultFromSearchRep = $searchRep->search($searchParams, $CURUSER['id']);
|
||||
$count = $resultFromSearchRep['total'];
|
||||
} else {
|
||||
foreach ($searchArr as $queryString) {
|
||||
$q = "%{$queryString}%";
|
||||
$torrentQuery->where("$tableTorrent.name", "like", $q);
|
||||
}
|
||||
write_log("User " . $CURUSER["username"] . "," . $CURUSER["ip"] . " is hacking search_area field in" . $_SERVER['SCRIPT_NAME'], 'mod');
|
||||
}
|
||||
if ($approvalStatus !== null) {
|
||||
$torrentQuery->where("$tableTorrent.approval_status", $approvalStatus);
|
||||
}
|
||||
$torrentQuery->where("$tableTorrent.visible", 'yes');
|
||||
$tableTorrent = "torrents";
|
||||
$tableUser = "users";
|
||||
$tableCategory = "categories";
|
||||
$torrentQuery = \Nexus\Database\NexusDB::table($tableTorrent)
|
||||
->join($tableCategory, "$tableTorrent.category", "=", "$tableCategory.id")
|
||||
->whereIn("$tableCategory.mode", $modeArr)
|
||||
;
|
||||
|
||||
$count = $torrentQuery->count();
|
||||
if ($searchArea == \App\Repositories\SearchRepository::SEARCH_AREA_TITLE) {
|
||||
foreach ($searchArr as $queryString) {
|
||||
$q = "%{$queryString}%";
|
||||
$torrentQuery->where(function (\Illuminate\Database\Query\Builder $query) use ($q, $tableTorrent) {
|
||||
return $query->where("$tableTorrent.name", 'like', $q)->orWhere("$tableTorrent.small_descr", "like", $q);
|
||||
});
|
||||
}
|
||||
} elseif ($searchArea == \App\Repositories\SearchRepository::SEARCH_AREA_DESC) {
|
||||
foreach ($searchArr as $queryString) {
|
||||
$q = "%{$queryString}%";
|
||||
$torrentQuery->where("$tableTorrent.descr", "like", $q);
|
||||
}
|
||||
} elseif ($searchArea == \App\Repositories\SearchRepository::SEARCH_AREA_OWNER) {
|
||||
$torrentQuery->join($tableUser, "$tableTorrent.owner", "=", "$tableUser.id");
|
||||
foreach ($searchArr as $queryString) {
|
||||
$q = "%{$queryString}%";
|
||||
$torrentQuery->where("$tableUser.username", "like", $q);
|
||||
}
|
||||
} elseif ($searchArea == \App\Repositories\SearchRepository::SEARCH_AREA_IMDB) {
|
||||
foreach ($searchArr as $queryString) {
|
||||
$q = "%{$queryString}%";
|
||||
$torrentQuery->where("$tableTorrent.url", "like", $q);
|
||||
}
|
||||
} else {
|
||||
foreach ($searchArr as $queryString) {
|
||||
$q = "%{$queryString}%";
|
||||
$torrentQuery->where("$tableTorrent.name", "like", $q);
|
||||
}
|
||||
write_log("User " . $CURUSER["username"] . "," . $CURUSER["ip"] . " is hacking search_area field in" . $_SERVER['SCRIPT_NAME'], 'mod');
|
||||
}
|
||||
if ($approvalStatus !== null) {
|
||||
$torrentQuery->where("$tableTorrent.approval_status", $approvalStatus);
|
||||
}
|
||||
if ($banned !== null) {
|
||||
$torrentQuery->where("$tableTorrent.banned", $banned);
|
||||
}
|
||||
|
||||
$count = $torrentQuery->count();
|
||||
}
|
||||
}
|
||||
|
||||
if ($CURUSER["torrentsperpage"])
|
||||
@@ -106,12 +140,16 @@ list($pagertop, $pagerbottom, $limit, $offset, $size, $page) = pager($torrentspe
|
||||
stdhead(nexus_trans('search.global_search'));
|
||||
print("<table width=\"97%\" class=\"main\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td class=\"embedded\">");
|
||||
if ($search && $count > 0) {
|
||||
$fieldsStr = implode(', ', \App\Models\Torrent::getFieldsForList(true));
|
||||
$rows = $torrentQuery->selectRaw("$fieldsStr, categories.mode as search_box_id")
|
||||
->forPage($page + 1, $torrentsperpage)
|
||||
->orderBy("$tableTorrent.$column", $ascdesc)
|
||||
->get()
|
||||
->toArray();
|
||||
if ($shouldUseMeili) {
|
||||
$rows = $resultFromSearchRep['list'];
|
||||
} else {
|
||||
$fieldsStr = implode(', ', \App\Models\Torrent::getFieldsForList(true));
|
||||
$rows = $torrentQuery->selectRaw("$fieldsStr, categories.mode as search_box_id")
|
||||
->forPage($page + 1, $torrentsperpage)
|
||||
->orderBy("$tableTorrent.$column", $ascdesc)
|
||||
->get()
|
||||
->toArray();
|
||||
}
|
||||
print($pagertop);
|
||||
torrenttable(json_decode(json_encode($rows), true));
|
||||
print($pagerbottom);
|
||||
|
||||
Reference in New Issue
Block a user