BuyerService.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Services\Elasticsearch\Erp;
  3. use App\Foundation\ElasticsearchClient;
  4. class BuyerService
  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($where)
  18. {
  19. $query = "
  20. SELECT * FROM erp_buyer
  21. WHERE $where
  22. ";
  23. return $this->executeSql($query);
  24. }
  25. public function executeSql($query)
  26. {
  27. return $this->client->client()->sql()->query([
  28. 'body' => [ 'query' => $query ]
  29. ])['rows'];
  30. }
  31. public function getQueryByKeyword($keyword)
  32. {
  33. return "SELECT serial_number
  34. FROM taling___products_product___v1
  35. WHERE
  36. (
  37. MATCH(name_nori, '$keyword') OR MATCH(name_jamo, '$keyword') OR MATCH(name_chosung, '$keyword')
  38. OR
  39. MATCH(display_name_nori, '$keyword') OR MATCH(display_name_jamo, '$keyword') OR MATCH(display_name_chosung, '$keyword')
  40. OR
  41. MATCH(description_nori, '$keyword') OR MATCH(description_jamo, '$keyword') OR MATCH(description_chosung, '$keyword')
  42. OR
  43. MATCH(market_name_nori, '$keyword') OR MATCH(market_name_jamo, '$keyword') OR MATCH(market_name_chosung, '$keyword')
  44. OR
  45. MATCH(category_name_nori, '$keyword') OR MATCH(category_name_jamo, '$keyword') OR MATCH(category_name_chosung, '$keyword')
  46. )
  47. ORDER BY score() DESC";
  48. }
  49. }