Indices.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Elastica\Query;
  3. use Elastica\Index as ElasticaIndex;
  4. trigger_error('Elastica\Query\Indices is deprecated and will be removed in further Elastica releases. Search on the _index field instead.', E_USER_DEPRECATED);
  5. /**
  6. * Class Indices.
  7. *
  8. * @deprecated Search on the _index field instead
  9. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-indices-query.html
  10. */
  11. class Indices extends AbstractQuery
  12. {
  13. /**
  14. * @param AbstractQuery $query Query which will be applied to docs in the specified indices
  15. * @param mixed[] $indices
  16. */
  17. public function __construct(AbstractQuery $query, array $indices)
  18. {
  19. $this->setIndices($indices)->setQuery($query);
  20. }
  21. /**
  22. * Set the indices on which this query should be applied.
  23. *
  24. * @param mixed[] $indices
  25. *
  26. * @return $this
  27. */
  28. public function setIndices(array $indices)
  29. {
  30. $this->setParam('indices', []);
  31. foreach ($indices as $index) {
  32. $this->addIndex($index);
  33. }
  34. return $this;
  35. }
  36. /**
  37. * Adds one more index on which this query should be applied.
  38. *
  39. * @param string|\Elastica\Index $index
  40. *
  41. * @return $this
  42. */
  43. public function addIndex($index)
  44. {
  45. if ($index instanceof ElasticaIndex) {
  46. $index = $index->getName();
  47. }
  48. return $this->addParam('indices', (string) $index);
  49. }
  50. /**
  51. * Set the query to be applied to docs in the specified indices.
  52. *
  53. * @param AbstractQuery $query
  54. *
  55. * @return $this
  56. */
  57. public function setQuery(AbstractQuery $query)
  58. {
  59. return $this->setParam('query', $query);
  60. }
  61. /**
  62. * Set the query to be applied to docs in indices which do not match those specified in the "indices" parameter.
  63. *
  64. * @param AbstractQuery $query
  65. *
  66. * @return $this
  67. */
  68. public function setNoMatchQuery(AbstractQuery $query)
  69. {
  70. return $this->setParam('no_match_query', $query);
  71. }
  72. }