Laravel Scout Elastic


(Adem) #1

Hello. I use the https://packagist.org/packages/tamayo/laravel-scout-elastic package for Laravel Scout Elastic. I had to write a closure function to use fuzzy. My problem is that I need to get the true values ​​in the Internet column of the table I query, but Model::search (...)->where('internet', 1) fetches all records. Although I have done a lot of research, I have not found a solution yet. Some of the methods I have tried are as follows.

    $products = Products::search($request->get('query'),
        function (\Elasticsearch\Client $client, $query, $params) {
            $params['body']['query'] = [
                'multi_match' => [
                    'query' => $query,
                    'fuzziness' => 'AUTO',
                    'fields' => ['name^3', 'brand'],
                ],        ];

            return $client->search($params);
        }
    )->where('internet', 1)->paginate(20);




    $products = Products::where('internet', 1)->search($request->get('query'),
        function (\Elasticsearch\Client $client, $query, $params) {
            $params['body']['query'] = [
                'multi_match' => [
                    'query' => $query,
                    'fuzziness' => 'AUTO',
                    'fields' => ['name^3', 'brand'],
                ],        ];

            return $client->search($params);
        }
    )->paginate(20);




      $products = Products::search($request->get('query'),
        function (\Elasticsearch\Client $client, $query, $params) {
            $params['body']['query'] = [
                'multi_match' => [
                    'query' => $query,
                    'fuzziness' => 'AUTO',
                    'fields' => ['name^3', 'brand'],
                ],
                'filter' => [
                      'term' => ['internet' => 1]
                ]      ];

            return $client->search($params);
        }
    )->where('internet', 1)->paginate(20);

I'm sorry for my bad english.


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.