1
0

SearchRequestSimpleQuery.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Maxence Lange <maxence@artificial-owl.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OC\FullTextSearch\Model;
  26. use JsonSerializable;
  27. use OCP\FullTextSearch\Model\ISearchRequestSimpleQuery;
  28. /**
  29. * @since 17.0.0
  30. *
  31. * Class SearchRequestSimpleQuery
  32. *
  33. * @package OC\FullTextSearch\Model
  34. */
  35. final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonSerializable {
  36. /** @var int */
  37. private $type = 0;
  38. /** @var string */
  39. private $field = '';
  40. /** @var array */
  41. private $values = [];
  42. /**
  43. * SearchRequestQuery constructor.
  44. *
  45. * @param $type
  46. * @param $field
  47. *
  48. * @since 17.0.0
  49. */
  50. public function __construct(string $field, int $type) {
  51. $this->field = $field;
  52. $this->type = $type;
  53. }
  54. /**
  55. * Get the compare type of the query
  56. *
  57. * @return int
  58. * @since 17.0.0
  59. */
  60. public function getType(): int {
  61. return $this->type;
  62. }
  63. /**
  64. * Get the field to apply query
  65. *
  66. * @return string
  67. * @since 17.0.0
  68. */
  69. public function getField(): string {
  70. return $this->field;
  71. }
  72. /**
  73. * Set the field to apply query
  74. *
  75. * @param string $field
  76. *
  77. * @return ISearchRequestSimpleQuery
  78. * @since 17.0.0
  79. */
  80. public function setField(string $field): ISearchRequestSimpleQuery {
  81. $this->field = $field;
  82. return $this;
  83. }
  84. /**
  85. * Get the value to compare (string)
  86. *
  87. * @return array
  88. * @since 17.0.0
  89. */
  90. public function getValues(): array {
  91. return $this->values;
  92. }
  93. /**
  94. * Add value to compare (string)
  95. *
  96. * @param string $value
  97. *
  98. * @return ISearchRequestSimpleQuery
  99. * @since 17.0.0
  100. */
  101. public function addValue(string $value): ISearchRequestSimpleQuery {
  102. $this->values[] = $value;
  103. return $this;
  104. }
  105. /**
  106. * Add value to compare (int)
  107. *
  108. * @param int $value
  109. *
  110. * @return ISearchRequestSimpleQuery
  111. * @since 17.0.0
  112. */
  113. public function addValueInt(int $value): ISearchRequestSimpleQuery {
  114. $this->values[] = $value;
  115. return $this;
  116. }
  117. /**
  118. * Add value to compare (array)
  119. *
  120. * @param array $value
  121. *
  122. * @return ISearchRequestSimpleQuery
  123. * @since 17.0.0
  124. */
  125. public function addValueArray(array $value): ISearchRequestSimpleQuery {
  126. $this->values[] = $value;
  127. return $this;
  128. }
  129. /**
  130. * Add value to compare (bool)
  131. *
  132. * @param bool $value
  133. *
  134. * @return ISearchRequestSimpleQuery
  135. * @since 17.0.0
  136. */
  137. public function addValueBool(bool $value): ISearchRequestSimpleQuery {
  138. $this->values[] = $value;
  139. return $this;
  140. }
  141. /**
  142. * @since 17.0.0
  143. */
  144. public function jsonSerialize(): array {
  145. return [
  146. 'type' => $this->getType(),
  147. 'field' => $this->getField(),
  148. 'values' => $this->getValues()
  149. ];
  150. }
  151. }