From fc208ba57cd63be9d2879ecc19301f3f7ff19c7f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mantas=20Jonu=C5=A1as?= <mantas.jonusas@nfq.lt>
Date: Mon, 16 Mar 2015 19:02:27 +0200
Subject: [PATCH] Added geo-shape filter

---
 Filter/GeoShapeFilter.php | 100 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)
 create mode 100644 Filter/GeoShapeFilter.php

diff --git a/Filter/GeoShapeFilter.php b/Filter/GeoShapeFilter.php
new file mode 100644
index 0000000..d05a398
--- /dev/null
+++ b/Filter/GeoShapeFilter.php
@@ -0,0 +1,100 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchBundle\DSL\Filter;
+
+use ONGR\ElasticsearchBundle\DSL\BuilderInterface;
+use ONGR\ElasticsearchBundle\DSL\ParametersTrait;
+
+/**
+ * Elasticsearch geo-shape filter.
+ */
+class GeoShapeFilter implements BuilderInterface
+{
+    use ParametersTrait;
+
+    /**
+     * @var array
+     */
+    private $fields = [];
+
+    /**
+     * @param array $parameters
+     */
+    public function __construct(array $parameters = [])
+    {
+        $this->setParameters($parameters);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'geo_shape';
+    }
+
+    /**
+     * Add geo-shape provided filter.
+     *
+     * @param string $field       Field name.
+     * @param string $type        Shape type.
+     * @param array  $coordinates Shape coordinates.
+     * @param array  $parameters  Additional parameters.
+     */
+    public function addShape($field, $type, array $coordinates, array $parameters = [])
+    {
+        $filter = array_merge(
+            $parameters,
+            [
+                'type' => $type,
+                'coordinates' => $coordinates,
+            ]
+        );
+
+        $this->fields[$field]['shape'] = $filter;
+    }
+
+    /**
+     * Add geo-shape pre-indexed filter.
+     *
+     * @param string $field      Field name.
+     * @param string $id         The ID of the document that containing the pre-indexed shape.
+     * @param string $type       Name of the index where the pre-indexed shape is.
+     * @param string $index      Index type where the pre-indexed shape is.
+     * @param string $path       The field specified as path containing the pre-indexed shape.
+     * @param array  $parameters Additional parameters.
+     */
+    public function addPreIndexedShape($field, $id, $type, $index, $path, array $parameters = [])
+    {
+        $filter = array_merge(
+            $parameters,
+            [
+                'id' => $id,
+                'type' => $type,
+                'index' => $index,
+                'path' => $path,
+            ]
+        );
+
+        $this->fields[$field]['indexed_shape'] = $filter;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        $output = $this->processArray($this->fields);
+
+        return $output;
+    }
+}
-- 
GitLab