File: Index.php

package info (click to toggle)
php-horde-elasticsearch 1.0.4-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 108 kB
  • sloc: xml: 197; php: 162; makefile: 2
file content (97 lines) | stat: -rw-r--r-- 2,205 bytes parent folder | download | duplicates (2)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
 * Copyright 2011-2017 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file LICENSE for license information (BSD). If you
 * did not receive this file, see http://www.horde.org/licenses/bsd.
 *
 * @author   Chuck Hagenbuch <chuck@horde.org>
 * @category Horde
 * @license  http://www.horde.org/licenses/bsd BSD
 * @package  ElasticSearch
 */

/**
 * ElasticSearch index class
 *
 * @author    Chuck Hagenbuch <chuck@horde.org>
 * @category  Horde
 * @copyright 2011-2017 Horde LLC
 * @license   http://www.horde.org/licenses/bsd BSD
 * @package   ElasticSearch
 */
class Horde_ElasticSearch_Index
{
    protected $_client;
    protected $_index;

    public function __construct($index, Horde_ElasticSearch_Client $client)
    {
        $this->_index = $index;
        $this->_client = $client;
    }

    /**
     * curl -X PUT {SERVER}/{INDEX}/
     */
    public function create()
    {
        $this->_client->request(null, 'PUT');
    }

    /**
     * curl -X DELETE {SERVER}/{INDEX}/
     */
    public function drop()
    {
        $this->_client->request(null, 'DELETE');
    }

    /**
     * curl -X GET {SERVER}/{INDEX}/_status
     */
    public function status()
    {
        return $this->_client->status($this->_index);
    }

    /**
     * curl -X GET {SERVER}/{INDEX}/{TYPE}/_search?q= ...
     */
    public function search($type, $q)
    {
        return $this->_client->search($this->_index, $type, $q);
    }

    /**
     * curl -XGET {SERVER}/{INDEX}/{TYPE/{ID}
     */
    public function get($type, $id)
    {
        return $this->_client->get($this->_index, $type, $id);
    }

    /**
     * curl -X PUT {SERVER}/{INDEX}/{TYPE}/{ID} -d ...
     */
    public function add($type, $id, $data)
    {
        return $this->_client->add($this->_index, $type, $id, $data);
    }

    /**
     * curl -X GET {SERVER}/{INDEX}/{TYPE}/_count -d {matchAll:{}}
     */
    public function count($type)
    {
        return $this->_client->count($this->_index, $type);
    }

    /**
     * curl -X PUT {SERVER}/{INDEX}/{TYPE}/_mapping -d ...
     */
    public function map($type, $data)
    {
        return $this->_client->map($this->_index, $type, $data);
    }
}