1<?php
2
3namespace Elastica\QueryBuilder\DSL;
4
5use Elastica\Exception\NotImplementedException;
6use Elastica\QueryBuilder\DSL;
7use Elastica\Suggest\Completion;
8use Elastica\Suggest\Phrase;
9use Elastica\Suggest\Term;
10
11/**
12 * elasticsearch suggesters DSL.
13 *
14 * @author Manuel Andreo Garcia <andreo.garcia@googlemail.com>
15 *
16 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html
17 */
18class Suggest implements DSL
19{
20    /**
21     * must return type for QueryBuilder usage.
22     *
23     * @return string
24     */
25    public function getType(): string
26    {
27        return self::TYPE_SUGGEST;
28    }
29
30    /**
31     * term suggester.
32     *
33     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-term.html
34     *
35     * @param $name
36     * @param $field
37     *
38     * @return Term
39     */
40    public function term($name, $field): Term
41    {
42        return new Term($name, $field);
43    }
44
45    /**
46     * phrase suggester.
47     *
48     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html
49     *
50     * @param $name
51     * @param $field
52     *
53     * @return Phrase
54     */
55    public function phrase($name, $field): Phrase
56    {
57        return new Phrase($name, $field);
58    }
59
60    /**
61     * completion suggester.
62     *
63     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html
64     *
65     * @param string $name
66     * @param string $field
67     *
68     * @return Completion
69     */
70    public function completion($name, $field): Completion
71    {
72        return new Completion($name, $field);
73    }
74
75    /**
76     * context suggester.
77     *
78     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/suggester-context.html
79     */
80    public function context()
81    {
82        throw new NotImplementedException();
83    }
84}
85