Term.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace Elastica\Suggest;
  3. /**
  4. * Class Term.
  5. *
  6. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-term.html
  7. */
  8. class Term extends AbstractSuggest
  9. {
  10. const SORT_SCORE = 'score';
  11. const SORT_FREQUENCY = 'frequency';
  12. const SUGGEST_MODE_MISSING = 'missing';
  13. const SUGGEST_MODE_POPULAR = 'popular';
  14. const SUGGEST_MODE_ALWAYS = 'always';
  15. /**
  16. * @param string $analyzer
  17. *
  18. * @return $this
  19. */
  20. public function setAnalyzer($analyzer)
  21. {
  22. return $this->setParam('analyzer', $analyzer);
  23. }
  24. /**
  25. * @param string $sort see SORT_* constants for options
  26. *
  27. * @return $this
  28. */
  29. public function setSort($sort)
  30. {
  31. return $this->setParam('sort', $sort);
  32. }
  33. /**
  34. * @param string $mode see SUGGEST_MODE_* constants for options
  35. *
  36. * @return $this
  37. */
  38. public function setSuggestMode($mode)
  39. {
  40. return $this->setParam('suggest_mode', $mode);
  41. }
  42. /**
  43. * If true, suggest terms will be lower cased after text analysis.
  44. *
  45. * @param bool $lowercase
  46. *
  47. * @return $this
  48. */
  49. public function setLowercaseTerms($lowercase = true)
  50. {
  51. return $this->setParam('lowercase_terms', (bool) $lowercase);
  52. }
  53. /**
  54. * Set the maximum edit distance candidate suggestions can have in order to be considered as a suggestion.
  55. *
  56. * @param int $max Either 1 or 2. Any other value will result in an error.
  57. *
  58. * @return $this
  59. */
  60. public function setMaxEdits($max)
  61. {
  62. return $this->setParam('max_edits', (int) $max);
  63. }
  64. /**
  65. * The number of minimum prefix characters that must match in order to be a suggestion candidate.
  66. *
  67. * @param int $length defaults to 1
  68. *
  69. * @return $this
  70. */
  71. public function setPrefixLength($length)
  72. {
  73. return $this->setParam('prefix_len', (int) $length);
  74. }
  75. /**
  76. * The minimum length a suggest text term must have in order to be included.
  77. *
  78. * @param int $length defaults to 4
  79. *
  80. * @return $this
  81. */
  82. public function setMinWordLength($length)
  83. {
  84. return $this->setParam('min_word_length', (int) $length);
  85. }
  86. /**
  87. * @param int $max defaults to 5
  88. *
  89. * @return $this
  90. */
  91. public function setMaxInspections($max)
  92. {
  93. return $this->setParam('max_inspections', $max);
  94. }
  95. /**
  96. * Set the minimum number of documents in which a suggestion should appear.
  97. *
  98. * @param int|float $min Defaults to 0. If the value is greater than 1, it must be a whole number.
  99. *
  100. * @return $this
  101. */
  102. public function setMinDocFrequency($min)
  103. {
  104. return $this->setParam('min_doc_freq', $min);
  105. }
  106. /**
  107. * Set the maximum number of documents in which a suggest text token can exist in order to be included.
  108. *
  109. * @param float $max
  110. *
  111. * @return $this
  112. */
  113. public function setMaxTermFrequency($max)
  114. {
  115. return $this->setParam('max_term_freq', $max);
  116. }
  117. /**
  118. * Which string distance implementation to use for comparing how similar suggested terms are.
  119. * Five possible values can be specified:.
  120. *
  121. * - internal
  122. * - damerau_levenshtein
  123. * - levenshtein
  124. * - jaro_winkler
  125. * - ngram
  126. *
  127. * @param string $distanceAlgrorithm
  128. *
  129. * @return $this
  130. */
  131. public function setStringDistanceAlgorithm($distanceAlgorithm)
  132. {
  133. return $this->setParam('string_distance', $distanceAlgorithm);
  134. }
  135. }