[icinga-checkins] icinga.org: icingaweb2-module-elasticsearch/master: RestApiQuery: Allow to provide URL params for count and search requests

git at icinga.org git at icinga.org
Wed May 11 10:13:41 CEST 2016


Module: icingaweb2-module-elasticsearch
Branch: master
Commit: 1a36192134f40ffbde031bc1534cb02206311c88
URL:    https://git.icinga.org/?p=icingaweb2-module-elasticsearch.git;a=commit;h=1a36192134f40ffbde031bc1534cb02206311c88

Author: Johannes Meyer <johannes.meyer at netways.de>
Date:   Wed May 11 10:12:40 2016 +0200

RestApiQuery: Allow to provide URL params for count and search requests

---

 library/Elasticsearch/RestApi/RestApiQuery.php |   49 +++++++++++++++++++++---
 1 file changed, 43 insertions(+), 6 deletions(-)

diff --git a/library/Elasticsearch/RestApi/RestApiQuery.php b/library/Elasticsearch/RestApi/RestApiQuery.php
index ebe6017..2591859 100644
--- a/library/Elasticsearch/RestApi/RestApiQuery.php
+++ b/library/Elasticsearch/RestApi/RestApiQuery.php
@@ -5,6 +5,7 @@ namespace Icinga\Module\Elasticsearch\RestApi;
 
 use LogicException;
 use Icinga\Data\SimpleQuery;
+use Icinga\Web\UrlParams;
 
 class RestApiQuery extends SimpleQuery
 {
@@ -33,6 +34,13 @@ class RestApiQuery extends SimpleQuery
     protected $types;
 
     /**
+     * The URL params to use for count and search requests
+     *
+     * @var UrlParams
+     */
+    protected $params;
+
+    /**
      * Whether _source retrieval is disabled
      *
      * @var bool
@@ -93,6 +101,33 @@ class RestApiQuery extends SimpleQuery
     }
 
     /**
+     * Set the URL params to use for count and search requests
+     *
+     * @param   UrlParams   $params
+     *
+     * @return  $this
+     */
+    public function setParams(UrlParams $params)
+    {
+        $this->params = $params;
+        return $this;
+    }
+
+    /**
+     * Return the URL params to use for count and search requests
+     *
+     * @return  UrlParams
+     */
+    public function getParams()
+    {
+        if ($this->params === null) {
+            $this->params = new UrlParams();
+        }
+
+        return $this->params;
+    }
+
+    /**
      * Set whether _source retrieval is disabled
      *
      * @param   bool    $state
@@ -158,11 +193,12 @@ class RestApiQuery extends SimpleQuery
     {
         $foldedColumn = $this->getUnfoldAttribute();
         if ($foldedColumn === null) {
-            return new CountApiRequest(
+            $request = new CountApiRequest(
                 $this->getIndices(),
                 $this->getTypes(),
                 array('query' => $this->ds->renderFilter($this->getFilter()))
             );
+            return $request->setParams($this->getParams());
         }
 
         $requestedFields = $this->getColumns();
@@ -189,10 +225,10 @@ class RestApiQuery extends SimpleQuery
             )
         );
 
-        $request->getParams()
-            ->add('_source', 'false')
-            ->add('filter_path', 'aggregations');
-        return $request;
+        $params = $this->getParams()
+            ->set('_source', 'false')
+            ->set('filter_path', 'aggregations');
+        return $request->setParams($params);
     }
 
     /**
@@ -268,7 +304,8 @@ class RestApiQuery extends SimpleQuery
             }
         }
 
-        return new SearchApiRequest($this->getIndices(), $this->getTypes(), $body);
+        $request = new SearchApiRequest($this->getIndices(), $this->getTypes(), $body);
+        return $request->setParams($this->getParams());
     }
 
     /**



More information about the icinga-checkins mailing list