scraper link change sarch
This commit is contained in:
parent
e62affb2da
commit
81ea303a1d
|
|
@ -41,7 +41,7 @@ return [
|
|||
|
|
||||
*/
|
||||
|
||||
'queue' => env('SCOUT_QUEUE', false),
|
||||
'queue' => env('SCOUT_QUEUE', true),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
@ -115,5 +115,17 @@ return [
|
|||
'id' => env('ALGOLIA_APP_ID', ''),
|
||||
'secret' => env('ALGOLIA_SECRET', ''),
|
||||
],
|
||||
'meilisearch' => [
|
||||
'host' => env('MEILISEARCH_HOST', 'http://localhost:7700'),
|
||||
'key' => env('MEILISEARCH_KEY', 'qazwsx12qazwsx12'),
|
||||
'index-settings' => [
|
||||
\Webkul\Product\Models\ProductFlat::class => [
|
||||
'filterableAttributes'=> ['locale', 'channel' ],
|
||||
'sortableAttributes' => ['name','created_at','min_price'],
|
||||
// Other settings fields...
|
||||
],
|
||||
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -475,27 +475,40 @@ class ProductRepository extends WProductRepository
|
|||
|
||||
$locale = core()->getRequestedLocaleCode();
|
||||
|
||||
if (config('scout.driver') == 'algolia') {
|
||||
$results = app(ProductFlatRepository::class)->getModel()::search('query', function ($searchDriver, string $query, array $options) use ($term, $channel, $locale) {
|
||||
$queries = explode('_', $term);
|
||||
if (config('scout.driver') == 'meilisearch') {
|
||||
$queries = explode('_', $term);
|
||||
$result = app(ProductFlatRepository::class)->getModel()::search(implode(' OR ', $queries),
|
||||
function($meilisearch, $query, $options) use ($term, $channel, $locale){
|
||||
|
||||
$options['similarQuery'] = array_map('trim', $queries);
|
||||
$options['filter'] = "(locale = $locale) AND (channel = $channel)";
|
||||
$options['sort'] = ['name:asc'];
|
||||
# sort direction
|
||||
|
||||
$searchDriver->setSettings([
|
||||
'attributesForFaceting' => [
|
||||
'searchable(locale)',
|
||||
'searchable(channel)',
|
||||
],
|
||||
]);
|
||||
if (isset($params['order']) && in_array($params['order'], ['desc', 'asc'])) {
|
||||
$orderDirection = $params['order'];
|
||||
} else {
|
||||
$sortOptions = $this->getDefaultSortByOption();
|
||||
|
||||
$options['facetFilters'] = ['locale:' . $locale, 'channel:' . $channel];
|
||||
$orderDirection = ! empty($sortOptions) ? $sortOptions[1] : 'asc';
|
||||
}
|
||||
|
||||
return $searchDriver->search($query, $options);
|
||||
})
|
||||
->where('status', 1)
|
||||
->where('visible_individually', 1)
|
||||
->orderBy('product_id', 'desc')
|
||||
->paginate(request()->input('limit')??10);
|
||||
if (isset($params['sort']) && $attribute = $this->attributeRepository->findOneByField('code', $params['sort'])) {
|
||||
|
||||
if ($attribute->code === 'price') {
|
||||
$options['sort'] = ["min_price:$orderDirection"];
|
||||
|
||||
} else {
|
||||
$options['sort'] = ["$attribute->code:$orderDirection"];
|
||||
}
|
||||
} else {
|
||||
$sortOptions = $this->getDefaultSortByOption();
|
||||
$options['sort'] = ["$sortOptions[0]:$sortOptions[1]"];
|
||||
|
||||
}
|
||||
//$options['sort'] =
|
||||
|
||||
return $meilisearch->rawSearch($query, $options);
|
||||
});
|
||||
} else if (config('scout.driver') == 'elastic') {
|
||||
$queries = explode('_', $term);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue