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();
|
$channel = core()->getRequestedChannelCode();
|
||||||
|
|
||||||
$locale = core()->getRequestedLocaleCode();
|
$locale = core()->getRequestedLocaleCode();
|
||||||
|
|
||||||
$options['filters'] = "(locale = $locale) AND (channel = $channel)";
|
$options['filters'] = "(locale = $locale) AND (channel = $channel)";
|
||||||
});
|
$options['sort'] = ['name:asc'];
|
||||||
// ->where('status', 1)
|
|
||||||
// ->where('visible_individually', 1)
|
|
||||||
// ->where('channel', $channel)
|
|
||||||
// ->where('locale', $locale)
|
|
||||||
// ->orderBy('product_id', 'desc');
|
|
||||||
|
|
||||||
# sort direction
|
# sort direction
|
||||||
$orderDirection = 'asc';
|
|
||||||
// if (isset($params['order']) && in_array($params['order'], ['desc', 'asc'])) {
|
if (isset($params['order']) && in_array($params['order'], ['desc', 'asc'])) {
|
||||||
// $orderDirection = $params['order'];
|
$orderDirection = $params['order'];
|
||||||
// } else {
|
} else {
|
||||||
// $sortOptions = $this->getDefaultSortByOption();
|
$sortOptions = $this->getDefaultSortByOption();
|
||||||
//
|
|
||||||
// $orderDirection = ! empty($sortOptions) ? $sortOptions[1] : 'asc';
|
$orderDirection = ! empty($sortOptions) ? $sortOptions[1] : 'asc';
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (isset($params['sort'])) {
|
if (isset($params['sort'])) {
|
||||||
// $this->checkSortAttributeAndGenerateQuery($qb, $params['sort'], $orderDirection);
|
|
||||||
// } else {
|
$attribute = $this->attributeRepository->findOneByField('code', $params['sort']);
|
||||||
// $sortOptions = $this->getDefaultSortByOption();
|
|
||||||
// if (! empty($sortOptions)) {
|
if ($attribute) {
|
||||||
// $this->checkSortAttributeAndGenerateQuery($qb, $sortOptions[0], $orderDirection);
|
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);
|
return $qb->paginate($perPage);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue