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