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', ''),
|
'id' => env('ALGOLIA_APP_ID', ''),
|
||||||
'secret' => env('ALGOLIA_SECRET', ''),
|
'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();
|
$locale = core()->getRequestedLocaleCode();
|
||||||
|
|
||||||
if (config('scout.driver') == 'algolia') {
|
if (config('scout.driver') == 'meilisearch') {
|
||||||
$results = app(ProductFlatRepository::class)->getModel()::search('query', function ($searchDriver, string $query, array $options) use ($term, $channel, $locale) {
|
$queries = explode('_', $term);
|
||||||
$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([
|
if (isset($params['order']) && in_array($params['order'], ['desc', 'asc'])) {
|
||||||
'attributesForFaceting' => [
|
$orderDirection = $params['order'];
|
||||||
'searchable(locale)',
|
} else {
|
||||||
'searchable(channel)',
|
$sortOptions = $this->getDefaultSortByOption();
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$options['facetFilters'] = ['locale:' . $locale, 'channel:' . $channel];
|
$orderDirection = ! empty($sortOptions) ? $sortOptions[1] : 'asc';
|
||||||
|
}
|
||||||
|
|
||||||
return $searchDriver->search($query, $options);
|
if (isset($params['sort']) && $attribute = $this->attributeRepository->findOneByField('code', $params['sort'])) {
|
||||||
})
|
|
||||||
->where('status', 1)
|
if ($attribute->code === 'price') {
|
||||||
->where('visible_individually', 1)
|
$options['sort'] = ["min_price:$orderDirection"];
|
||||||
->orderBy('product_id', 'desc')
|
|
||||||
->paginate(request()->input('limit')??10);
|
} 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') {
|
} else if (config('scout.driver') == 'elastic') {
|
||||||
$queries = explode('_', $term);
|
$queries = explode('_', $term);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue