BoolExpression.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Search\Request\Query;
  7. use Magento\Framework\Search\Request\QueryInterface;
  8. /**
  9. * Bool Query
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class BoolExpression implements QueryInterface
  14. {
  15. const QUERY_CONDITION_MUST = 'must';
  16. const QUERY_CONDITION_SHOULD = 'should';
  17. const QUERY_CONDITION_NOT = 'not';
  18. /**
  19. * Boost
  20. *
  21. * @var int|null
  22. */
  23. protected $boost;
  24. /**
  25. * Query Name
  26. *
  27. * @var string
  28. */
  29. protected $name;
  30. /**
  31. * Query names to which result set SHOULD satisfy
  32. *
  33. * @var array
  34. */
  35. protected $should = [];
  36. /**
  37. * Query names to which result set MUST satisfy
  38. *
  39. * @var array
  40. */
  41. protected $must = [];
  42. /**
  43. * Query names to which result set MUST NOT satisfy
  44. *
  45. * @var array
  46. */
  47. protected $mustNot = [];
  48. /**
  49. * @param string $name
  50. * @param int|null $boost
  51. * @param array $must
  52. * @param array $should
  53. * @param array $not
  54. * @codeCoverageIgnore
  55. */
  56. public function __construct($name, $boost, array $must = [], array $should = [], array $not = [])
  57. {
  58. $this->name = $name;
  59. $this->boost = $boost;
  60. $this->must = $must;
  61. $this->should = $should;
  62. $this->mustNot = $not;
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function getType()
  68. {
  69. return QueryInterface::TYPE_BOOL;
  70. }
  71. /**
  72. * {@inheritdoc}
  73. * @codeCoverageIgnore
  74. */
  75. public function getName()
  76. {
  77. return $this->name;
  78. }
  79. /**
  80. * {@inheritdoc}
  81. */
  82. public function getBoost()
  83. {
  84. return $this->boost;
  85. }
  86. /**
  87. * Get Should queries
  88. *
  89. * @return QueryInterface[]
  90. * @codeCoverageIgnore
  91. */
  92. public function getShould()
  93. {
  94. return $this->should;
  95. }
  96. /**
  97. * Get Must queries
  98. *
  99. * @return QueryInterface[]
  100. * @codeCoverageIgnore
  101. */
  102. public function getMust()
  103. {
  104. return $this->must;
  105. }
  106. /**
  107. * Get Must Not queries
  108. *
  109. * @return QueryInterface[]
  110. * @codeCoverageIgnore
  111. */
  112. public function getMustNot()
  113. {
  114. return $this->mustNot;
  115. }
  116. }