mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
MeiliSearch + Peers&Snatched table swip
This commit is contained in:
+4
-4
@@ -76,7 +76,7 @@ function bonusarray($option = 0){
|
||||
$bonus['description'] = $lang_mybonus['text_buy_invite_note'];
|
||||
$results[] = $bonus;
|
||||
}
|
||||
|
||||
|
||||
//Tmp Invite
|
||||
$tmpInviteBonus = \App\Models\BonusLogs::getBonusForBuyTemporaryInvite();
|
||||
if ($tmpInviteBonus > 0) {
|
||||
@@ -306,7 +306,7 @@ unset($msg);
|
||||
if (isset($do)) {
|
||||
if ($do == "upload")
|
||||
$msg = $lang_mybonus['text_success_upload'];
|
||||
if ($do == "download")
|
||||
elseif ($do == "download")
|
||||
$msg = $lang_mybonus['text_success_download'];
|
||||
elseif ($do == "invite")
|
||||
$msg = $lang_mybonus['text_success_invites'];
|
||||
@@ -410,7 +410,7 @@ for ($i=0; $i < count($allBonus); $i++)
|
||||
}
|
||||
elseif($bonusarray['art'] == 'invite')
|
||||
{
|
||||
if (\App\Models\Setting::get('main.invitesystem') != 'yes')
|
||||
if (\App\Models\Setting::get('main.invitesystem') != 'yes')
|
||||
print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"".nexus_trans('invite.send_deny_reasons.invite_system_closed')."\" disabled=\"disabled\" /></td>");
|
||||
elseif(!user_can($permission, false, 0)){
|
||||
$requireClass = get_setting("authority.$permission");
|
||||
@@ -420,7 +420,7 @@ for ($i=0; $i < count($allBonus); $i++)
|
||||
}
|
||||
elseif($bonusarray['art'] == 'tmp_invite')
|
||||
{
|
||||
if (\App\Models\Setting::get('main.invitesystem') != 'yes')
|
||||
if (\App\Models\Setting::get('main.invitesystem') != 'yes')
|
||||
print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"".nexus_trans('invite.send_deny_reasons.invite_system_closed')."\" disabled=\"disabled\" /></td>");
|
||||
elseif(!user_can($permission, false, 0)){
|
||||
$requireClass = get_setting("authority.$permission");
|
||||
|
||||
+83
-45
@@ -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);
|
||||
|
||||
+2
-1
@@ -285,7 +285,8 @@ if ($affectedRows == 1) {
|
||||
'comment' => '',
|
||||
], true);
|
||||
}
|
||||
|
||||
$meiliSearch = new \App\Repositories\MeiliSearchRepository();
|
||||
$meiliSearch->doImportFromDatabase($row['id']);
|
||||
}
|
||||
|
||||
$returl = "details.php?id=$id&edited=1";
|
||||
|
||||
@@ -430,6 +430,9 @@ write_log("Torrent $id ($torrent) was uploaded by $anon");
|
||||
$searchRep = new \App\Repositories\SearchRepository();
|
||||
$searchRep->addTorrent($id);
|
||||
|
||||
$meiliSearch = new \App\Repositories\MeiliSearchRepository();
|
||||
$meiliSearch->doImportFromDatabase($id);
|
||||
|
||||
//===notify people who voted on offer thanks CoLdFuSiOn :)
|
||||
if ($is_offer)
|
||||
{
|
||||
|
||||
+23
-14
@@ -5,6 +5,7 @@ require_once(get_langfile_path('torrents.php'));
|
||||
require_once(get_langfile_path('speical.php'));
|
||||
loggedinorreturn();
|
||||
parked();
|
||||
|
||||
//check searchbox
|
||||
switch (nexus()->getScript()) {
|
||||
case 'torrents':
|
||||
@@ -27,8 +28,9 @@ switch (nexus()->getScript()) {
|
||||
*/
|
||||
$tagRep = new \App\Repositories\TagRepository();
|
||||
$allTags = $tagRep->listAll($sectiontype);
|
||||
$elasticsearchEnabled = nexus_env('ELASTICSEARCH_ENABLED');
|
||||
$filterInputWidth = 62;
|
||||
$searchParams = $_GET;
|
||||
$searchParams['mode'] = $sectiontype;
|
||||
|
||||
$showsubcat = get_searchbox_value($sectiontype, 'showsubcat');//whether show subcategory (i.e. sources, codecs) or not
|
||||
$showsource = get_searchbox_value($sectiontype, 'showsource'); //whether show sources or not
|
||||
@@ -54,9 +56,13 @@ if ($showsubcat){
|
||||
|
||||
$searchstr_ori = htmlspecialchars(trim($_GET["search"] ?? ''));
|
||||
$searchstr = mysql_real_escape_string(trim($_GET["search"] ?? ''));
|
||||
if (empty($searchstr))
|
||||
unset($searchstr);
|
||||
if (empty($searchstr)) {
|
||||
unset($searchstr);
|
||||
}
|
||||
|
||||
$meilisearchEnabled = get_setting('system.meilisearch_enabled') == 'yes';
|
||||
$shouldUseMeili = $meilisearchEnabled && !empty($searchstr);
|
||||
do_log("[SHOULD_USE_MEILI]: $shouldUseMeili");
|
||||
// sorting by MarkoStamcar
|
||||
$column = '';
|
||||
$ascdesc = '';
|
||||
@@ -154,8 +160,11 @@ elseif ($inclbookmarked == 2) //not bookmarked
|
||||
}
|
||||
// ----------------- end bookmarked ---------------------//
|
||||
|
||||
if (!isset($CURUSER) || !user_can('seebanned'))
|
||||
$wherea[] = "banned = 'no'";
|
||||
if (!isset($CURUSER) || !user_can('seebanned')) {
|
||||
$wherea[] = "banned = 'no'";
|
||||
$searchParams["banned"] = 'no';
|
||||
}
|
||||
|
||||
// ----------------- start include dead ---------------------//
|
||||
if (isset($_GET["incldead"]))
|
||||
$include_dead = intval($_GET["incldead"] ?? 0);
|
||||
@@ -821,9 +830,11 @@ if ($approvalStatusIconEnabled == 'yes' || (user_can('torrent-approval') && $app
|
||||
if ($showApprovalStatusFilter && isset($_REQUEST['approval_status']) && is_numeric($_REQUEST['approval_status'])) {
|
||||
$approvalStatus = intval($_REQUEST['approval_status']);
|
||||
$wherea[] = "torrents.approval_status = $approvalStatus";
|
||||
$searchParams['approval_status'] = $approvalStatus;
|
||||
$addparam .= "approval_status=$approvalStatus&";
|
||||
} elseif ($approvalStatusNoneVisible == 'no' && !user_can('torrent-approval')) {
|
||||
$wherea[] = "torrents.approval_status = " . \App\Models\Torrent::APPROVAL_STATUS_ALLOW;
|
||||
$searchParams['approval_status'] = \App\Models\Torrent::APPROVAL_STATUS_ALLOW;
|
||||
}
|
||||
|
||||
if (isset($_GET['size_begin']) && ctype_digit($_GET['size_begin'])) {
|
||||
@@ -903,12 +914,10 @@ else
|
||||
$sql = "SELECT COUNT(*), categories.mode FROM torrents LEFT JOIN categories ON category = categories.id " . ($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "") . $tagFilter . $where . " GROUP BY categories.mode";
|
||||
}
|
||||
|
||||
if ($elasticsearchEnabled) {
|
||||
$searchRep = new \App\Repositories\SearchRepository();
|
||||
$esParams = $_GET;
|
||||
$esParams['mode'] = $sectiontype;
|
||||
$resultFromElastic = $searchRep->listTorrentFromEs($esParams, $CURUSER['id'], $_SERVER['QUERY_STRING']);
|
||||
$count = $resultFromElastic['total'];
|
||||
if ($shouldUseMeili) {
|
||||
$searchRep = new \App\Repositories\MeiliSearchRepository();
|
||||
$resultFromSearchRep = $searchRep->search($searchParams, $CURUSER['id']);
|
||||
$count = $resultFromSearchRep['total'];
|
||||
} else {
|
||||
$res = sql_query($sql);
|
||||
$count = 0;
|
||||
@@ -957,7 +966,7 @@ if ($count)
|
||||
$query = "SELECT $fieldsStr, categories.mode as search_box_id FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")." LEFT JOIN categories ON torrents.category=categories.id $tagFilter $where $orderby $limit";
|
||||
// }
|
||||
do_log("[TORRENT_LIST_SQL] $query", 'debug');
|
||||
if (!$elasticsearchEnabled) {
|
||||
if (!$shouldUseMeili) {
|
||||
$res = sql_query($query);
|
||||
}
|
||||
} else {
|
||||
@@ -1258,8 +1267,8 @@ elseif($inclbookmarked == 2)
|
||||
|
||||
if ($count) {
|
||||
$rows = [];
|
||||
if ($elasticsearchEnabled) {
|
||||
$rows = $resultFromElastic['data'];
|
||||
if ($shouldUseMeili) {
|
||||
$rows = $resultFromSearchRep['list'];
|
||||
} else {
|
||||
while ($row = mysql_fetch_assoc($res)) {
|
||||
$rows[] = $row;
|
||||
|
||||
Reference in New Issue
Block a user