search refactor3
This commit is contained in:
parent
56a0958338
commit
2df079c65a
|
|
@ -523,37 +523,47 @@ class ProductRepository extends PRepository
|
|||
|
||||
|
||||
|
||||
$qb = app(ProductFlatRepository::class)->getModel()::search(implode(' OR ', $queries),function($index, $query, $options){
|
||||
$qb = app(ProductFlatRepository::class)->getModel()::search(implode(' OR ', $queries),function($meilisearch, $query, $options) use ($params){
|
||||
$channel = core()->getRequestedChannelCode();
|
||||
|
||||
$locale = core()->getRequestedLocaleCode();
|
||||
|
||||
$options['filters'] = "(locale = $locale) AND (channel = $channel)";
|
||||
});
|
||||
// ->where('status', 1)
|
||||
// ->where('visible_individually', 1)
|
||||
// ->where('channel', $channel)
|
||||
// ->where('locale', $locale)
|
||||
// ->orderBy('product_id', 'desc');
|
||||
|
||||
$options['sort'] = ['name:asc'];
|
||||
# sort direction
|
||||
$orderDirection = 'asc';
|
||||
// if (isset($params['order']) && in_array($params['order'], ['desc', 'asc'])) {
|
||||
// $orderDirection = $params['order'];
|
||||
// } else {
|
||||
// $sortOptions = $this->getDefaultSortByOption();
|
||||
//
|
||||
// $orderDirection = ! empty($sortOptions) ? $sortOptions[1] : 'asc';
|
||||
// }
|
||||
//
|
||||
// if (isset($params['sort'])) {
|
||||
// $this->checkSortAttributeAndGenerateQuery($qb, $params['sort'], $orderDirection);
|
||||
// } else {
|
||||
// $sortOptions = $this->getDefaultSortByOption();
|
||||
// if (! empty($sortOptions)) {
|
||||
// $this->checkSortAttributeAndGenerateQuery($qb, $sortOptions[0], $orderDirection);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (isset($params['order']) && in_array($params['order'], ['desc', 'asc'])) {
|
||||
$orderDirection = $params['order'];
|
||||
} else {
|
||||
$sortOptions = $this->getDefaultSortByOption();
|
||||
|
||||
$orderDirection = ! empty($sortOptions) ? $sortOptions[1] : 'asc';
|
||||
}
|
||||
|
||||
if (isset($params['sort'])) {
|
||||
|
||||
$attribute = $this->attributeRepository->findOneByField('code', $params['sort']);
|
||||
|
||||
if ($attribute) {
|
||||
if ($attribute->code === 'price') {
|
||||
$options['sort'] = ["min_price:$orderDirection"];
|
||||
|
||||
} else {
|
||||
$options['sort'] = ["$attribute->code:$orderDirection"];
|
||||
}
|
||||
} else {
|
||||
/* `created_at` is not an attribute so it will be in else case */
|
||||
$query->orderBy('product_flat.created_at', $orderDirection);
|
||||
}
|
||||
} else {
|
||||
$sortOptions = $this->getDefaultSortByOption();
|
||||
$options['sort'] = ["$sortOptions[0]:$sortOptions[1]"];
|
||||
|
||||
}
|
||||
//$options['sort'] =
|
||||
|
||||
return $meilisearch->search($query, $options);
|
||||
});
|
||||
|
||||
return $qb->paginate($perPage);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue