SearchRequestSimpleQuery.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\FullTextSearch\Model;
  8. use JsonSerializable;
  9. use OCP\FullTextSearch\Model\ISearchRequestSimpleQuery;
  10. /**
  11. * @since 17.0.0
  12. *
  13. * Class SearchRequestSimpleQuery
  14. *
  15. * @package OC\FullTextSearch\Model
  16. */
  17. final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonSerializable {
  18. private array $values = [];
  19. /**
  20. * SearchRequestQuery constructor.
  21. *
  22. * @since 17.0.0
  23. */
  24. public function __construct(
  25. private string $field,
  26. private int $type,
  27. ) {
  28. }
  29. /**
  30. * Get the compare type of the query
  31. *
  32. * @since 17.0.0
  33. */
  34. public function getType(): int {
  35. return $this->type;
  36. }
  37. /**
  38. * Get the field to apply query
  39. *
  40. * @since 17.0.0
  41. */
  42. public function getField(): string {
  43. return $this->field;
  44. }
  45. /**
  46. * Set the field to apply query
  47. *
  48. * @since 17.0.0
  49. */
  50. public function setField(string $field): ISearchRequestSimpleQuery {
  51. $this->field = $field;
  52. return $this;
  53. }
  54. /**
  55. * Get the value to compare (string)
  56. *
  57. * @since 17.0.0
  58. */
  59. public function getValues(): array {
  60. return $this->values;
  61. }
  62. /**
  63. * Add value to compare (string)
  64. *
  65. * @since 17.0.0
  66. */
  67. public function addValue(string $value): ISearchRequestSimpleQuery {
  68. $this->values[] = $value;
  69. return $this;
  70. }
  71. /**
  72. * Add value to compare (int)
  73. *
  74. * @since 17.0.0
  75. */
  76. public function addValueInt(int $value): ISearchRequestSimpleQuery {
  77. $this->values[] = $value;
  78. return $this;
  79. }
  80. /**
  81. * Add value to compare (array)
  82. *
  83. * @since 17.0.0
  84. */
  85. public function addValueArray(array $value): ISearchRequestSimpleQuery {
  86. $this->values[] = $value;
  87. return $this;
  88. }
  89. /**
  90. * Add value to compare (bool)
  91. *
  92. * @since 17.0.0
  93. */
  94. public function addValueBool(bool $value): ISearchRequestSimpleQuery {
  95. $this->values[] = $value;
  96. return $this;
  97. }
  98. /**
  99. * @since 17.0.0
  100. */
  101. public function jsonSerialize(): array {
  102. return [
  103. 'type' => $this->getType(),
  104. 'field' => $this->getField(),
  105. 'values' => $this->getValues()
  106. ];
  107. }
  108. }