SearchRequestSimpleQuery.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. private array $values = [];
  37. /**
  38. * SearchRequestQuery constructor.
  39. *
  40. * @since 17.0.0
  41. */
  42. public function __construct(
  43. private string $field,
  44. private int $type,
  45. ) {
  46. }
  47. /**
  48. * Get the compare type of the query
  49. *
  50. * @since 17.0.0
  51. */
  52. public function getType(): int {
  53. return $this->type;
  54. }
  55. /**
  56. * Get the field to apply query
  57. *
  58. * @since 17.0.0
  59. */
  60. public function getField(): string {
  61. return $this->field;
  62. }
  63. /**
  64. * Set the field to apply query
  65. *
  66. * @since 17.0.0
  67. */
  68. public function setField(string $field): ISearchRequestSimpleQuery {
  69. $this->field = $field;
  70. return $this;
  71. }
  72. /**
  73. * Get the value to compare (string)
  74. *
  75. * @since 17.0.0
  76. */
  77. public function getValues(): array {
  78. return $this->values;
  79. }
  80. /**
  81. * Add value to compare (string)
  82. *
  83. * @since 17.0.0
  84. */
  85. public function addValue(string $value): ISearchRequestSimpleQuery {
  86. $this->values[] = $value;
  87. return $this;
  88. }
  89. /**
  90. * Add value to compare (int)
  91. *
  92. * @since 17.0.0
  93. */
  94. public function addValueInt(int $value): ISearchRequestSimpleQuery {
  95. $this->values[] = $value;
  96. return $this;
  97. }
  98. /**
  99. * Add value to compare (array)
  100. *
  101. * @since 17.0.0
  102. */
  103. public function addValueArray(array $value): ISearchRequestSimpleQuery {
  104. $this->values[] = $value;
  105. return $this;
  106. }
  107. /**
  108. * Add value to compare (bool)
  109. *
  110. * @since 17.0.0
  111. */
  112. public function addValueBool(bool $value): ISearchRequestSimpleQuery {
  113. $this->values[] = $value;
  114. return $this;
  115. }
  116. /**
  117. * @since 17.0.0
  118. */
  119. public function jsonSerialize(): array {
  120. return [
  121. 'type' => $this->getType(),
  122. 'field' => $this->getField(),
  123. 'values' => $this->getValues()
  124. ];
  125. }
  126. }