summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Query/SimpleQueryString.php
blob: a6c4ba9d4153b7493a1bcd23906747bcd8769c8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

namespace Elastica\Query;

/**
 * Class SimpleQueryString
 * @package Elastica\Query
 * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html
 */
class SimpleQueryString extends AbstractQuery
{
    const OPERATOR_AND = "and";
    const OPERATOR_OR = "or";

    /**
     * @param string $query
     * @param array $fields
     */
    public function __construct($query, array $fields = array())
    {
        $this->setQuery($query);
        if (sizeof($fields)) {
            $this->setFields($fields);
        }
    }

    /**
     * Set the querystring for this query
     * @param string $query see ES documentation for querystring syntax
     * @return \Elastica\Query\SimpleQueryString
     */
    public function setQuery($query)
    {
        return $this->setParam("query", $query);
    }

    /**
     * @param string[] $fields the fields on which to perform this query. Defaults to index.query.default_field.
     * @return \Elastica\Query\SimpleQueryString
     */
    public function setFields(array $fields)
    {
        return $this->setParam("fields", $fields);
    }

    /**
     * Set the default operator to use if no explicit operator is defined in the query string
     * @param string $operator see OPERATOR_* constants for options
     * @return \Elastica\Query\SimpleQueryString
     */
    public function setDefaultOperator($operator)
    {
        return $this->setParam("default_operator", $operator);
    }

    /**
     * Set the analyzer used to analyze each term of the query
     * @param string $analyzer
     * @return \Elastica\Query\SimpleQueryString
     */
    public function setAnalyzer($analyzer)
    {
        return $this->setParam("analyzer", $analyzer);
    }
}