From 94d42cb3b3144fceabd5ed006ff2e9c58e6e9573 Mon Sep 17 00:00:00 2001
From: Ron Rademaker <ron@connectholland.nl>
Date: Wed, 15 Jun 2016 15:14:06 +0200
Subject: [PATCH] Added query objects for match_phrase and match_phrase_prefix

---
 src/Query/MatchPhrasePrefixQuery.php       | 29 ++++++++++++++++++
 src/Query/MatchPhraseQuery.php             | 29 ++++++++++++++++++
 tests/Query/MatchPhrasePrefixQueryTest.php | 35 ++++++++++++++++++++++
 tests/Query/MatchPhraseQueryTest.php       | 35 ++++++++++++++++++++++
 4 files changed, 128 insertions(+)
 create mode 100644 src/Query/MatchPhrasePrefixQuery.php
 create mode 100644 src/Query/MatchPhraseQuery.php
 create mode 100644 tests/Query/MatchPhrasePrefixQueryTest.php
 create mode 100644 tests/Query/MatchPhraseQueryTest.php

diff --git a/src/Query/MatchPhrasePrefixQuery.php b/src/Query/MatchPhrasePrefixQuery.php
new file mode 100644
index 0000000..a215d44
--- /dev/null
+++ b/src/Query/MatchPhrasePrefixQuery.php
@@ -0,0 +1,29 @@
+<?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\ElasticsearchDSL\Query;
+
+/**
+ * Represents Elasticsearch "match_phrase_prefix" query.
+ *
+ * @author Ron Rademaker
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#query-dsl-match-query-phrase-prefix
+ */
+class MatchPhrasePrefixQuery extends MatchQuery
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'match_phrase_prefix';
+    }
+}
diff --git a/src/Query/MatchPhraseQuery.php b/src/Query/MatchPhraseQuery.php
new file mode 100644
index 0000000..6ac5d7a
--- /dev/null
+++ b/src/Query/MatchPhraseQuery.php
@@ -0,0 +1,29 @@
+<?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\ElasticsearchDSL\Query;
+
+/**
+ * Represents Elasticsearch "match_phrase" query.
+ *
+ * @author Ron Rademaker
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#query-dsl-match-query-phrase
+ */
+class MatchPhraseQuery extends MatchQuery
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'match_phrase';
+    }
+}
diff --git a/tests/Query/MatchPhrasePrefixQueryTest.php b/tests/Query/MatchPhrasePrefixQueryTest.php
new file mode 100644
index 0000000..ea5c202
--- /dev/null
+++ b/tests/Query/MatchPhrasePrefixQueryTest.php
@@ -0,0 +1,35 @@
+<?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\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\MatchPhrasePrefixQuery;
+use PHPUnit_Framework_TestCase;
+
+class MatchPhrasePrefixQueryTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new MatchPhrasePrefixQuery('message', 'this is a test');
+        $expected = [
+            'match_phrase_prefix' => [
+                'message' => [
+                    'query' => 'this is a test',
+                ],
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/MatchPhraseQueryTest.php b/tests/Query/MatchPhraseQueryTest.php
new file mode 100644
index 0000000..74cf40b
--- /dev/null
+++ b/tests/Query/MatchPhraseQueryTest.php
@@ -0,0 +1,35 @@
+<?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\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\MatchPhraseQuery;
+use PHPUnit_Framework_TestCase;
+
+class MatchPhraseQueryTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new MatchPhraseQuery('message', 'this is a test');
+        $expected = [
+            'match_phrase' => [
+                'message' => [
+                    'query' => 'this is a test',
+                ],
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
-- 
GitLab