Author: mj
Date: Fri Jan 27 10:02:00 2012
New Revision: 10755

Log:
#2199 - Update Elastica library to 0.18.6.

Added:
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Filter/Nested.php
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Percolator.php
Modified:
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Client.php
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Cluster.php
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Document.php
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Filter/Term.php
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Index.php
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Query.php
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Query/Term.php
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Request.php
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Response.php
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Search.php
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Transport/Http.php
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Type.php

Modified: trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Client.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Client.php  Fri Jan 
27 00:04:10 2012        (r10754)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Client.php  Fri Jan 
27 10:02:00 2012        (r10755)
@@ -61,7 +61,7 @@
         *
         * @param array $config Params
         */
-       public function setConfig($config) {
+       public function setConfig(array $config) {
                foreach ($config as $key => $value) {
                        $this->_config[$key] = $value;
                }
@@ -243,8 +243,8 @@
         * Deletes documents with the given ids, index, type from the index
         *
         * @param array $ids Document ids
-        * @param string $index Index name
-        * @param string $type Type of documents
+        * @param string|Elastica_Index $index Index name
+        * @param string|Elastica_Type $type Type of documents
         * @return Elastica_Response Response object
         * @throws Elastica_Exception If ids is empty
         * @link http://www.elasticsearch.com/docs/elasticsearch/rest_api/bulk/

Modified: trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Cluster.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Cluster.php Fri Jan 
27 00:04:10 2012        (r10754)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Cluster.php Fri Jan 
27 10:02:00 2012        (r10755)
@@ -43,7 +43,7 @@
         * Returns the full state of the cluster
         *
         * @return array State array
-        * @link 
http://www.elasticsearch.com/docs/elasticsearch/rest_api/admin/cluster/state
+        * @link 
http://www.elasticsearch.org/guide/reference/api/admin-cluster-state.html
         */
        public function getState() {
                return $this->_data;

Modified: trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Document.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Document.php        
Fri Jan 27 00:04:10 2012        (r10754)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Document.php        
Fri Jan 27 10:02:00 2012        (r10755)
@@ -3,8 +3,8 @@
  * Single document stored in elastic search
  *
  * @category Xodoa
- * @package Elastica
- * @author Nicolas Ruflin <[email protected]>
+ * @package  Elastica
+ * @author   Nicolas Ruflin <[email protected]>
  */
 class Elastica_Document {
 
@@ -27,18 +27,23 @@
         * @var string|int Parent document id
         */
        protected $_parent = '';
-       
+
        /**
         * @var string Optype
         */
        protected $_optype = '';
 
        /**
+        * @var string Percolate
+        */
+       protected $_percolate = '';
+
+       /**
         * Creates a new document
         *
-        * @param int $id OPTIONAL $id Id is create if empty
-        * @param array $data OPTIONAL Data array
-        * @param string $type OPTIONAL Type name
+        * @param int    $id    OPTIONAL $id Id is create if empty
+        * @param array  $data  OPTIONAL Data array
+        * @param string $type  OPTIONAL Type name
         * @param string $index OPTIONAL Index name
         */
        public function __construct($id = '', array $data = array(), $type = 
'', $index = '') {
@@ -60,8 +65,8 @@
        /**
         * Adds the given key/value pair to the document
         *
-        * @param string $key Document entry key
-        * @param mixed $value Document entry value
+        * @param string $key   Document entry key
+        * @param mixed  $value Document entry value
         * @return Elastica_Document
         */
        public function add($key, $value) {
@@ -80,7 +85,7 @@
         * This installs the tika file analysis plugin. More infos about 
supported formats
         * can be found here: {@link http://tika.apache.org/0.7/formats.html}
         *
-        * @param string $key Key to add the file to
+        * @param string $key      Key to add the file to
         * @param string $filepath Path to add the file
         * @param string $mimeType OPTIONAL Header mime type
         * @return Elastica_Document
@@ -89,11 +94,7 @@
                $value = base64_encode(file_get_contents($filepath));
 
                if (!empty($mimeType)) {
-                       $value = array(
-                               '_content_type' => $mimeType,
-                               '_name' => $filepath,
-                               'content' => $value,
-                       );
+                       $value = array('_content_type' => $mimeType, '_name' => 
$filepath, 'content' => $value,);
                }
 
                $this->add($key, $value);
@@ -101,22 +102,28 @@
        }
 
        /**
+        * @param string $key     Document key
+        * @param string $content Raw file content
+        * @return Elastica_Document
+        */
+       public function addFileContent($key, $content) {
+               return $this->add($key, base64_encode($content));
+       }
+
+       /**
         * Adds a geopoint to the document
         *
         * Geohashes re not yet supported
         *
-        * @param string $key Field key
-        * @param float $latitude Latitud value
-        * @param float $longitude Longitude value
+        * @param string $key       Field key
+        * @param float  $latitude  Latitud value
+        * @param float  $longitude Longitude value
         * @link 
http://www.elasticsearch.com/docs/elasticsearch/mapping/geo_point/
         * @return Elastica_Document
         */
        public function addGeoPoint($key, $latitude, $longitude) {
 
-               $value = array(
-                       'lat' => $latitude,
-                       'lon' => $longitude,
-               );
+               $value = array('lat' => $latitude, 'lon' => $longitude,);
 
                $this->add($key, $value);
                return $this;
@@ -135,14 +142,14 @@
 
        /**
         * Sets lifetime of document
-        * 
+        *
         * @param string $ttl
         * @return Elastica_Document
         */
        public function setTTL($ttl) {
                return $this->add('_ttl', $ttl);
        }
-       
+
        /**
         * Returns the document data
         *
@@ -208,7 +215,7 @@
         * @link http://www.elasticsearch.org/blog/2011/02/08/versioning.html
         */
        public function setVersion($version) {
-               if($version !== '') {
+               if ($version !== '') {
                        $this->_version = (int) $version;
                }
                return $this;
@@ -261,28 +268,44 @@
        public function getOpType() {
                return $this->_optype;
        }
-       
+
+       /**
+        * Set percolate query param
+        *
+        * @param string $value percolator filter
+        * @return Elastica_Document
+        */
+       public function setPercolate($value = '*') {
+               $this->_percolate = $value;
+               return $this;
+       }
+
+       /**
+        * Get percolate parameter
+        *
+        * @return string
+        */
+       public function getPercolate() {
+               return $this->_percolate;
+       }
+
        /**
         * Returns the document as an array
         * @return array
         */
        public function toArray() {
-               $index = array(
-                       '_index' => $this->getIndex(),
-                       '_type' => $this->getType(),
-                       '_id' => $this->getId()
-               );
-               
+               $index = array('_index' => $this->getIndex(), '_type' => 
$this->getType(), '_id' => $this->getId());
+
                $version = $this->getVersion();
                if (!empty($version)) {
                        $index['_version'] = $version;
                }
-               
+
                $parent = $this->getParent();
                if (!empty($parent)) {
                        $index['_parent'] = $parent;
                }
-               
+
                $params[] = $action;
                $params[] = $doc->getData();
        }

Added: trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Filter/Nested.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Filter/Nested.php   
Fri Jan 27 10:02:00 2012        (r10755)
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Nested filter
+ *
+ * @uses Elastica_Filter_Abstract
+ * @category Xodoa
+ * @package Elastica
+ * @author Nicolas Ruflin <[email protected]>
+ * @link 
http://www.elasticsearch.org/guide/reference/query-dsl/nested-filter.html
+ */
+class Elastica_Filter_Nested extends Elastica_Filter_Abstract
+{
+       /**
+        * Adds field to mlt filter
+        *
+        * @param string $path Nested object path
+        * @return Elastica_Filter_Nested
+        */
+       public function setPath($path) {
+               return $this->setParam('path', $path);
+       }
+       
+       /**
+        * Sets nested filter
+        * 
+        * @param Elastica_Filter_Abstract $filter
+        * @return Elastica_Filter_Nested
+        */
+       public function setFilter(Elastica_Filter_Abstract $filter) {
+               return $this->setParam('query', $filter->toArray());
+       }
+       
+       /**
+        * @param string $scoreMode Options: avg, total, max and none.
+        * @return Elastica_Filter_Nested
+        */
+       public function setScoreMode($scoreMode) {
+               return $this->setParam('score_mode', $scoreMode);
+       }
+}

Modified: 
trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Filter/Term.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Filter/Term.php     
Fri Jan 27 00:04:10 2012        (r10754)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Filter/Term.php     
Fri Jan 27 10:02:00 2012        (r10755)
@@ -10,13 +10,11 @@
  */
 class Elastica_Filter_Term extends Elastica_Filter_Abstract
 {
-       protected $_term = array();
-
        /**
         * @param array $term Term array
         */
        public function __construct(array $term = array()) {
-               $this->setTerm($term);
+               $this->setRawTerm($term);
        }
 
        /**
@@ -25,9 +23,8 @@
         * @param array $term Key value pair
         * @return Elastica_Filter_Term Filter object
         */
-       public function setTerm(array $term) {
-               $this->_term = $term;
-               return $this;
+       public function setRawTerm(array $term) {
+               return $this->setParams($term);
        }
 
        /**
@@ -37,20 +34,7 @@
         * @param string|array $value Values(s) for the query. Boost can be set 
with array
         * @return Elastica_Filter_Term Filter object
         */
-       public function addTerm($key, $value) {
-               $this->_term = array($key => $value);
-               return $this;
-       }
-
-       /**
-        * Convers filter to array
-        *
-        * @see Elastica_Filter_Abstract::toArray()
-        * @return array Data array
-        */
-       public function toArray() {
-               $args = $this->_term;
-
-               return array('term' => $args);
+       public function setTerm($key, $value) {
+               return $this->setRawTerm(array($key => $value));
        }
 }

Modified: trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Index.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Index.php   Fri Jan 
27 00:04:10 2012        (r10754)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Index.php   Fri Jan 
27 10:02:00 2012        (r10755)
@@ -144,11 +144,16 @@
         * Searchs in this index
         *
         * @param string|array|Elastica_Query $query Array with all query data 
inside or a Elastica_Query object
+        * @param int $limit OPTIONAL
         * @return Elastica_ResultSet ResultSet with all results inside
         * @see Elastica_Searchable::search
         */
-       public function search($query) {
+       public function search($query, $limit = 0) {
                $query = Elastica_Query::create($query);
+               
+               if ($limit) {
+                       $query->setLimit($limit);
+               }
                $path = '_search';
 
                $response = $this->request($path, Elastica_Request::GET, 
$query->toArray());

Added: trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Percolator.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Percolator.php      
Fri Jan 27 10:02:00 2012        (r10755)
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Percolator class
+ *
+ * @category Xodoa
+ * @package Elastica
+ * @author Nicolas Ruflin <[email protected]>
+ * @link http://www.elasticsearch.org/guide/reference/api/percolate.html
+ */
+class Elastica_Percolator
+{
+       /**
+        * @var Elastica_Index
+        */
+       protected $_index = null;
+
+       /**
+        * @param Elastica_Index $index
+        */
+       public function __construct(Elastica_Index $index) {
+               $this->_index = $index;
+       }
+       
+       /**
+        * Registers a percolator query
+        * 
+        * @param string $name Query name
+        * @param string|Elastica_Query|Elastica_Query_Abstract $query Query to 
add
+        * @return Elastica_Resonse
+        */
+       public function registerQuery($name, $query) {
+               $path = '_percolator/' . $this->_index->getName() . '/' . $name;
+               $query = Elastica_Query::create($query);
+               return $this->_index->getClient()->request($path, 
Elastica_Request::PUT, $query->toArray());
+       }
+       
+       /**
+        * Match a document to percolator queries
+        * 
+        * @param Elastica_Document $doc
+        * @param string|Elastica_Query|Elastica_Query_Abstract $query Not 
implemented yet
+        * @return Elastica_Resonse
+        */
+       public function matchDoc(Elastica_Document $doc, $query = null) {
+               $path = $this->_index->getName() . '/type/_percolate';
+               $data = array('doc' => $doc->getData());
+               
+               $response = $this->getIndex()->getClient()->request($path, 
Elastica_Request::GET, $data);
+               $data = $response->getData();
+               
+               return $data['matches'];
+       }
+       
+       /**
+        * @return Elastica_Index
+        */
+       public function getIndex() {
+               return $this->_index;
+       }
+}
\ No newline at end of file

Modified: trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Query.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Query.php   Fri Jan 
27 00:04:10 2012        (r10754)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Query.php   Fri Jan 
27 10:02:00 2012        (r10755)
@@ -120,6 +120,7 @@
         *
         * @param mixed $sort Sort parameter
         * @return Elastica_Query Query object
+        * @link 
http://www.elasticsearch.org/guide/reference/api/search/sort.html
         */
        public function addSort($sort) {
                return $this->addParam('sort', $sort);
@@ -160,6 +161,8 @@
        /**
         * Sets maximum number of results for this query
         *
+        * Setting the limit to 0, means no limit
+        *
         * @param int $limit OPTIONAL Maximal number of results for query 
(default = 10)
         * @return Elastica_Query Query object
         */

Modified: trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Query/Term.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Query/Term.php      
Fri Jan 27 00:04:10 2012        (r10754)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Query/Term.php      
Fri Jan 27 10:02:00 2012        (r10755)
@@ -10,15 +10,13 @@
  */
 class Elastica_Query_Term extends Elastica_Query_Abstract
 {
-       protected $_term = array();
-
        /**
         * Constructs the Term query object
         *
         * @param array $term OPTIONAL Calls setTerm with the given $term array
         */
        public function __construct(array $term = array()) {
-               $this->setTerm($term);
+               $this->setRawTerm($term);
        }
 
        /**
@@ -28,9 +26,8 @@
         * @param array $term Term array
         * @return Elastica_Query_Term Current object
         */
-       public function setTerm(array $term) {
-               $this->_term = $term;
-               return $this;
+       public function setRawTerm(array $term) {
+               return $this->setParams($term);
        }
 
        /**
@@ -41,19 +38,7 @@
         * @param float $boost OPTIONAL Boost value (default = 1.0)
         * @return Elastica_Query_Term Current object
         */
-       public function addTerm($key, $value, $boost = 1.0) {
-               // TODO: Why is return $this->setTerm(array($key => 
array('value' => $value, 'boost' => $boost)));
-               //              not working? Tested with filer
-               return $this->setTerm(array($key => $value));
-       }
-
-       /**
-        * Converts the term query to an array
-        *
-        * @return array Array term query
-        */
-       public function toArray() {
-               $args = $this->_term;
-               return array('term' => $args);
+       public function setTerm($key, $value, $boost = 1.0) {
+               return $this->setRawTerm(array($key => array('value' => $value, 
'boost' => $boost)));
        }
 }

Modified: trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Request.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Request.php Fri Jan 
27 00:04:10 2012        (r10754)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Request.php Fri Jan 
27 10:02:00 2012        (r10755)
@@ -134,10 +134,24 @@
                $transport = $this->getTransport();
 
                $servers = $this->getClient()->getConfig('servers');
+               
+               /*$dir = sys_get_temp_dir();
+               $name = 'elasticaServers.json';
+               $file = $dir . DIRECTORY_SEPARATOR . $name;
+               
+               error_log($file);
 
+               if (!file_exists($file)) {
+                       file_put_contents($file, 'hh');
+                       error_log(print_r($this->getClient()->getCluster(), 
true));
+               }*/
+               
+               
                if (empty($servers)) {
                        $response = 
$transport->exec($this->getClient()->getHost(), $this->getClient()->getPort());
                } else {
+                       
+       
                        // Set server id for first request (round robin by 
default)
                        if (is_null(self::$_serverId)) {
                                self::$_serverId = rand(0, count($servers) - 1);

Modified: trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Response.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Response.php        
Fri Jan 27 00:04:10 2012        (r10754)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Response.php        
Fri Jan 27 10:02:00 2012        (r10755)
@@ -120,9 +120,8 @@
                return $this;
        }
 
-
        /**
-        * @return int
+        * @return int Time request took
         */
        public function getEngineTime() {
                $data = $this->getData();
@@ -131,14 +130,13 @@
                        throw new Elastica_Exception_NotFound("Unable to find 
the field [took]from the response");
                }
 
-               return  $data['took'];
+               return $data['took'];
        }
 
-
        /**
         * Get the _shard statistics for the response
         *
-        * @return void
+        * @return array
         */
        public function getShardsStatistics() {
                $data = $this->getData();

Modified: trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Search.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Search.php  Fri Jan 
27 00:04:10 2012        (r10754)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Search.php  Fri Jan 
27 10:02:00 2012        (r10755)
@@ -3,11 +3,10 @@
  * Elastica search object
  *
  * @category Xodoa
- * @package Elastica
- * @author Nicolas Ruflin <[email protected]>
+ * @package  Elastica
+ * @author   Nicolas Ruflin <[email protected]>
  */
-class Elastica_Search
-{
+class Elastica_Search {
        protected $_indices = array();
        protected $_types = array();
 
@@ -46,6 +45,20 @@
        }
 
        /**
+        * Add array of indices at once
+        *
+        * @param array $indices
+        * @return Elastica_Search
+        */
+       public function addIndices(array $indices = array()) {
+               foreach ($indices as $index) {
+                       $this->addIndex($index);
+               }
+
+               return $this;
+       }
+
+       /**
         * Adds a type to the current search
         *
         * @param Elastica_Type|string $type Type name or object
@@ -67,6 +80,20 @@
        }
 
        /**
+        * Add array of types
+        *
+        * @param array $types
+        * @return Elastica_Search
+        */
+       public function addTypes(array $types = array()) {
+               foreach ($types as $type) {
+                       $this->addType($type);
+               }
+
+               return $this;
+       }
+
+       /**
         * @return Elastica_Client Client object
         */
        public function getClient() {
@@ -129,10 +156,14 @@
         * Search in the set indices, types
         *
         * @param mixed $query
+        * @param int   $limit OPTIONAL
         * @return Elastica_ResultSet
         */
-       public function search($query) {
+       public function search($query, $limit = 0) {
                $query = Elastica_Query::create($query);
+               if ($limit) {
+                       $query->setLimit($limit);
+               }
                $path = $this->getPath();
 
                $response = $this->getClient()->request($path, 
Elastica_Request::GET, $query->toArray());

Modified: 
trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Transport/Http.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Transport/Http.php  
Fri Jan 27 00:04:10 2012        (r10754)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Transport/Http.php  
Fri Jan 27 10:02:00 2012        (r10755)
@@ -71,8 +71,6 @@
                        curl_setopt($conn, CURLOPT_POSTFIELDS, $content);
                }
 
-
-
                $start = microtime(true);
                $responseString = curl_exec($conn);
                $end = microtime(true);

Modified: trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Type.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Type.php    Fri Jan 
27 00:04:10 2012        (r10754)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Type.php    Fri Jan 
27 10:02:00 2012        (r10755)
@@ -9,30 +9,29 @@
  * Search over different indices and types is not supported yet {@link 
http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/indices_types/}
  *
  * @category Xodoa
- * @package Elastica
- * @author Nicolas Ruflin <[email protected]>
+ * @package  Elastica
+ * @author   Nicolas Ruflin <[email protected]>
  */
-class Elastica_Type implements Elastica_Searchable
-{
+class Elastica_Type implements Elastica_Searchable {
        /**
         * @var Elastica_Index Index object
         */
        protected $_index = null;
 
        /**
-        * @var string Object type
+        * @var string Type name
         */
-       protected $_type = '';
+       protected $_name = '';
 
        /**
         * Creates a new type object inside the given index
         *
         * @param Elastica_Index $index Index Object
-        * @param string $type Type name
+        * @param string         $name  Type name
         */
-       public function __construct(Elastica_Index $index, $type) {
+       public function __construct(Elastica_Index $index, $name) {
                $this->_index = $index;
-               $this->_type = $type;
+               $this->_name = $name;
        }
 
        /**
@@ -46,18 +45,23 @@
                $path = $doc->getId();
 
                $query = array();
-               
+
                if ($doc->getVersion() > 0) {
                        $query['version'] = $doc->getVersion();
                }
-               
+
                if ($doc->getParent()) {
                        $query['parent'] = $doc->getParent();
                }
-               
+
                if ($doc->getOpType()) {
                        $query['op_type'] = $doc->getOpType();
                }
+
+               if ($doc->getPercolate()) {
+                       $query['percolate'] = $doc->getPercolate();
+               }
+
                if (count($query) > 0) {
                        $path .= '?' . http_build_query($query);
                }
@@ -75,13 +79,13 @@
        /**
         * Uses _bulk to send documents to the server
         *
-        * @param array $docs Array of Elastica_Document
+        * @param Elastica_Document[] $docs Array of Elastica_Document
         * @link http://www.elasticsearch.com/docs/elasticsearch/rest_api/bulk/
         */
        public function addDocuments(array $docs) {
 
-               foreach($docs as $doc) {
-                       $doc->setType($this->getType());
+               foreach ($docs as $doc) {
+                       $doc->setType($this->getName());
                }
 
                return $this->getIndex()->addDocuments($docs);
@@ -96,39 +100,44 @@
        public function getDocument($id) {
                $path = $id;
 
-               $result = $this->request($path, 
Elastica_Request::GET)->getData();
+               try {
+                       $result = $this->request($path, 
Elastica_Request::GET)->getData();
+               } catch (Elastica_Exception_Response $e) {
+                       throw new Elastica_Exception_NotFound('doc id ' . $id . 
' not found');
+               }
 
                if (empty($result['exists'])) {
                        throw new Elastica_Exception_NotFound('doc id ' . $id . 
' not found');
                }
 
-               $data = isset($result['_source'])?$result['_source']:array();
-               $document = new Elastica_Document($id, $data, $this->getType(), 
 $this->getIndex());
+               $data = isset($result['_source']) ? $result['_source'] : 
array();
+               $document = new Elastica_Document($id, $data, $this->getName(), 
$this->getIndex());
                $document->setVersion($result['_version']);
                return $document;
        }
 
        /**
-        * @return string Type name
-        */
-       public function getName() {
-               return $this->getType();
-       }
-
-       /**
         * Returns the type name
         *
         * @return string Type
+        * @deprecated Use getName instead
         */
        public function getType() {
-               return $this->_type;
+               return $this->getName();
+       }
+
+       /**
+        * @return string Type name
+        */
+       public function getName() {
+               return $this->_name;
        }
 
        /**
         * Sets value type mapping for this type
         *
         * @param Elastica_Type_Mapping|array $mapping Elastica_Type_Mapping 
object or property array with all mappings
-        * @param bool $source OPTIONAL If source should be stored or not 
(default = true)
+        * @param bool                        $source  OPTIONAL If source 
should be stored or not (default = true)
         */
        public function setMapping($mapping) {
 
@@ -151,11 +160,15 @@
 
        /**
         * @param string|array|Elastica_Query $query Array with all query data 
inside or a Elastica_Query object
+        * @param int                         $limit OPTIONAL
         * @return Elastica_ResultSet ResultSet with all results inside
         * @see Elastica_Searchable::search
         */
-       public function search($query) {
+       public function search($query, $limit = 0) {
                $query = Elastica_Query::create($query);
+               if ($limit) {
+                       $query->setLimit($limit);
+               }
                $path = '_search';
 
                $response = $this->request($path, Elastica_Request::GET, 
$query->toArray());
@@ -199,6 +212,16 @@
        }
 
        /**
+        * Deletes the given list of ids from this type
+        *
+        * @param array $ids
+        * @return Elastica_Response Response object
+        */
+       public function deleteIds(array $ids) {
+               return $this->getIndex()->getClient()->deleteIds($ids, 
$this->getIndex(), $this);
+       }
+
+       /**
         * Deletes entries in the db based on a query
         *
         * @param Elastica_Query $query Query object
@@ -214,8 +237,8 @@
         *
         * The id in the given object has to be set
         *
-        * @param EalsticSearch_Document $doc Document to query for similar 
objects
-        * @param array $args OPTIONAL Additional arguments for the query
+        * @param EalsticSearch_Document $doc  Document to query for similar 
objects
+        * @param array                  $args OPTIONAL Additional arguments 
for the query
         * @link 
http://www.elasticsearch.com/docs/elasticsearch/rest_api/more_like_this/
         */
        public function moreLikeThis(Elastica_Document $doc, $args = array()) {
@@ -227,13 +250,13 @@
        /**
         * Makes calls to the elasticsearch server based on this type
         *
-        * @param string $path Path to call
+        * @param string $path   Path to call
         * @param string $method Rest method to use (GET, POST, DELETE, PUT)
-        * @param array $data OPTIONAL Arguments as array
+        * @param array  $data   OPTIONAL Arguments as array
         * @return Elastica_Response Response object
         */
        public function request($path, $method, $data = array()) {
-               $path = $this->getType() . '/' . $path;
+               $path = $this->getName() . '/' . $path;
                return $this->getIndex()->request($path, $method, $data);
        }
 }

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to