From 832934df690857c457b5f69f3fc433e8e6f0aa08 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= <simonas.serlinskas@nfq.com>
Date: Tue, 30 Jun 2015 09:42:10 +0300
Subject: [PATCH] removed suggester, it will be completely rewritten

---
 src/SearchEndpoint/SearchEndpointFactory.php |   1 -
 src/SearchEndpoint/SuggestEndpoint.php       |  19 --
 src/Suggester/AbstractSuggester.php          | 117 ----------
 src/Suggester/Completion.php                 | 215 -----------------
 src/Suggester/Context.php                    | 105 ---------
 src/Suggester/Context/AbstractContext.php    |  83 -------
 src/Suggester/Context/CategoryContext.php    |  28 ---
 src/Suggester/Context/GeoContext.php         |  53 -----
 src/Suggester/Phrase.php                     | 231 -------------------
 src/Suggester/Term.php                       | 180 ---------------
 10 files changed, 1032 deletions(-)
 delete mode 100644 src/SearchEndpoint/SuggestEndpoint.php
 delete mode 100644 src/Suggester/AbstractSuggester.php
 delete mode 100644 src/Suggester/Completion.php
 delete mode 100644 src/Suggester/Context.php
 delete mode 100644 src/Suggester/Context/AbstractContext.php
 delete mode 100644 src/Suggester/Context/CategoryContext.php
 delete mode 100644 src/Suggester/Context/GeoContext.php
 delete mode 100644 src/Suggester/Phrase.php
 delete mode 100644 src/Suggester/Term.php

diff --git a/src/SearchEndpoint/SearchEndpointFactory.php b/src/SearchEndpoint/SearchEndpointFactory.php
index 291a631..b6352d1 100644
--- a/src/SearchEndpoint/SearchEndpointFactory.php
+++ b/src/SearchEndpoint/SearchEndpointFactory.php
@@ -26,7 +26,6 @@ class SearchEndpointFactory
         'sort' => 'ONGR\ElasticsearchDSL\SearchEndpoint\SortEndpoint',
         'highlight' => 'ONGR\ElasticsearchDSL\SearchEndpoint\HighlightEndpoint',
         'aggregations' => 'ONGR\ElasticsearchDSL\SearchEndpoint\AggregationsEndpoint',
-        'suggest' => 'ONGR\ElasticsearchDSL\SearchEndpoint\SuggestEndpoint',
     ];
 
     /**
diff --git a/src/SearchEndpoint/SuggestEndpoint.php b/src/SearchEndpoint/SuggestEndpoint.php
deleted file mode 100644
index f2edd7a..0000000
--- a/src/SearchEndpoint/SuggestEndpoint.php
+++ /dev/null
@@ -1,19 +0,0 @@
-<?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\SearchEndpoint;
-
-/**
- * Search suggesters dsl endpoint.
- */
-class SuggestEndpoint extends AggregationsEndpoint
-{
-}
diff --git a/src/Suggester/AbstractSuggester.php b/src/Suggester/AbstractSuggester.php
deleted file mode 100644
index 72f8a2e..0000000
--- a/src/Suggester/AbstractSuggester.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?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\Suggester;
-
-use ONGR\ElasticsearchDSL\NamedBuilderInterface;
-
-/**
- * AbstractSuggester class.
- */
-abstract class AbstractSuggester implements NamedBuilderInterface
-{
-    /**
-     * @var string
-     */
-    private $field;
-
-    /**
-     * @var string
-     */
-    private $text;
-
-    /**
-     * @var string
-     */
-    private $name;
-
-    /**
-     * @param string $field
-     * @param string $text
-     * @param string $name
-     */
-    public function __construct($field, $text, $name = null)
-    {
-        $this->field = $field;
-        $this->text = $text;
-
-        if ($name === null) {
-            $this->name = $field . '-' . $this->getType();
-        } else {
-            $this->name = $name;
-        }
-    }
-
-    /**
-     * @return string
-     */
-    abstract public function getType();
-
-    /**
-     * @param string $field
-     *
-     * @return AbstractSuggester
-     */
-    public function setField($field)
-    {
-        $this->field = $field;
-
-        return $this;
-    }
-
-    /**
-     * @return string
-     */
-    public function getField()
-    {
-        return $this->field;
-    }
-
-    /**
-     * @param string $text
-     *
-     * @return AbstractSuggester
-     */
-    public function setText($text)
-    {
-        $this->text = $text;
-
-        return $this;
-    }
-
-    /**
-     * @return string
-     */
-    public function getText()
-    {
-        return $this->text;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getName()
-    {
-        return $this->name;
-    }
-
-    /**
-     * @param string $name
-     *
-     * @return AbstractSuggester
-     */
-    public function setName($name)
-    {
-        $this->name = $name;
-
-        return $this;
-    }
-}
diff --git a/src/Suggester/Completion.php b/src/Suggester/Completion.php
deleted file mode 100644
index 265da6b..0000000
--- a/src/Suggester/Completion.php
+++ /dev/null
@@ -1,215 +0,0 @@
-<?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\Suggester;
-
-/**
- * Completion class.
- */
-class Completion extends AbstractSuggester
-{
-    /**
-     * @var bool
-     */
-    private $useFuzzy = false;
-
-    /**
-     * @var int
-     */
-    private $fuzziness;
-
-    /**
-     * @var bool
-     */
-    private $transpositions;
-
-    /**
-     * @var int
-     */
-    private $minLength;
-
-    /**
-     * @var int
-     */
-    private $prefixLength;
-
-    /**
-     * @var string
-     */
-    private $unicodeAware;
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'completion';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        if (!$this->getField() && !$this->getText()) {
-            throw new \LogicException('Field and text should be defined.');
-        }
-
-        $fuzzy = array_filter(
-            [
-                'fuzziness' => $this->getFuzziness(),
-                'transpositions' => $this->isTranspositions(),
-                'min_length' => $this->getMinLength(),
-                'prefix_length' => $this->getPrefixLength(),
-                'unicode_aware' => $this->getUnicodeAware(),
-            ]
-        );
-
-        $completion = [
-            'field' => $this->getField(),
-        ];
-
-        if (empty($fuzzy) && $this->isFuzzy()) {
-            $completion['fuzzy'] = true;
-        } elseif (!empty($fuzzy)) {
-            $completion['fuzzy'] = $fuzzy;
-        }
-
-        return [
-            $this->getName() => [
-                'text' => $this->getText(),
-                'completion' => $completion,
-            ],
-        ];
-    }
-
-    /**
-     * @return int
-     */
-    public function getFuzziness()
-    {
-        return $this->fuzziness;
-    }
-
-    /**
-     * @param int $fuzziness
-     *
-     * @return Completion
-     */
-    public function setFuzziness($fuzziness)
-    {
-        $this->fuzziness = $fuzziness;
-
-        return $this;
-    }
-
-    /**
-     * @return int
-     */
-    public function getMinLength()
-    {
-        return $this->minLength;
-    }
-
-    /**
-     * @param int $minLength
-     *
-     * @return Completion
-     */
-    public function setMinLength($minLength)
-    {
-        $this->minLength = $minLength;
-
-        return $this;
-    }
-
-    /**
-     * @return int
-     */
-    public function getPrefixLength()
-    {
-        return $this->prefixLength;
-    }
-
-    /**
-     * @param int $prefixLength
-     *
-     * @return Completion
-     */
-    public function setPrefixLength($prefixLength)
-    {
-        $this->prefixLength = $prefixLength;
-
-        return $this;
-    }
-
-    /**
-     * @return bool
-     */
-    public function isTranspositions()
-    {
-        return $this->transpositions;
-    }
-
-    /**
-     * @param bool $transpositions
-     *
-     * @return Completion
-     */
-    public function setTranspositions($transpositions)
-    {
-        $this->transpositions = $transpositions;
-
-        return $this;
-    }
-
-    /**
-     * @return string
-     */
-    public function getUnicodeAware()
-    {
-        return $this->unicodeAware;
-    }
-
-    /**
-     * @param string $unicodeAware
-     *
-     * @return Completion
-     */
-    public function setUnicodeAware($unicodeAware)
-    {
-        $this->unicodeAware = $unicodeAware;
-
-        return $this;
-    }
-
-    /**
-     * @return bool
-     */
-    public function isFuzzy()
-    {
-        return $this->useFuzzy;
-    }
-
-    /**
-     * Sets fuzzy and returns Completion object.
-     *
-     * @param bool $useFuzzy
-     *
-     * @return Completion
-     */
-    public function useFuzzy($useFuzzy)
-    {
-        $this->useFuzzy = $useFuzzy;
-
-        return $this;
-    }
-}
diff --git a/src/Suggester/Context.php b/src/Suggester/Context.php
deleted file mode 100644
index cf28cf0..0000000
--- a/src/Suggester/Context.php
+++ /dev/null
@@ -1,105 +0,0 @@
-<?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\Suggester;
-
-use ONGR\ElasticsearchDSL\Suggester\Context\AbstractContext;
-
-/**
- * Context suggester.
- */
-class Context extends AbstractSuggester
-{
-    /**
-     * @var AbstractContext[]
-     */
-    private $context;
-
-    /**
-     * @var int Size of completion.
-     */
-    private $size;
-
-    /**
-     * Returns context.
-     *
-     * @return AbstractContext[]
-     */
-    public function getContext()
-    {
-        return $this->context;
-    }
-
-    /**
-     * Sets context array.
-     *
-     * @param AbstractContext[] $context
-     */
-    public function setContext($context)
-    {
-        $this->context = $context;
-    }
-
-    /**
-     * Sets context.
-     *
-     * @param AbstractContext $context
-     */
-    public function addContext($context)
-    {
-        $this->context[] = $context;
-    }
-
-    /**
-     * @return int
-     */
-    public function getSize()
-    {
-        return $this->size;
-    }
-
-    /**
-     * @param int $size
-     */
-    public function setSize($size)
-    {
-        $this->size = $size;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        $completion = ['field' => $this->getField()];
-        foreach ($this->context as $context) {
-            $completion['context'][$context->getName()] = $context->toArray();
-        }
-        if ($this->getSize() !== null) {
-            $completion['size'] = $this->getSize();
-        }
-
-        return [
-            $this->getName() => [
-                'text' => $this->getText(),
-                'completion' => $completion,
-            ],
-        ];
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'completion';
-    }
-}
diff --git a/src/Suggester/Context/AbstractContext.php b/src/Suggester/Context/AbstractContext.php
deleted file mode 100644
index 1d2e4fc..0000000
--- a/src/Suggester/Context/AbstractContext.php
+++ /dev/null
@@ -1,83 +0,0 @@
-<?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\Suggester\Context;
-
-/**
- * Abstract context to be used by geo context and category context.
- */
-abstract class AbstractContext
-{
-    /**
-     * @var string Name of the context used.
-     */
-    private $name;
-
-    /**
-     * @var string|array Value of the context.
-     */
-    private $value;
-
-    /**
-     * Constructor.
-     *
-     * @param string       $name  Context name.
-     * @param array|string $value Context value.
-     */
-    public function __construct($name, $value)
-    {
-        $this->name = $name;
-        $this->value = $value;
-    }
-
-    /**
-     * Converts context to an array.
-     *
-     * @return array
-     */
-    abstract public function toArray();
-
-    /**
-     * Returns name of the context.
-     *
-     * @return string
-     */
-    public function getName()
-    {
-        return $this->name;
-    }
-
-    /**
-     * Sets type of the context.
-     *
-     * @param string $name
-     */
-    public function setName($name)
-    {
-        $this->name = $name;
-    }
-
-    /**
-     * @return array|string
-     */
-    public function getValue()
-    {
-        return $this->value;
-    }
-
-    /**
-     * @param array|string $value
-     */
-    public function setValue($value)
-    {
-        $this->value = $value;
-    }
-}
diff --git a/src/Suggester/Context/CategoryContext.php b/src/Suggester/Context/CategoryContext.php
deleted file mode 100644
index f78dbca..0000000
--- a/src/Suggester/Context/CategoryContext.php
+++ /dev/null
@@ -1,28 +0,0 @@
-<?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\Suggester\Context;
-
-/**
- * Category context to be used by context suggester.
- */
-class CategoryContext extends AbstractContext
-{
-    /**
-     * {@inheritdoc}
-     *
-     * @return array|string
-     */
-    public function toArray()
-    {
-        return $this->getValue();
-    }
-}
diff --git a/src/Suggester/Context/GeoContext.php b/src/Suggester/Context/GeoContext.php
deleted file mode 100644
index 6db0115..0000000
--- a/src/Suggester/Context/GeoContext.php
+++ /dev/null
@@ -1,53 +0,0 @@
-<?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\Suggester\Context;
-
-/**
- * Geo context to be used by context suggester.
- */
-class GeoContext extends AbstractContext
-{
-    /**
-     * @var string
-     */
-    private $precision;
-
-    /**
-     * @return mixed
-     */
-    public function getPrecision()
-    {
-        return $this->precision;
-    }
-
-    /**
-     * @param mixed $precision
-     */
-    public function setPrecision($precision)
-    {
-        $this->precision = $precision;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        $out = ['value' => $this->getValue()];
-
-        if ($this->getPrecision() !== null) {
-            $out['precision'] = $this->getPrecision();
-        }
-
-        return $out;
-    }
-}
diff --git a/src/Suggester/Phrase.php b/src/Suggester/Phrase.php
deleted file mode 100644
index 5fff0aa..0000000
--- a/src/Suggester/Phrase.php
+++ /dev/null
@@ -1,231 +0,0 @@
-<?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\Suggester;
-
-/**
- * Phrase class.
- */
-class Phrase extends AbstractSuggester
-{
-    /**
-     * @var string
-     */
-    private $analyzer;
-
-    /**
-     * @var int
-     */
-    private $gramSize;
-
-    /**
-     * @var float
-     */
-    private $realWordErrorLikelihood;
-
-    /**
-     * @var float
-     */
-    private $confidence;
-
-    /**
-     * @var float
-     */
-    private $maxErrors;
-
-    /**
-     * @var array
-     */
-    private $highlight = [];
-
-    /**
-     * @var int
-     */
-    private $size;
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'phrase';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        if (!$this->getField() && !$this->getText()) {
-            throw new \LogicException('Field and text should be defined.');
-        }
-
-        $phrase = [
-            'field' => $this->getField(),
-            'analyzer' => $this->getAnalyzer(),
-            'size' => $this->getSize(),
-            'real_word_error_likelihood' => $this->getRealWordErrorLikelihood(),
-            'max_errors' => $this->getMaxErrors(),
-            'gram_size' => $this->getGramSize(),
-        ];
-
-        if ($this->getHighlight()) {
-            $phrase['highlight'] = (object)$this->getHighlight();
-        }
-
-        return [
-            $this->getName() => [
-                'text' => $this->getText(),
-                'phrase' => array_filter($phrase),
-            ],
-        ];
-    }
-
-    /**
-     * @return string
-     */
-    public function getAnalyzer()
-    {
-        return $this->analyzer;
-    }
-
-    /**
-     * @param string $analyzer
-     *
-     * @return Phrase
-     */
-    public function setAnalyzer($analyzer)
-    {
-        $this->analyzer = $analyzer;
-
-        return $this;
-    }
-
-    /**
-     * @return float
-     */
-    public function getConfidence()
-    {
-        return $this->confidence;
-    }
-
-    /**
-     * @param float $confidence
-     *
-     * @return Phrase
-     */
-    public function setConfidence($confidence)
-    {
-        $this->confidence = $confidence;
-
-        return $this;
-    }
-
-    /**
-     * @return int
-     */
-    public function getGramSize()
-    {
-        return $this->gramSize;
-    }
-
-    /**
-     * @param int $gramSize
-     *
-     * @return Phrase
-     */
-    public function setGramSize($gramSize)
-    {
-        $this->gramSize = $gramSize;
-
-        return $this;
-    }
-
-    /**
-     * @return array
-     */
-    public function getHighlight()
-    {
-        return $this->highlight;
-    }
-
-    /**
-     * @param array $highlight
-     *
-     * @return Phrase
-     */
-    public function setHighlight($highlight)
-    {
-        $this->highlight = $highlight;
-
-        return $this;
-    }
-
-    /**
-     * @return float
-     */
-    public function getMaxErrors()
-    {
-        return $this->maxErrors;
-    }
-
-    /**
-     * @param float $maxErrors
-     *
-     * @return Phrase
-     */
-    public function setMaxErrors($maxErrors)
-    {
-        $this->maxErrors = $maxErrors;
-
-        return $this;
-    }
-
-    /**
-     * @return float
-     */
-    public function getRealWordErrorLikelihood()
-    {
-        return $this->realWordErrorLikelihood;
-    }
-
-    /**
-     * @param float $realWordErrorLikelihood
-     *
-     * @return Phrase
-     */
-    public function setRealWordErrorLikelihood($realWordErrorLikelihood)
-    {
-        $this->realWordErrorLikelihood = $realWordErrorLikelihood;
-
-        return $this;
-    }
-
-    /**
-     * @param int $size
-     *
-     * @return Phrase
-     */
-    public function setSize($size)
-    {
-        $this->size = $size;
-
-        return $this;
-    }
-
-    /**
-     * @return int
-     */
-    public function getSize()
-    {
-        return $this->size;
-    }
-}
diff --git a/src/Suggester/Term.php b/src/Suggester/Term.php
deleted file mode 100644
index 9cc8ade..0000000
--- a/src/Suggester/Term.php
+++ /dev/null
@@ -1,180 +0,0 @@
-<?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\Suggester;
-
-/**
- * Term class.
- */
-class Term extends AbstractSuggester
-{
-    const SORT_BY_SCORE = 'score';
-    const SORT_BY_FREQ = 'frequency';
-    const SUGGEST_MODE_MISSING = 'missing';
-    const SUGGEST_MODE_POPULAR = 'popular';
-    const SUGGEST_MODE_ALWAYS = 'always';
-
-    /**
-     * @var string
-     */
-    private $sort;
-
-    /**
-     * @var string
-     */
-    private $analyzer;
-
-    /**
-     * @var string;
-     */
-    private $suggestMode;
-
-    /**
-     * @var int
-     */
-    private $size;
-
-    /**
-     * @return string
-     */
-    public function getType()
-    {
-        return 'term';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        if (!$this->getField() && !$this->getText()) {
-            throw new \LogicException('Field and text should be defined.');
-        }
-
-        $suggester = array_filter(
-            [
-                'field' => $this->getField(),
-                'analyzer' => $this->getAnalyzer(),
-                'sort' => $this->getSort(),
-                'suggest_mode' => $this->getSuggestMode(),
-            ]
-        );
-
-        return [
-            $this->getName() => array_filter(
-                [
-                    'text' => $this->getText(),
-                    'size' => $this->getSize(),
-                    'term' => $suggester,
-                ]
-            ),
-        ];
-    }
-
-    /**
-     * @return string
-     */
-    public function getSort()
-    {
-        return $this->sort;
-    }
-
-    /**
-     * @param string $sort
-     *
-     * @return Term
-     */
-    public function setSort($sort)
-    {
-        if (in_array(
-            $sort,
-            [
-                self::SORT_BY_FREQ,
-                self::SORT_BY_SCORE,
-            ]
-        )
-        ) {
-            $this->sort = $sort;
-        }
-
-        return $this;
-    }
-
-    /**
-     * @return string
-     */
-    public function getAnalyzer()
-    {
-        return $this->analyzer;
-    }
-
-    /**
-     * @param string $analyzer
-     *
-     * @return Term
-     */
-    public function setAnalyzer($analyzer)
-    {
-        $this->analyzer = $analyzer;
-
-        return $this;
-    }
-
-    /**
-     * @return string
-     */
-    public function getSuggestMode()
-    {
-        return $this->suggestMode;
-    }
-
-    /**
-     * @param string $suggestMode
-     *
-     * @return Term
-     */
-    public function setSuggestMode($suggestMode)
-    {
-        if (in_array(
-            $suggestMode,
-            [
-                self::SUGGEST_MODE_ALWAYS,
-                self::SUGGEST_MODE_MISSING,
-                self::SUGGEST_MODE_POPULAR,
-            ]
-        )
-        ) {
-            $this->suggestMode = $suggestMode;
-        }
-
-        return $this;
-    }
-
-    /**
-     * @param int $size
-     *
-     * @return Term
-     */
-    public function setSize($size)
-    {
-        $this->size = $size;
-
-        return $this;
-    }
-
-    /**
-     * @return int
-     */
-    public function getSize()
-    {
-        return $this->size;
-    }
-}
-- 
GitLab