mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-29 08:27:23 +08:00
meilisearch sort
This commit is contained in:
@@ -97,6 +97,8 @@ class Test extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
$rep = new MeiliSearchRepository();
|
||||||
|
$rep->import();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ class MeiliSearchRepository extends BaseRepository
|
|||||||
self::SEARCH_AREA_IMDB => ['text' => 'imdb'],
|
self::SEARCH_AREA_IMDB => ['text' => 'imdb'],
|
||||||
];
|
];
|
||||||
|
|
||||||
//cat401=1&source1=1&medium1=1&codec1=1&audiocodec1=1&standard1=1&processing1=1&team1=1&incldead=1&spstate=2&inclbookmarked=1&search=tr&search_area=1&search_mode=1
|
|
||||||
private static array $queryFieldToTorrentFieldMaps = [
|
private static array $queryFieldToTorrentFieldMaps = [
|
||||||
'cat' => 'category',
|
'cat' => 'category',
|
||||||
'source' => 'source',
|
'source' => 'source',
|
||||||
@@ -159,12 +158,12 @@ class MeiliSearchRepository extends BaseRepository
|
|||||||
"filterableAttributes" => self::$filterableAttributes,
|
"filterableAttributes" => self::$filterableAttributes,
|
||||||
"sortableAttributes" => self::$sortableAttributes,
|
"sortableAttributes" => self::$sortableAttributes,
|
||||||
"rankingRules" => [
|
"rankingRules" => [
|
||||||
"sort",
|
|
||||||
"words",
|
"words",
|
||||||
// "typo",
|
"sort",
|
||||||
// "proximity",
|
"typo",
|
||||||
// "attribute",
|
"proximity",
|
||||||
// "exactness"
|
"attribute",
|
||||||
|
"exactness"
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
$index->updateSettings($settings);
|
$index->updateSettings($settings);
|
||||||
@@ -254,9 +253,11 @@ class MeiliSearchRepository extends BaseRepository
|
|||||||
//NP starts from 0, but meilisearch starts from 1
|
//NP starts from 0, but meilisearch starts from 1
|
||||||
"page" => $page + 1,
|
"page" => $page + 1,
|
||||||
"filter" => $filters,
|
"filter" => $filters,
|
||||||
"sort" => $this->getSort($params),
|
|
||||||
"attributesToRetrieve" => $this->getAttributesToRetrieve(),
|
"attributesToRetrieve" => $this->getAttributesToRetrieve(),
|
||||||
];
|
];
|
||||||
|
if (isset($params['sort'], $params['type'])) {
|
||||||
|
$searchParams['sort'] = $this->getSort($params);
|
||||||
|
}
|
||||||
$searchResult = $index->search($query, $searchParams);
|
$searchResult = $index->search($query, $searchParams);
|
||||||
$total = $searchResult->getTotalHits();
|
$total = $searchResult->getTotalHits();
|
||||||
do_log("search params: " . nexus_json_encode($searchParams) . ", total: $total");
|
do_log("search params: " . nexus_json_encode($searchParams) . ", total: $total");
|
||||||
@@ -493,6 +494,10 @@ class MeiliSearchRepository extends BaseRepository
|
|||||||
|
|
||||||
private function getSort(array $params): array
|
private function getSort(array $params): array
|
||||||
{
|
{
|
||||||
|
if (!isset($params['sort']) || !isset($params['type'])) {
|
||||||
|
//Use default
|
||||||
|
return [];
|
||||||
|
}
|
||||||
if (isset($params['sort'], self::$sortFieldMaps[$params['sort']]) && isset($params['type']) && in_array($params['type'], ['asc', 'desc'])) {
|
if (isset($params['sort'], self::$sortFieldMaps[$params['sort']]) && isset($params['type']) && in_array($params['type'], ['asc', 'desc'])) {
|
||||||
$sortField = self::$sortFieldMaps[$params['sort']];
|
$sortField = self::$sortFieldMaps[$params['sort']];
|
||||||
} else {
|
} else {
|
||||||
@@ -503,12 +508,14 @@ class MeiliSearchRepository extends BaseRepository
|
|||||||
} else {
|
} else {
|
||||||
$sortType = "desc";
|
$sortType = "desc";
|
||||||
}
|
}
|
||||||
if ($sortField == "id") {
|
//when searching, ignore promotion
|
||||||
return ["pos_state:desc", "$sortField:$sortType"];
|
// if ($sortField == "id") {
|
||||||
} else {
|
// return ["pos_state:desc", "$sortField:$sortType"];
|
||||||
return ["pos_state:desc", "$sortField:$sortType", "id:desc"];
|
// } else {
|
||||||
}
|
// return ["pos_state:desc", "$sortField:$sortType", "id:desc"];
|
||||||
|
// }
|
||||||
|
|
||||||
|
return ["$sortField:$sortType"];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPerPage(User $user)
|
private function getPerPage(User $user)
|
||||||
|
|||||||
Reference in New Issue
Block a user