1<?php
2
3namespace Elastica\Query;
4
5use Elastica\Document;
6
7/**
8 * Percolate query.
9 *
10 * @author Boris Popovschi <zyqsempai@mail.ru>
11 *
12 * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-percolate-query.html
13 */
14/**
15 * Class Percolate.
16 */
17class Percolate extends AbstractQuery
18{
19    /**
20     * The field of type percolator and that holds the indexed queries. This is a required parameter.
21     *
22     * @param string $field
23     *
24     * @return $this
25     */
26    public function setField(string $field): self
27    {
28        return $this->setParam('field', $field);
29    }
30
31    /**
32     * The source of the document being percolated.
33     *
34     * @param Document|array $document
35     *
36     * @return $this
37     */
38    public function setDocument($document): self
39    {
40        return $this->setParam('document', $document);
41    }
42
43    /**
44     * The index the document resides in.
45     *
46     * @param string $index
47     *
48     * @return $this
49     */
50    public function setDocumentIndex(string $index): self
51    {
52        return $this->setParam('index', $index);
53    }
54
55    /**
56     * The type of the document to fetch.
57     *
58     * @param string $type
59     *
60     * @return $this
61     */
62    public function setExistingDocumentType(string $type): self
63    {
64        return $this->setParam('type', $type);
65    }
66
67    /**
68     * The id of the document to fetch.
69     *
70     * @param int|string $id
71     *
72     * @return $this
73     */
74    public function setDocumentId($id): self
75    {
76        return $this->setParam('id', $id);
77    }
78
79    /**
80     * Optionally, routing to be used to fetch document to percolate.
81     *
82     * @param string $routing
83     *
84     * @return $this
85     */
86    public function setDocumentRouting(string $routing): self
87    {
88        return $this->setParam('routing', $routing);
89    }
90
91    /**
92     * Optionally, preference to be used to fetch document to percolate.
93     *
94     * @param array $preference
95     *
96     * @return $this
97     */
98    public function setDocumentPreference(array $preference): self
99    {
100        return $this->setParam('preference', $preference);
101    }
102
103    /**
104     * Optionally, the expected version of the document to be fetched.
105     *
106     * @param int $version
107     *
108     * @return $this
109     */
110    public function setDocumentVersion(int $version): self
111    {
112        return $this->setParam('version', $version);
113    }
114}
115