ElasticsearchService.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Services\Elasticsearch;
  3. use App\Foundation\ElasticsearchClient;
  4. class ElasticsearchService
  5. {
  6. /**
  7. * @var ElasticsearchClient
  8. */
  9. private $client;
  10. /**
  11. * @param ElasticsearchClient $client
  12. */
  13. public function __construct(ElasticsearchClient $client)
  14. {
  15. $this->client = $client;
  16. }
  17. public function getQueryAll($query)
  18. {
  19. $query = "
  20. $query
  21. ";
  22. return $this->executeSql($query);
  23. }
  24. public function executeSql($query)
  25. {
  26. return $this->client->client()->sql()->query([
  27. 'body' => [ 'query' => $query ]
  28. ])['rows'];
  29. }
  30. public function getQueryByKeyword($keyword)
  31. {
  32. return "SELECT serial_number
  33. FROM taling___products_product___v1
  34. WHERE
  35. (
  36. MATCH(name_nori, '$keyword') OR MATCH(name_jamo, '$keyword') OR MATCH(name_chosung, '$keyword')
  37. OR
  38. MATCH(display_name_nori, '$keyword') OR MATCH(display_name_jamo, '$keyword') OR MATCH(display_name_chosung, '$keyword')
  39. OR
  40. MATCH(description_nori, '$keyword') OR MATCH(description_jamo, '$keyword') OR MATCH(description_chosung, '$keyword')
  41. OR
  42. MATCH(market_name_nori, '$keyword') OR MATCH(market_name_jamo, '$keyword') OR MATCH(market_name_chosung, '$keyword')
  43. OR
  44. MATCH(category_name_nori, '$keyword') OR MATCH(category_name_jamo, '$keyword') OR MATCH(category_name_chosung, '$keyword')
  45. )
  46. ORDER BY score() DESC";
  47. }
  48. }