DirectGenerator.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace Elastica\Suggest\CandidateGenerator;
  3. /**
  4. * Class DirectGenerator.
  5. *
  6. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html#_direct_generators
  7. */
  8. class DirectGenerator extends AbstractCandidateGenerator
  9. {
  10. const SUGGEST_MODE_MISSING = 'missing';
  11. const SUGGEST_MODE_POPULAR = 'popular';
  12. const SUGGEST_MODE_ALWAYS = 'always';
  13. /**
  14. * @param string $field
  15. */
  16. public function __construct($field)
  17. {
  18. $this->setField($field);
  19. }
  20. /**
  21. * Set the field name from which to fetch candidate suggestions.
  22. *
  23. * @param string $field
  24. *
  25. * @return $this
  26. */
  27. public function setField($field)
  28. {
  29. return $this->setParam('field', $field);
  30. }
  31. /**
  32. * Set the maximum corrections to be returned per suggest text token.
  33. *
  34. * @param int $size
  35. *
  36. * @return $this
  37. */
  38. public function setSize($size)
  39. {
  40. return $this->setParam('size', $size);
  41. }
  42. /**
  43. * @param string $mode see SUGGEST_MODE_* constants for options
  44. *
  45. * @return $this
  46. */
  47. public function setSuggestMode($mode)
  48. {
  49. return $this->setParam('suggest_mode', $mode);
  50. }
  51. /**
  52. * @param int $max can only be a value between 1 and 2. Defaults to 2.
  53. *
  54. * @return $this
  55. */
  56. public function setMaxEdits($max)
  57. {
  58. return $this->setParam('max_edits', $max);
  59. }
  60. /**
  61. * @param int $length defaults to 1
  62. *
  63. * @return $this
  64. */
  65. public function setPrefixLength($length)
  66. {
  67. return $this->setParam('prefix_length', $length);
  68. }
  69. /**
  70. * @param int $min defaults to 4
  71. *
  72. * @return $this
  73. */
  74. public function setMinWordLength($min)
  75. {
  76. return $this->setParam('min_word_length', $min);
  77. }
  78. /**
  79. * @param int $max
  80. *
  81. * @return $this
  82. */
  83. public function setMaxInspections($max)
  84. {
  85. return $this->setParam('max_inspections', $max);
  86. }
  87. /**
  88. * @param float $min
  89. *
  90. * @return $this
  91. */
  92. public function setMinDocFrequency($min)
  93. {
  94. return $this->setParam('min_doc_freq', $min);
  95. }
  96. /**
  97. * @param float $max
  98. *
  99. * @return $this
  100. */
  101. public function setMaxTermFrequency($max)
  102. {
  103. return $this->setParam('max_term_freq', $max);
  104. }
  105. /**
  106. * Set an analyzer to be applied to the original token prior to candidate generation.
  107. *
  108. * @param string $pre an analyzer
  109. *
  110. * @return $this
  111. */
  112. public function setPreFilter($pre)
  113. {
  114. return $this->setParam('pre_filter', $pre);
  115. }
  116. /**
  117. * Set an analyzer to be applied to generated tokens before they are passed to the phrase scorer.
  118. *
  119. * @param string $post
  120. *
  121. * @return $this
  122. */
  123. public function setPostFilter($post)
  124. {
  125. return $this->setParam('post_filter', $post);
  126. }
  127. }