1<?php
2
3namespace Elastica;
4
5use Elastica\Exception\ClientException;
6use Elastica\Exception\ConnectionException;
7use Elastica\Exception\InvalidException;
8use Elastica\Exception\ResponseException;
9use Elastica\Query\AbstractQuery;
10use Elastica\Suggest\AbstractSuggest;
11
12/**
13 * Elastica searchable interface.
14 *
15 * @author Thibault Duplessis <thibault.duplessis@gmail.com>
16 * @phpstan-import-type TCreateQueryArgs from Query
17 * @phpstan-import-type TCreateQueryArgsMatching from Query
18 */
19interface SearchableInterface
20{
21    /**
22     * Searches results for a query.
23     *
24     * {
25     *     "from" : 0,
26     *     "size" : 10,
27     *     "sort" : {
28     *          "postDate" : {"order" : "desc"},
29     *          "user" : { },
30     *          "_score" : { }
31     *      },
32     *      "query" : {
33     *          "term" : { "user" : "kimchy" }
34     *      }
35     * }
36     *
37     * @param AbstractQuery|AbstractSuggest|array|Collapse|Query|string|Suggest|null $query Array with all query data inside or a Elastica\Query object
38     * @phpstan-param TCreateQueryArgs $query
39     *
40     * @param array|int|null $options Limit or associative array of options (option=>value)
41     * @param string         $method  Request method, see Request's constants
42     *
43     * @throws ClientException
44     * @throws ConnectionException
45     * @throws InvalidException
46     * @throws ResponseException
47     */
48    public function search($query = '', $options = null, string $method = Request::POST): ResultSet;
49
50    /**
51     * Counts results for a query.
52     *
53     * If no query is set, matchall query is created
54     *
55     * @param AbstractQuery|array|Query|string|null $query Array with all query data inside or a Elastica\Query object
56     * @phpstan-param TCreateQueryArgsMatching $query
57     *
58     * @param string $method Request method, see Request's constants
59     *
60     * @throws ClientException
61     * @throws ConnectionException
62     * @throws ResponseException
63     *
64     * @return int number of documents matching the query
65     */
66    public function count($query = '', string $method = Request::POST);
67
68    /**
69     * @param AbstractQuery|AbstractSuggest|array|Collapse|Query|string|Suggest|null $query
70     * @phpstan-param TCreateQueryArgs $query
71     *
72     * @param array|int|null $options
73     */
74    public function createSearch($query = '', $options = null): Search;
75}
76