From 9ce05146a8aa96d41038e563dcf14d3bfc7e0aed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zigmas=20Satkevi=C4=8Dius?= Date: Tue, 25 Nov 2014 12:14:22 +0200 Subject: [PATCH 01/10] Added annotation parsers. --- .../Suggester/AbstractSuggesterProperty.php | 47 ++++++++ .../Suggester/CompletionSuggesterProperty.php | 64 ++++++++++ .../Suggester/Context/AbstractContext.php | 59 +++++++++ .../Suggester/Context/CategoryContext.php | 29 +++++ .../Suggester/Context/GeoLocationContext.php | 39 ++++++ .../Suggester/ContextSuggesterProperty.php | 39 ++++++ Document/Suggester/AbstractSuggester.php | 52 ++++++++ Document/Suggester/CompletionSuggester.php | 113 ++++++++++++++++++ .../Suggester/Context/AbstractContext.php | 52 ++++++++ .../Suggester/Context/CategoryContext.php | 43 +++++++ .../Suggester/Context/GeoLocationContext.php | 28 +++++ Document/Suggester/ContextSuggester.php | 32 +++++ Mapping/MappingTool.php | 24 +++- Mapping/MetadataCollector.php | 28 +++-- ORM/Repository.php | 7 ++ 15 files changed, 647 insertions(+), 9 deletions(-) create mode 100644 Annotation/Suggester/AbstractSuggesterProperty.php create mode 100644 Annotation/Suggester/CompletionSuggesterProperty.php create mode 100644 Annotation/Suggester/Context/AbstractContext.php create mode 100644 Annotation/Suggester/Context/CategoryContext.php create mode 100644 Annotation/Suggester/Context/GeoLocationContext.php create mode 100644 Annotation/Suggester/ContextSuggesterProperty.php create mode 100644 Document/Suggester/AbstractSuggester.php create mode 100644 Document/Suggester/CompletionSuggester.php create mode 100644 Document/Suggester/Context/AbstractContext.php create mode 100644 Document/Suggester/Context/CategoryContext.php create mode 100644 Document/Suggester/Context/GeoLocationContext.php create mode 100644 Document/Suggester/ContextSuggester.php diff --git a/Annotation/Suggester/AbstractSuggesterProperty.php b/Annotation/Suggester/AbstractSuggesterProperty.php new file mode 100644 index 00000000..2a18bea9 --- /dev/null +++ b/Annotation/Suggester/AbstractSuggesterProperty.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Annotation\Suggester; + +/** + * Abstract class for various suggester annotations. + */ +abstract class AbstractSuggesterProperty +{ + /** + * @var string + */ + public $type = 'completion'; + + /** + * @var string + * + * @Required + */ + public $name; + + /** + * Object name to map. + * + * @var string + */ + public $objectName; + + /** + * Returns required properties. + * + * @return array + */ + public function filter() + { + return ['type' => $this->type]; + } +} diff --git a/Annotation/Suggester/CompletionSuggesterProperty.php b/Annotation/Suggester/CompletionSuggesterProperty.php new file mode 100644 index 00000000..969adcb0 --- /dev/null +++ b/Annotation/Suggester/CompletionSuggesterProperty.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Annotation\Suggester; + +/** + * Class for completion suggester. + * + * @Annotation + * @Target("PROPERTY") + */ +class CompletionSuggesterProperty extends AbstractSuggesterProperty +{ + /** + * @var string + */ + public $index_analyzer; + + /** + * @var string + */ + public $search_analyzer; + + /** + * @var int + */ + public $preserve_separators; + + /** + * @var bool + */ + public $preserve_position_increments; + + /** + * @var int + */ + public $max_input_length; + + /** + * @var bool + */ + public $payloads; + + /** + * {@inheritdoc} + */ + public function filter() + { + $data = array_merge(parent::filter(), array_filter(get_object_vars($this))); + + return array_diff_key( + $data, + array_flip(['name', 'objectName']) + ); + } +} diff --git a/Annotation/Suggester/Context/AbstractContext.php b/Annotation/Suggester/Context/AbstractContext.php new file mode 100644 index 00000000..0e5568e3 --- /dev/null +++ b/Annotation/Suggester/Context/AbstractContext.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Annotation\Suggester\Context; + +/** + * Abstract class for various context annotations. + */ +abstract class AbstractContext +{ + /** + * @var array + */ + public $default; + + /** + * @var string + * + * @Required + */ + public $name; + + /** + * @var string + */ + public $path; + + /** + * Returns context type. + * + * @return string + */ + abstract public function getType(); + + /** + * Returns filtered object data. + * + * @return array + */ + public function filter() + { + $vars = array_diff_key( + array_filter(get_object_vars($this)), + array_flip(['name']) + ); + + $vars['type'] = $this->getType(); + + return $vars; + } +} diff --git a/Annotation/Suggester/Context/CategoryContext.php b/Annotation/Suggester/Context/CategoryContext.php new file mode 100644 index 00000000..97e1dd1e --- /dev/null +++ b/Annotation/Suggester/Context/CategoryContext.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Annotation\Suggester\Context; + +/** + * Class for geo category context annotations used in context suggester. + * + * @Annotation + * @Target("ANNOTATION") + */ +class CategoryContext extends AbstractContext +{ + /** + * {@inheritdoc} + */ + public function getType() + { + return 'category'; + } +} diff --git a/Annotation/Suggester/Context/GeoLocationContext.php b/Annotation/Suggester/Context/GeoLocationContext.php new file mode 100644 index 00000000..5b7a966d --- /dev/null +++ b/Annotation/Suggester/Context/GeoLocationContext.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Annotation\Suggester\Context; + +/** + * Class for geo location context annotations used in context suggester. + * + * @Annotation + * @Target("ANNOTATION") + */ +class GeoLocationContext extends AbstractContext +{ + /** + * @var array + */ + public $precision; + + /** + * @var bool + */ + public $neighbors; + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'geo'; + } +} diff --git a/Annotation/Suggester/ContextSuggesterProperty.php b/Annotation/Suggester/ContextSuggesterProperty.php new file mode 100644 index 00000000..e2a6024c --- /dev/null +++ b/Annotation/Suggester/ContextSuggesterProperty.php @@ -0,0 +1,39 @@ + + */ + public $context; + + /** + * {@inheritdoc} + */ + public function filter() + { + $data = array_merge(parent::filter(), array_filter(get_object_vars($this))); + + $data = array_diff_key( + $data, + array_flip(['name', 'objectName', 'context']) + ); + + /** @var AbstractContext $singleContext */ + foreach ($this->context as $singleContext) { + $data['context'][$singleContext->name] = $singleContext->filter(); + } + + return $data; + } +} diff --git a/Document/Suggester/AbstractSuggester.php b/Document/Suggester/AbstractSuggester.php new file mode 100644 index 00000000..d5f0d096 --- /dev/null +++ b/Document/Suggester/AbstractSuggester.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Document\Suggester; + +/** + * Abstract record document for various suggesters. + */ +abstract class AbstractSuggester +{ + /** + * Input to store. + * + * @var string[] + */ + private $input; + + /** + * Setter for input to store. + * + * @param string[]|string $input + */ + public function setInput($input) + { + $this->input = is_array($input) ? $input : [$input]; + } + + /** + * Returns input to check for. + * + * @return string[] + */ + public function getInput() + { + return $this->input; + } + + /** + * Returns suggester type. + * + * @return string + */ + abstract public function getType(); +} diff --git a/Document/Suggester/CompletionSuggester.php b/Document/Suggester/CompletionSuggester.php new file mode 100644 index 00000000..1c5c3903 --- /dev/null +++ b/Document/Suggester/CompletionSuggester.php @@ -0,0 +1,113 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Document\Suggester; + +use ONGR\ElasticsearchBundle\Annotation as ES; + +/** + * Class to be used for completion suggestion objects. + * + * @ES\Object + */ +class CompletionSuggester extends AbstractSuggester +{ + /** + * String to return. + * + * @var string + */ + private $output; + + /** + * Object to be returned in the suggest option. + * + * @var object + */ + private $payload; + + /** + * Weight used to rank suggestions. + * + * @var int|string + */ + private $weight; + + /** + * Setter for string to return. + * + * @param string $output + */ + public function setOutput($output) + { + $this->output = $output; + } + + /** + * Returns output to be set. + * + * @return string + */ + public function getOutput() + { + return $this->output; + } + + /** + * Setter for object to be returned in the suggest option. + * + * @param object $payload + */ + public function setPayload($payload) + { + $this->payload = $payload; + } + + /** + * Returns object to be returned in the suggest option. + * + * @return object + */ + public function getPayload() + { + return $this->payload; + } + + /** + * Setter for a weight used to rank suggestions. + * + * @param int|string $weight + * + * @return mixed + */ + public function setWeight($weight) + { + $this->weight = $weight; + } + + /** + * Returns object to be returned in the suggest option. + * + * @return object + */ + public function getWeight() + { + return $this->weight; + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'completion'; + } +} diff --git a/Document/Suggester/Context/AbstractContext.php b/Document/Suggester/Context/AbstractContext.php new file mode 100644 index 00000000..44ab34fe --- /dev/null +++ b/Document/Suggester/Context/AbstractContext.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Document\Suggester\Context; + +/** + * Abstract context type for context suggester. + */ +abstract class AbstractContext +{ + /** + * Context name. + * + * @var string + */ + private $name; + + /** + * Returns context name. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Sets context name. + * + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Returns context type. + * + * @return string + */ + abstract public function getType(); +} diff --git a/Document/Suggester/Context/CategoryContext.php b/Document/Suggester/Context/CategoryContext.php new file mode 100644 index 00000000..7a3430b1 --- /dev/null +++ b/Document/Suggester/Context/CategoryContext.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Document\Suggester\Context; + +/** + * Category context type for context suggester. + */ +class CategoryContext extends AbstractContext +{ + /** + * @var String|string[] + */ + private $value; + + /** + * Returns context value. + * + * @return array + */ + public function getValue() + { + return []; + } + + /** + * Returns context type. + * + * @return string + */ + public function getType() + { + return 'category'; + } +} diff --git a/Document/Suggester/Context/GeoLocationContext.php b/Document/Suggester/Context/GeoLocationContext.php new file mode 100644 index 00000000..286e631f --- /dev/null +++ b/Document/Suggester/Context/GeoLocationContext.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Document\Suggester\Context; + +/** + * Abstract geo location context type for context suggester. + */ +class GeoLocationContext extends AbstractContext +{ + /** + * Returns context type. + * + * @return string + */ + public function getType() + { + return 'geo_location'; + } +} diff --git a/Document/Suggester/ContextSuggester.php b/Document/Suggester/ContextSuggester.php new file mode 100644 index 00000000..21662237 --- /dev/null +++ b/Document/Suggester/ContextSuggester.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Document\Suggester; + +use ONGR\ElasticsearchBundle\Annotation as ES; + +/** + * Class to be used for context suggestion objects. + * + * @ES\Object + */ +class ContextSuggester extends AbstractSuggester +{ + private $contexts; + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'completion'; + } +} diff --git a/Mapping/MappingTool.php b/Mapping/MappingTool.php index 337bdad9..43a8992f 100644 --- a/Mapping/MappingTool.php +++ b/Mapping/MappingTool.php @@ -23,12 +23,20 @@ class MappingTool 'type' => 'object', '_routing' => ['required' => true], 'format' => 'dateOptionalTime', + 'max_input_length' => 50, + 'preserve_separators' => true, + 'preserve_position_increments' => true, + 'analyzer' => 'simple', + 'payloads' => false, ]; /** * @var array */ - private $formatFields = ['_ttl' => 'handleTime']; + protected $formatFields = [ + '_ttl' => 'handleTime', + 'precision' => 'handlePrecision', + ]; /** * @var array @@ -224,4 +232,18 @@ private function handleTime($value) return $value; } + + /** + * Handles precision. + * + * @param array|string $value + * + * @return array + */ + private function handlePrecision($value) + { + // TODO: currently precision is not checked. Issue #46. + + return []; + } } diff --git a/Mapping/MetadataCollector.php b/Mapping/MetadataCollector.php index 422667fc..64c0a28e 100644 --- a/Mapping/MetadataCollector.php +++ b/Mapping/MetadataCollector.php @@ -24,13 +24,6 @@ */ class MetadataCollector { - /** - * Annotations to load. - * - * @var array - */ - protected $annotations = ['Document', 'Property', 'Object', 'Nested', 'MultiField']; - /** * @var array */ @@ -399,9 +392,14 @@ private function getProperties(\ReflectionClass $reflectionClass) foreach ($reflectionClass->getProperties() as $property) { /** @var Property $type */ $type = $this->reader->getPropertyAnnotation($property, 'ONGR\ElasticsearchBundle\Annotation\Property'); + if ($type === null) { + $type = $this->reader->getPropertyAnnotation($property, 'ONGR\ElasticsearchBundle\Annotation\Suggester\AbstractSuggesterProperty'); + } if (!empty($type)) { $maps = $type->filter(); $this->aliases[$reflectionClass->getName()][$type->name] = $property->getName(); + + // Object. if (($type->type === 'object' || $type->type === 'nested') && !empty($type->objectName)) { if (!empty($this->objects[strtolower($type->objectName)])) { $objMap = $this->objects[strtolower($type->objectName)]; @@ -411,6 +409,8 @@ private function getProperties(\ReflectionClass $reflectionClass) } $maps = array_replace_recursive($maps, $objMap); } + + // MultiField. if (isset($maps['fields']) && !in_array($type, ['object', 'nested'])) { $fieldsMap = []; /** @var MultiField $field */ @@ -431,7 +431,19 @@ private function getProperties(\ReflectionClass $reflectionClass) */ private function registerAnnotations() { - foreach ($this->annotations as $annotation) { + $annotations = [ + 'Document', + 'Property', + 'Object', + 'Nested', + 'MultiField', + 'Suggester/CompletionSuggesterProperty', + 'Suggester/ContextSuggesterProperty', + 'Suggester/Context/CategoryContext', + 'Suggester/Context/GeoLocationContext', + ]; + + foreach ($annotations as $annotation) { AnnotationRegistry::registerFile(__DIR__ . "/../Annotation/{$annotation}.php"); } } diff --git a/ORM/Repository.php b/ORM/Repository.php index 2a2a6941..42ea2102 100644 --- a/ORM/Repository.php +++ b/ORM/Repository.php @@ -145,6 +145,13 @@ public function findBy( return $this->execute($search, $resultType); } + /** + * Returns auto complete data. + */ + public function getAutoComplete() + { + } + /** * Returns search instance. * From e748521963f3e6886b5ad44c21f428848b07a0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zigmas=20Satkevi=C4=8Dius?= Date: Thu, 27 Nov 2014 14:02:38 +0200 Subject: [PATCH 02/10] Added documents for indexing. --- Document/Suggester/AbstractSuggester.php | 60 ++++++++++++++++++- Document/Suggester/CompletionSuggester.php | 59 +++++++----------- .../Suggester/Context/AbstractContext.php | 9 ++- .../Suggester/Context/CategoryContext.php | 36 ++++++++--- .../Suggester/Context/GeoLocationContext.php | 37 +++++++++++- Document/Suggester/ContextSuggester.php | 47 ++++++++++++++- ORM/Manager.php | 6 ++ Result/Converter.php | 14 +++++ Tests/Functional/ORM/ManagerTest.php | 39 ++++++++++++ 9 files changed, 253 insertions(+), 54 deletions(-) diff --git a/Document/Suggester/AbstractSuggester.php b/Document/Suggester/AbstractSuggester.php index d5f0d096..48173750 100644 --- a/Document/Suggester/AbstractSuggester.php +++ b/Document/Suggester/AbstractSuggester.php @@ -19,10 +19,17 @@ abstract class AbstractSuggester /** * Input to store. * - * @var string[] + * @var string[]|string */ private $input; + /** + * String to return. + * + * @var string + */ + private $output; + /** * Setter for input to store. * @@ -30,7 +37,7 @@ abstract class AbstractSuggester */ public function setInput($input) { - $this->input = is_array($input) ? $input : [$input]; + $this->input = $input; } /** @@ -43,10 +50,59 @@ public function getInput() return $this->input; } + /** + * Setter for string to return. + * + * @param string $output + */ + public function setOutput($output) + { + $this->output = $output; + } + + /** + * Returns output to be set. + * + * @return string + */ + public function getOutput() + { + return $this->output; + } + /** * Returns suggester type. * * @return string */ abstract public function getType(); + + /** + * Returns array value of this suggester. + * + * @return array + */ + public function toArray() + { + $out = []; + + if ($this->getInput() !== null) { + $out['input'] = $this->getInput(); + } + + if ($this->getOutput() !== null) { + $out['output'] = $this->getOutput(); + } + + return $out; + } + + /** + * Sets object fields using the array passed. + * + * @param array $rawArray + */ + public function fromArray($rawArray) + { + } } diff --git a/Document/Suggester/CompletionSuggester.php b/Document/Suggester/CompletionSuggester.php index 1c5c3903..7799f437 100644 --- a/Document/Suggester/CompletionSuggester.php +++ b/Document/Suggester/CompletionSuggester.php @@ -15,22 +15,13 @@ /** * Class to be used for completion suggestion objects. - * - * @ES\Object */ -class CompletionSuggester extends AbstractSuggester +abstract class CompletionSuggester extends AbstractSuggester { - /** - * String to return. - * - * @var string - */ - private $output; - /** * Object to be returned in the suggest option. * - * @var object + * @var array */ private $payload; @@ -41,30 +32,10 @@ class CompletionSuggester extends AbstractSuggester */ private $weight; - /** - * Setter for string to return. - * - * @param string $output - */ - public function setOutput($output) - { - $this->output = $output; - } - - /** - * Returns output to be set. - * - * @return string - */ - public function getOutput() - { - return $this->output; - } - /** * Setter for object to be returned in the suggest option. * - * @param object $payload + * @param array $payload */ public function setPayload($payload) { @@ -74,7 +45,7 @@ public function setPayload($payload) /** * Returns object to be returned in the suggest option. * - * @return object + * @return array */ public function getPayload() { @@ -85,8 +56,6 @@ public function getPayload() * Setter for a weight used to rank suggestions. * * @param int|string $weight - * - * @return mixed */ public function setWeight($weight) { @@ -96,13 +65,31 @@ public function setWeight($weight) /** * Returns object to be returned in the suggest option. * - * @return object + * @return int|string */ public function getWeight() { return $this->weight; } + /** + * {@inheritdoc} + */ + public function toArray() + { + $out = parent::toArray(); + + if ($this->getWeight() !== null) { + $out['weight'] = $this->getWeight(); + } + + if ($this->getPayload() !== null) { + $out['payload'] = $this->getPayload(); + } + + return $out; + } + /** * {@inheritdoc} */ diff --git a/Document/Suggester/Context/AbstractContext.php b/Document/Suggester/Context/AbstractContext.php index 44ab34fe..d88a13a5 100644 --- a/Document/Suggester/Context/AbstractContext.php +++ b/Document/Suggester/Context/AbstractContext.php @@ -48,5 +48,12 @@ public function setName($name) * * @return string */ - abstract public function getType(); + abstract public function getContextType(); + + /** + * Returns context object value. + * + * @return string + */ + abstract public function getValue(); } diff --git a/Document/Suggester/Context/CategoryContext.php b/Document/Suggester/Context/CategoryContext.php index 7a3430b1..5079ba77 100644 --- a/Document/Suggester/Context/CategoryContext.php +++ b/Document/Suggester/Context/CategoryContext.php @@ -17,27 +17,45 @@ class CategoryContext extends AbstractContext { /** - * @var String|string[] + * Type to use as a context. + * + * @var string|array */ - private $value; + private $types; /** - * Returns context value. + * Returns type. * - * @return array + * @return string|array */ - public function getValue() + public function getTypes() { - return []; + return $this->types; } /** - * Returns context type. + * Sets type. * - * @return string + * @param $type string|array + */ + public function setTypes($types) + { + $this->types = $types; + } + + /** + * {@inheritdoc} */ - public function getType() + public function getContextType() { return 'category'; } + + /** + * {@inheritdoc} + */ + public function getValue() + { + return $this->types; + } } diff --git a/Document/Suggester/Context/GeoLocationContext.php b/Document/Suggester/Context/GeoLocationContext.php index 286e631f..76fa7dcd 100644 --- a/Document/Suggester/Context/GeoLocationContext.php +++ b/Document/Suggester/Context/GeoLocationContext.php @@ -17,12 +17,43 @@ class GeoLocationContext extends AbstractContext { /** - * Returns context type. + * @var array|string + */ + private $location; + + /** + * Returns location. + * + * @return array|string + */ + public function getLocation() + { + return $this->location; + } + + /** + * Sets location. * - * @return string + * @param array|string $location */ - public function getType() + public function setLocation($location) + { + $this->location = $location; + } + + /** + * {@inheritdoc} + */ + public function getContextType() { return 'geo_location'; } + + /** + * {@inheritdoc} + */ + public function getValue() + { + return $this->getLocation(); + } } diff --git a/Document/Suggester/ContextSuggester.php b/Document/Suggester/ContextSuggester.php index 21662237..45649384 100644 --- a/Document/Suggester/ContextSuggester.php +++ b/Document/Suggester/ContextSuggester.php @@ -11,17 +11,58 @@ namespace ONGR\ElasticsearchBundle\Document\Suggester; -use ONGR\ElasticsearchBundle\Annotation as ES; +use ONGR\ElasticsearchBundle\Document\Suggester\Context\AbstractContext; /** * Class to be used for context suggestion objects. - * - * @ES\Object */ class ContextSuggester extends AbstractSuggester { + /** + * Contexts for context suggester. + * + * @var AbstractContext[] + */ private $contexts; + /** + * @return AbstractContext[] + */ + public function getContexts() + { + return $this->contexts; + } + + /** + * @param AbstractContext[] $contexts + */ + public function setContexts($contexts) + { + $this->contexts = $contexts; + } + + /** + * @param AbstractContext $context + */ + public function addContext(AbstractContext $context) + { + $this->contexts[] = $context; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + $out = parent::toArray(); + + foreach ($this->contexts as $context) { + $out['context'][$context->getName()] = $context->getValue(); + } + + return $out; + } + /** * {@inheritdoc} */ diff --git a/ORM/Manager.php b/ORM/Manager.php index 88aa50b2..cd89a677 100644 --- a/ORM/Manager.php +++ b/ORM/Manager.php @@ -13,6 +13,7 @@ use ONGR\ElasticsearchBundle\Client\Connection; use ONGR\ElasticsearchBundle\Document\DocumentInterface; +use ONGR\ElasticsearchBundle\Document\Suggester\AbstractSuggester; use ONGR\ElasticsearchBundle\Mapping\MetadataCollector; /** @@ -164,6 +165,11 @@ private function convertToArray($object, $getters) $value = $newValue; } + + if ($value instanceof AbstractSuggester) { + $value = $value->toArray(); + } + if ($value instanceof \DateTime) { $value = $value->format(\DateTime::ISO8601); } diff --git a/Result/Converter.php b/Result/Converter.php index 54e6b1c4..f433e2e6 100644 --- a/Result/Converter.php +++ b/Result/Converter.php @@ -103,6 +103,10 @@ public function assignArrayToObject(array $array, $object, array $setters) $value = \DateTime::createFromFormat(\DateTime::ISO8601, $value); } + if ($setter['type'] === 'completion') { + $value = $this->handleSuggester($setter, $value); + } + if ($setter['exec']) { $object->{$setter['name']}($value); } else { @@ -112,4 +116,14 @@ public function assignArrayToObject(array $array, $object, array $setters) return $object; } + + /** + * Returns a suggester to set. + * + * @param array $setter + * @param array $value + */ + private function handleSuggester($setter, $value) + { + } } diff --git a/Tests/Functional/ORM/ManagerTest.php b/Tests/Functional/ORM/ManagerTest.php index 99d73297..24381767 100644 --- a/Tests/Functional/ORM/ManagerTest.php +++ b/Tests/Functional/ORM/ManagerTest.php @@ -12,6 +12,9 @@ namespace ONGR\ElasticsearchBundle\Tests\Functional\ORM; use ONGR\ElasticsearchBundle\Document\DocumentInterface; +use ONGR\ElasticsearchBundle\Document\Suggester\Context\CategoryContext; +use ONGR\ElasticsearchBundle\Document\Suggester\Context\GeoLocationContext; +use ONGR\ElasticsearchBundle\Document\Suggester\ContextSuggester; use ONGR\ElasticsearchBundle\ORM\Manager; use ONGR\ElasticsearchBundle\Test\ElasticsearchTestCase; use ONGR\TestingBundle\Document\CdnObject; @@ -72,6 +75,42 @@ public function testPersist() $this->assertEquals($cdn->cdn_url, $actualUrl[0]->cdn->cdn_url); } + /** + * Check if indexed suggest fields are stored as expected. + */ + public function testSuggesters() + { + /** @var Manager $manager */ + $manager = $this->getManager(); + + $suggester = new ContextSuggester(); + $suggester->setInput(['test']); + $categoryContext = new CategoryContext(); + $categoryContext->setName('price'); + $categoryContext->setTypes('500'); + + $locationContext = new GeoLocationContext(); + $locationContext->setName('location'); + $locationContext->setLocation(['lat' => 50, 'lon' => 50]); + + $suggester->addContext($categoryContext); + $suggester->addContext($locationContext); + + $product = new Product(); + $product->suggesting = $suggester; + + $manager->persist($product); + $manager->commit(); + + $repository = $manager->getRepository('ONGRTestingBundle:Product'); + /** @var Product[] $actualProduct */ + $actualProducts = $repository->execute($repository->createSearch()); + $this->assertCount(1, $actualProducts); + + /** @var Product $actualProduct */ + $actualProduct = $actualProducts->current(); + } + /** * Data provider for testPersistExceptions(). * From 381daf3e65bfa82379a7f95101eb11e493048517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zigmas=20Satkevi=C4=8Dius?= Date: Fri, 28 Nov 2014 15:26:15 +0200 Subject: [PATCH 03/10] Completed sugggestions indexing functionality. --- .../Suggester/AbstractSuggesterProperty.php | 43 +++++- .../Suggester/CompletionSuggesterProperty.php | 42 ------ .../Suggester/ContextSuggesterProperty.php | 9 +- Document/Suggester/CompletionSuggester.php | 100 -------------- .../CompletionSuggesterInterface.php | 16 +++ .../Suggester/CompletionSuggesterTrait.php | 22 +++ .../Suggester/Context/AbstractContext.php | 59 -------- .../Suggester/Context/CategoryContext.php | 61 --------- .../Suggester/Context/GeoLocationContext.php | 59 -------- Document/Suggester/ContextSuggester.php | 73 ---------- .../Suggester/ContextSuggesterInterface.php | 34 +++++ Document/Suggester/ContextSuggesterTrait.php | 40 ++++++ Document/Suggester/SuggesterInterface.php | 74 ++++++++++ ...stractSuggester.php => SuggesterTrait.php} | 66 ++++++--- Mapping/MappingTool.php | 2 + Mapping/MetadataCollector.php | 129 +++++++++++++----- ORM/Manager.php | 5 - Result/Converter.php | 6 +- Tests/Functional/ORM/ManagerTest.php | 37 +++-- 19 files changed, 394 insertions(+), 483 deletions(-) delete mode 100644 Document/Suggester/CompletionSuggester.php create mode 100644 Document/Suggester/CompletionSuggesterInterface.php create mode 100644 Document/Suggester/CompletionSuggesterTrait.php delete mode 100644 Document/Suggester/Context/AbstractContext.php delete mode 100644 Document/Suggester/Context/CategoryContext.php delete mode 100644 Document/Suggester/Context/GeoLocationContext.php delete mode 100644 Document/Suggester/ContextSuggester.php create mode 100644 Document/Suggester/ContextSuggesterInterface.php create mode 100644 Document/Suggester/ContextSuggesterTrait.php create mode 100644 Document/Suggester/SuggesterInterface.php rename Document/Suggester/{AbstractSuggester.php => SuggesterTrait.php} (52%) diff --git a/Annotation/Suggester/AbstractSuggesterProperty.php b/Annotation/Suggester/AbstractSuggesterProperty.php index 2a18bea9..53affdfc 100644 --- a/Annotation/Suggester/AbstractSuggesterProperty.php +++ b/Annotation/Suggester/AbstractSuggesterProperty.php @@ -29,19 +29,54 @@ abstract class AbstractSuggesterProperty public $name; /** - * Object name to map. - * * @var string + * + * @Required */ public $objectName; + /** + * @var string + */ + public $index_analyzer; + + /** + * @var string + */ + public $search_analyzer; + + /** + * @var int + */ + public $preserve_separators; + + /** + * @var bool + */ + public $preserve_position_increments; + + /** + * @var int + */ + public $max_input_length; + + /** + * @var bool + */ + public $payloads; + /** * Returns required properties. * + * @param array $extraExclude Extra object variables to exclude. + * * @return array */ - public function filter() + public function filter($extraExclude = []) { - return ['type' => $this->type]; + return array_diff_key( + array_filter(get_object_vars($this)), + array_flip(array_merge(['name', 'objectName', 'classObjectName'], $extraExclude)) + ); } } diff --git a/Annotation/Suggester/CompletionSuggesterProperty.php b/Annotation/Suggester/CompletionSuggesterProperty.php index 969adcb0..0fb2461a 100644 --- a/Annotation/Suggester/CompletionSuggesterProperty.php +++ b/Annotation/Suggester/CompletionSuggesterProperty.php @@ -19,46 +19,4 @@ */ class CompletionSuggesterProperty extends AbstractSuggesterProperty { - /** - * @var string - */ - public $index_analyzer; - - /** - * @var string - */ - public $search_analyzer; - - /** - * @var int - */ - public $preserve_separators; - - /** - * @var bool - */ - public $preserve_position_increments; - - /** - * @var int - */ - public $max_input_length; - - /** - * @var bool - */ - public $payloads; - - /** - * {@inheritdoc} - */ - public function filter() - { - $data = array_merge(parent::filter(), array_filter(get_object_vars($this))); - - return array_diff_key( - $data, - array_flip(['name', 'objectName']) - ); - } } diff --git a/Annotation/Suggester/ContextSuggesterProperty.php b/Annotation/Suggester/ContextSuggesterProperty.php index e2a6024c..95d5f2ed 100644 --- a/Annotation/Suggester/ContextSuggesterProperty.php +++ b/Annotation/Suggester/ContextSuggesterProperty.php @@ -20,14 +20,9 @@ class ContextSuggesterProperty extends AbstractSuggesterProperty /** * {@inheritdoc} */ - public function filter() + public function filter($extraExclude = []) { - $data = array_merge(parent::filter(), array_filter(get_object_vars($this))); - - $data = array_diff_key( - $data, - array_flip(['name', 'objectName', 'context']) - ); + $data = parent::filter(['context']); /** @var AbstractContext $singleContext */ foreach ($this->context as $singleContext) { diff --git a/Document/Suggester/CompletionSuggester.php b/Document/Suggester/CompletionSuggester.php deleted file mode 100644 index 7799f437..00000000 --- a/Document/Suggester/CompletionSuggester.php +++ /dev/null @@ -1,100 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ONGR\ElasticsearchBundle\Document\Suggester; - -use ONGR\ElasticsearchBundle\Annotation as ES; - -/** - * Class to be used for completion suggestion objects. - */ -abstract class CompletionSuggester extends AbstractSuggester -{ - /** - * Object to be returned in the suggest option. - * - * @var array - */ - private $payload; - - /** - * Weight used to rank suggestions. - * - * @var int|string - */ - private $weight; - - /** - * Setter for object to be returned in the suggest option. - * - * @param array $payload - */ - public function setPayload($payload) - { - $this->payload = $payload; - } - - /** - * Returns object to be returned in the suggest option. - * - * @return array - */ - public function getPayload() - { - return $this->payload; - } - - /** - * Setter for a weight used to rank suggestions. - * - * @param int|string $weight - */ - public function setWeight($weight) - { - $this->weight = $weight; - } - - /** - * Returns object to be returned in the suggest option. - * - * @return int|string - */ - public function getWeight() - { - return $this->weight; - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - $out = parent::toArray(); - - if ($this->getWeight() !== null) { - $out['weight'] = $this->getWeight(); - } - - if ($this->getPayload() !== null) { - $out['payload'] = $this->getPayload(); - } - - return $out; - } - - /** - * {@inheritdoc} - */ - public function getType() - { - return 'completion'; - } -} diff --git a/Document/Suggester/CompletionSuggesterInterface.php b/Document/Suggester/CompletionSuggesterInterface.php new file mode 100644 index 00000000..b9ae4315 --- /dev/null +++ b/Document/Suggester/CompletionSuggesterInterface.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Document\Suggester; + +use ONGR\ElasticsearchBundle\Annotation as ES; + +/** + * Trait to be used for completion suggestion objects. + */ +trait CompletionSuggesterTrait +{ + use SuggesterTrait; +} diff --git a/Document/Suggester/Context/AbstractContext.php b/Document/Suggester/Context/AbstractContext.php deleted file mode 100644 index d88a13a5..00000000 --- a/Document/Suggester/Context/AbstractContext.php +++ /dev/null @@ -1,59 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ONGR\ElasticsearchBundle\Document\Suggester\Context; - -/** - * Abstract context type for context suggester. - */ -abstract class AbstractContext -{ - /** - * Context name. - * - * @var string - */ - private $name; - - /** - * Returns context name. - * - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Sets context name. - * - * @param string $name - */ - public function setName($name) - { - $this->name = $name; - } - - /** - * Returns context type. - * - * @return string - */ - abstract public function getContextType(); - - /** - * Returns context object value. - * - * @return string - */ - abstract public function getValue(); -} diff --git a/Document/Suggester/Context/CategoryContext.php b/Document/Suggester/Context/CategoryContext.php deleted file mode 100644 index 5079ba77..00000000 --- a/Document/Suggester/Context/CategoryContext.php +++ /dev/null @@ -1,61 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ONGR\ElasticsearchBundle\Document\Suggester\Context; - -/** - * Category context type for context suggester. - */ -class CategoryContext extends AbstractContext -{ - /** - * Type to use as a context. - * - * @var string|array - */ - private $types; - - /** - * Returns type. - * - * @return string|array - */ - public function getTypes() - { - return $this->types; - } - - /** - * Sets type. - * - * @param $type string|array - */ - public function setTypes($types) - { - $this->types = $types; - } - - /** - * {@inheritdoc} - */ - public function getContextType() - { - return 'category'; - } - - /** - * {@inheritdoc} - */ - public function getValue() - { - return $this->types; - } -} diff --git a/Document/Suggester/Context/GeoLocationContext.php b/Document/Suggester/Context/GeoLocationContext.php deleted file mode 100644 index 76fa7dcd..00000000 --- a/Document/Suggester/Context/GeoLocationContext.php +++ /dev/null @@ -1,59 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ONGR\ElasticsearchBundle\Document\Suggester\Context; - -/** - * Abstract geo location context type for context suggester. - */ -class GeoLocationContext extends AbstractContext -{ - /** - * @var array|string - */ - private $location; - - /** - * Returns location. - * - * @return array|string - */ - public function getLocation() - { - return $this->location; - } - - /** - * Sets location. - * - * @param array|string $location - */ - public function setLocation($location) - { - $this->location = $location; - } - - /** - * {@inheritdoc} - */ - public function getContextType() - { - return 'geo_location'; - } - - /** - * {@inheritdoc} - */ - public function getValue() - { - return $this->getLocation(); - } -} diff --git a/Document/Suggester/ContextSuggester.php b/Document/Suggester/ContextSuggester.php deleted file mode 100644 index 45649384..00000000 --- a/Document/Suggester/ContextSuggester.php +++ /dev/null @@ -1,73 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ONGR\ElasticsearchBundle\Document\Suggester; - -use ONGR\ElasticsearchBundle\Document\Suggester\Context\AbstractContext; - -/** - * Class to be used for context suggestion objects. - */ -class ContextSuggester extends AbstractSuggester -{ - /** - * Contexts for context suggester. - * - * @var AbstractContext[] - */ - private $contexts; - - /** - * @return AbstractContext[] - */ - public function getContexts() - { - return $this->contexts; - } - - /** - * @param AbstractContext[] $contexts - */ - public function setContexts($contexts) - { - $this->contexts = $contexts; - } - - /** - * @param AbstractContext $context - */ - public function addContext(AbstractContext $context) - { - $this->contexts[] = $context; - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - $out = parent::toArray(); - - foreach ($this->contexts as $context) { - $out['context'][$context->getName()] = $context->getValue(); - } - - return $out; - } - - /** - * {@inheritdoc} - */ - public function getType() - { - return 'completion'; - } -} diff --git a/Document/Suggester/ContextSuggesterInterface.php b/Document/Suggester/ContextSuggesterInterface.php new file mode 100644 index 00000000..4a4da362 --- /dev/null +++ b/Document/Suggester/ContextSuggesterInterface.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Document\Suggester; + +use ONGR\ElasticsearchBundle\Annotation as ES; + +/** + * Interface to be used for completion suggestion objects. + */ +interface ContextSuggesterInterface extends SuggesterInterface +{ + /** + * Returns context to be used for completion. + * + * @return object + */ + public function getContext(); + + /** + * Sets context to be used for completion. + * + * @param object $context + */ + public function setContext($context); +} diff --git a/Document/Suggester/ContextSuggesterTrait.php b/Document/Suggester/ContextSuggesterTrait.php new file mode 100644 index 00000000..9d071b87 --- /dev/null +++ b/Document/Suggester/ContextSuggesterTrait.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Document\Suggester; + +/** + * Class to be used for context suggestion objects. + */ +trait ContextSuggesterTrait +{ + use SuggesterTrait; + + /** + * Returns context to be used for completion. + * + * @return object + */ + public function getContext() + { + return $this->context; + } + + /** + * Sets context to be used for completion. + * + * @param object $context + */ + public function setContext($context) + { + $this->context = $context; + } +} diff --git a/Document/Suggester/SuggesterInterface.php b/Document/Suggester/SuggesterInterface.php new file mode 100644 index 00000000..28aea4ac --- /dev/null +++ b/Document/Suggester/SuggesterInterface.php @@ -0,0 +1,74 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Document\Suggester; + +/** + * Interface for a basic suggester. + */ +interface SuggesterInterface +{ + /** + * Setter for input to store. + * + * @param string $input + */ + public function setInput($input); + + /** + * Returns stored input. + * + * @return string|string[] + */ + public function getInput(); + + /** + * Setter for string to return. + * + * @param string $output + */ + public function setOutput($output); + + /** + * Returns output to be set. + * + * @return string + */ + public function getOutput(); + + /** + * Returns object to be returned in the suggest option. + * + * @return int|string + */ + public function getWeight(); + + /** + * Setter for a weight used to rank suggestions. + * + * @param int|string $weight + */ + public function setWeight($weight); + + /** + * Returns object to be returned in the suggest option. + * + * @return object + */ + public function getPayload(); + + /** + * Setter for object to be returned in the suggest option. + * + * @param object $payload + */ + public function setPayload($payload); +} diff --git a/Document/Suggester/AbstractSuggester.php b/Document/Suggester/SuggesterTrait.php similarity index 52% rename from Document/Suggester/AbstractSuggester.php rename to Document/Suggester/SuggesterTrait.php index 48173750..dbc2f955 100644 --- a/Document/Suggester/AbstractSuggester.php +++ b/Document/Suggester/SuggesterTrait.php @@ -14,12 +14,14 @@ /** * Abstract record document for various suggesters. */ -abstract class AbstractSuggester +trait SuggesterTrait { /** * Input to store. * * @var string[]|string + * + * @ES\Property(type="string", name="input") */ private $input; @@ -27,9 +29,29 @@ abstract class AbstractSuggester * String to return. * * @var string + * + * @ES\Property(type="string", name="output") */ private $output; + /** + * Object to be returned in the suggest option. + * + * @var object + * + * @ES\Property(type="object", name="payload") + */ + private $payload; + + /** + * Weight used to rank suggestions. + * + * @var int|string + * + * @ES\Property(type="string", name="weight") + */ + private $weight; + /** * Setter for input to store. * @@ -71,38 +93,42 @@ public function getOutput() } /** - * Returns suggester type. + * Setter for object to be returned in the suggest option. * - * @return string + * @param object $payload */ - abstract public function getType(); + public function setPayload($payload) + { + $this->payload = (object)$payload; + } /** - * Returns array value of this suggester. + * Returns object to be returned in the suggest option. * - * @return array + * @return object */ - public function toArray() + public function getPayload() { - $out = []; - - if ($this->getInput() !== null) { - $out['input'] = $this->getInput(); - } - - if ($this->getOutput() !== null) { - $out['output'] = $this->getOutput(); - } + return $this->payload; + } - return $out; + /** + * Setter for a weight used to rank suggestions. + * + * @param int|string $weight + */ + public function setWeight($weight) + { + $this->weight = $weight; } /** - * Sets object fields using the array passed. + * Returns object to be returned in the suggest option. * - * @param array $rawArray + * @return int|string */ - public function fromArray($rawArray) + public function getWeight() { + return $this->weight; } } diff --git a/Mapping/MappingTool.php b/Mapping/MappingTool.php index 43a8992f..772e9d4d 100644 --- a/Mapping/MappingTool.php +++ b/Mapping/MappingTool.php @@ -26,6 +26,8 @@ class MappingTool 'max_input_length' => 50, 'preserve_separators' => true, 'preserve_position_increments' => true, + 'index_analyzer' => 'simple', + 'search_analyzer' => 'simple', 'analyzer' => 'simple', 'payloads' => false, ]; diff --git a/Mapping/MetadataCollector.php b/Mapping/MetadataCollector.php index 64c0a28e..99560158 100644 --- a/Mapping/MetadataCollector.php +++ b/Mapping/MetadataCollector.php @@ -17,6 +17,9 @@ use ONGR\ElasticsearchBundle\Annotation\Document; use ONGR\ElasticsearchBundle\Annotation\MultiField; use ONGR\ElasticsearchBundle\Annotation\Property; +use ONGR\ElasticsearchBundle\Annotation\Suggester\AbstractSuggesterProperty; +use ONGR\ElasticsearchBundle\Annotation\Suggester\CompletionSuggesterProperty; +use ONGR\ElasticsearchBundle\Annotation\Suggester\ContextSuggesterProperty; use ONGR\ElasticsearchBundle\Document\DocumentInterface; /** @@ -24,6 +27,17 @@ */ class MetadataCollector { + + /** + * @const string + */ + const SUGGESTER_PROPERTY_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Suggester\AbstractSuggesterProperty'; + + /** + * @const string + */ + const PROPERTY_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Property'; + /** * @var array */ @@ -55,6 +69,13 @@ class MetadataCollector */ private $aliases = []; + /** + * Contains suggester object mapping to be used for getters and setters. + * + * @var array + */ + private $suggesters = []; + /** * Directory in bundle to load documents from. * @@ -242,7 +263,7 @@ private function getDocumentType(\ReflectionClass $reflectionClass, Document $do /** * @param array $params Property parameters. - * @param array $alias Actual property name (not field name). + * @param string $alias Actual property name (not field name). * @param \ReflectionClass $reflectionClass Reflection class. * * @return array @@ -252,6 +273,13 @@ private function getInfoAboutProperty($params, $alias, $reflectionClass) $setter = $this->checkPropertyAccess($alias, 'set', $reflectionClass); $getter = $this->checkPropertyAccess($alias, 'get', $reflectionClass); + if ($params['type'] === 'completion') { + if (isset($this->suggesters[$reflectionClass->getName()][$alias])) { + $suggestionObjectNamespace = $this->suggesters[$reflectionClass->getName()][$alias]; + $params['properties'] = $this->objects[$suggestionObjectNamespace]['properties']; + } + } + if (isset($params['properties'])) { $data = $this->getInfoAboutPropertyObject($params['properties'], $alias, $reflectionClass); $setter['properties'] = $data['setter']; @@ -315,10 +343,7 @@ private function checkPropertyAccess($property, $methodPrefix, $reflectionClass) private function getInfoAboutPropertyObject($params, $propertyName, $reflectionClass) { /** @var Property $type */ - $type = $this->reader->getPropertyAnnotation( - $reflectionClass->getProperty($propertyName), - 'ONGR\ElasticsearchBundle\Annotation\Property' - ); + $type = $this->getPropertyAnnotationData($reflectionClass->getProperty($propertyName)); $childReflection = new \ReflectionClass($this->getNamespace($type->objectName)); @@ -336,7 +361,7 @@ private function getInfoAboutPropertyObject($params, $propertyName, $reflectionC 'setter' => $setters, 'getter' => $getters, 'namespace' => $this->getNamespace($type->objectName), - 'multiple' => $type->multiple, + 'multiple' => $type instanceof Property ? $type->multiple : false, ]; } @@ -390,42 +415,63 @@ private function getProperties(\ReflectionClass $reflectionClass) $mapping = []; /** @var \ReflectionProperty $property */ foreach ($reflectionClass->getProperties() as $property) { - /** @var Property $type */ - $type = $this->reader->getPropertyAnnotation($property, 'ONGR\ElasticsearchBundle\Annotation\Property'); - if ($type === null) { - $type = $this->reader->getPropertyAnnotation($property, 'ONGR\ElasticsearchBundle\Annotation\Suggester\AbstractSuggesterProperty'); + $type = $this->getPropertyAnnotationData($property); + + if (empty($type)) { + continue; } - if (!empty($type)) { - $maps = $type->filter(); - $this->aliases[$reflectionClass->getName()][$type->name] = $property->getName(); - - // Object. - if (($type->type === 'object' || $type->type === 'nested') && !empty($type->objectName)) { - if (!empty($this->objects[strtolower($type->objectName)])) { - $objMap = $this->objects[strtolower($type->objectName)]; - } else { - $objMap = $this->getRelationMapping($type->objectName); - $this->objects[strtolower($type->objectName)] = $objMap; - } - $maps = array_replace_recursive($maps, $objMap); - } - // MultiField. - if (isset($maps['fields']) && !in_array($type, ['object', 'nested'])) { - $fieldsMap = []; - /** @var MultiField $field */ - foreach ($maps['fields'] as $field) { - $fieldsMap[$field->name] = $field->filter(); - } - $maps['fields'] = $fieldsMap; + $maps = $type->filter(); + $this->aliases[$reflectionClass->getName()][$type->name] = $property->getName(); + + // Object. + if (in_array($type->type, ['object', 'nested']) && !empty($type->objectName)) { + $maps = array_replace_recursive($maps, $this->getObjectMapping($type->objectName)); + } + + // MultiField. + if (isset($maps['fields']) && !in_array($type->type, ['object', 'nested'])) { + $fieldsMap = []; + /** @var MultiField $field */ + foreach ($maps['fields'] as $field) { + $fieldsMap[$field->name] = $field->filter(); } - $mapping[$type->name] = $maps; + $maps['fields'] = $fieldsMap; + } + + // Suggesters. + if ($type instanceof AbstractSuggesterProperty) { + $this->getObjectMapping($type->objectName); + $this->suggesters[$reflectionClass->getName()][$property->getName()] = strtolower($type->objectName); } + + $mapping[$type->name] = $maps; } return $mapping; } + /** + * Returns object mapping. + * + * Loads from cache if it's already loaded. + * + * @param string $objectName + * + * @return array + */ + private function getObjectMapping($objectName) + { + if (!empty($this->objects[strtolower($objectName)])) { + $objMap = $this->objects[strtolower($objectName)]; + } else { + $objMap = $this->getRelationMapping($objectName); + $this->objects[strtolower($objectName)] = $objMap; + } + + return $objMap; + } + /** * Registers annotations to registry so that it could be used by reader. */ @@ -483,4 +529,21 @@ private function getBundle($name) throw new \LogicException(sprintf('Bundle \'%s\' does not exist.', $name)); } + + /** + * Returns property annotation data. + * + * @param \ReflectionProperty $property + * + * @return AbstractSuggesterProperty|Property + */ + private function getPropertyAnnotationData($property) + { + $type = $this->reader->getPropertyAnnotation($property, self::PROPERTY_ANNOTATION); + if ($type === null) { + $type = $this->reader->getPropertyAnnotation($property, self::SUGGESTER_PROPERTY_ANNOTATION); + } + + return $type; + } } diff --git a/ORM/Manager.php b/ORM/Manager.php index cd89a677..e2952c62 100644 --- a/ORM/Manager.php +++ b/ORM/Manager.php @@ -13,7 +13,6 @@ use ONGR\ElasticsearchBundle\Client\Connection; use ONGR\ElasticsearchBundle\Document\DocumentInterface; -use ONGR\ElasticsearchBundle\Document\Suggester\AbstractSuggester; use ONGR\ElasticsearchBundle\Mapping\MetadataCollector; /** @@ -166,10 +165,6 @@ private function convertToArray($object, $getters) $value = $newValue; } - if ($value instanceof AbstractSuggester) { - $value = $value->toArray(); - } - if ($value instanceof \DateTime) { $value = $value->format(\DateTime::ISO8601); } diff --git a/Result/Converter.php b/Result/Converter.php index f433e2e6..8a013d18 100644 --- a/Result/Converter.php +++ b/Result/Converter.php @@ -99,14 +99,10 @@ public function assignArrayToObject(array $array, $object, array $setters) } } - if ($setter['type'] === 'date') { + if (isset($setter['type']) && $setter['type'] === 'date') { $value = \DateTime::createFromFormat(\DateTime::ISO8601, $value); } - if ($setter['type'] === 'completion') { - $value = $this->handleSuggester($setter, $value); - } - if ($setter['exec']) { $object->{$setter['name']}($value); } else { diff --git a/Tests/Functional/ORM/ManagerTest.php b/Tests/Functional/ORM/ManagerTest.php index 24381767..56d23b36 100644 --- a/Tests/Functional/ORM/ManagerTest.php +++ b/Tests/Functional/ORM/ManagerTest.php @@ -12,14 +12,14 @@ namespace ONGR\ElasticsearchBundle\Tests\Functional\ORM; use ONGR\ElasticsearchBundle\Document\DocumentInterface; -use ONGR\ElasticsearchBundle\Document\Suggester\Context\CategoryContext; -use ONGR\ElasticsearchBundle\Document\Suggester\Context\GeoLocationContext; -use ONGR\ElasticsearchBundle\Document\Suggester\ContextSuggester; use ONGR\ElasticsearchBundle\ORM\Manager; use ONGR\ElasticsearchBundle\Test\ElasticsearchTestCase; use ONGR\TestingBundle\Document\CdnObject; use ONGR\TestingBundle\Document\Comment; +use ONGR\TestingBundle\Document\CompletionSuggesting; use ONGR\TestingBundle\Document\Product; +use ONGR\TestingBundle\Document\PriceLocationSuggesting; +use ONGR\TestingBundle\Document\PriceLocationContext; use ONGR\TestingBundle\Document\UrlObject; /** @@ -78,26 +78,29 @@ public function testPersist() /** * Check if indexed suggest fields are stored as expected. */ - public function testSuggesters() + public function testPersistSuggesters() { /** @var Manager $manager */ $manager = $this->getManager(); - $suggester = new ContextSuggester(); + $categoryContext = new PriceLocationContext(); + $categoryContext->price = '500'; + $categoryContext->location = ['lat' => 50, 'lon' => 50]; + $suggester = new PriceLocationSuggesting(); $suggester->setInput(['test']); - $categoryContext = new CategoryContext(); - $categoryContext->setName('price'); - $categoryContext->setTypes('500'); + $suggester->setOutput('success'); + $suggester->setContext($categoryContext); + $suggester->setPayload(['test']); + $suggester->setWeight(50); - $locationContext = new GeoLocationContext(); - $locationContext->setName('location'); - $locationContext->setLocation(['lat' => 50, 'lon' => 50]); - - $suggester->addContext($categoryContext); - $suggester->addContext($locationContext); + $completionSuggester = new CompletionSuggesting(); + $completionSuggester->setInput(['a', 'b', 'c']); + $completionSuggester->setOutput('completion success'); + $completionSuggester->setWeight(30); $product = new Product(); - $product->suggesting = $suggester; + $product->contextSuggesting = $suggester; + $product->completionSuggesting = $completionSuggester; $manager->persist($product); $manager->commit(); @@ -109,6 +112,10 @@ public function testSuggesters() /** @var Product $actualProduct */ $actualProduct = $actualProducts->current(); + $actualProduct->setId(null); + $actualProduct->setScore(null); + + $this->assertEquals($product, $actualProduct); } /** From 05f4c0ccc7d94c1f9c1f6679abfd62cd64a53502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zigmas=20Satkevi=C4=8Dius?= Date: Fri, 28 Nov 2014 17:34:28 +0200 Subject: [PATCH 04/10] Added context suggester DSL. --- DSL/Suggester/Context.php | 107 ++++++++++++++ DSL/Suggester/Context/AbstractContext.php | 87 +++++++++++ DSL/Suggester/Context/CategoryContext.php | 26 ++++ DSL/Suggester/Context/GeoContext.php | 53 +++++++ Result/Converter.php | 10 -- .../Functional/DSL/Suggester/ContextTest.php | 136 ++++++++++++++++++ 6 files changed, 409 insertions(+), 10 deletions(-) create mode 100644 DSL/Suggester/Context.php create mode 100644 DSL/Suggester/Context/AbstractContext.php create mode 100644 DSL/Suggester/Context/CategoryContext.php create mode 100644 DSL/Suggester/Context/GeoContext.php create mode 100644 Tests/Functional/DSL/Suggester/ContextTest.php diff --git a/DSL/Suggester/Context.php b/DSL/Suggester/Context.php new file mode 100644 index 00000000..06c16108 --- /dev/null +++ b/DSL/Suggester/Context.php @@ -0,0 +1,107 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\DSL\Suggester; + +use ONGR\ElasticsearchBundle\DSL\Suggester\Context\AbstractContext; + +/** + * Context suggester. + */ +class Context extends AbstractSuggester +{ + /** + * @var AbstractContext[] + */ + private $context; + + /** + * Size of completion. + * + * @var int + */ + 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/DSL/Suggester/Context/AbstractContext.php b/DSL/Suggester/Context/AbstractContext.php new file mode 100644 index 00000000..f9f0a724 --- /dev/null +++ b/DSL/Suggester/Context/AbstractContext.php @@ -0,0 +1,87 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\DSL\Suggester\Context; + +/** + * Abstract context to be used by geo context and category context. + */ +abstract class AbstractContext +{ + /** + * Name of the context used. + * + * @var string + */ + private $name; + + /** + * Value of the context. + * + * @var string|array + */ + 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/DSL/Suggester/Context/CategoryContext.php b/DSL/Suggester/Context/CategoryContext.php new file mode 100644 index 00000000..51429cd3 --- /dev/null +++ b/DSL/Suggester/Context/CategoryContext.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\DSL\Suggester\Context; + +/** + * Category context to be used by context suggester. + */ +class CategoryContext extends AbstractContext +{ + /** + * {@inheritdoc} + */ + public function toArray() + { + return $this->getValue(); + } +} diff --git a/DSL/Suggester/Context/GeoContext.php b/DSL/Suggester/Context/GeoContext.php new file mode 100644 index 00000000..2d01eac1 --- /dev/null +++ b/DSL/Suggester/Context/GeoContext.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\DSL\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/Result/Converter.php b/Result/Converter.php index 8a013d18..2c25164b 100644 --- a/Result/Converter.php +++ b/Result/Converter.php @@ -112,14 +112,4 @@ public function assignArrayToObject(array $array, $object, array $setters) return $object; } - - /** - * Returns a suggester to set. - * - * @param array $setter - * @param array $value - */ - private function handleSuggester($setter, $value) - { - } } diff --git a/Tests/Functional/DSL/Suggester/ContextTest.php b/Tests/Functional/DSL/Suggester/ContextTest.php new file mode 100644 index 00000000..c07315b1 --- /dev/null +++ b/Tests/Functional/DSL/Suggester/ContextTest.php @@ -0,0 +1,136 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\Functional\DSL\Suggester; + +use ONGR\ElasticsearchBundle\DSL\Suggester\Context; +use ONGR\ElasticsearchBundle\ORM\Repository; +use ONGR\ElasticsearchBundle\Test\ElasticsearchTestCase; + +/** + * Tests for context suggester. + */ +class ContextTest extends ElasticsearchTestCase +{ + /** + * {@inheritdoc} + */ + protected function getDataArray() + { + return [ + 'default' => [ + 'product' => [ + [ + '_id' => 1, + 'title' => 'foo', + 'suggestions' => [ + 'input' => ['Lorem', 'ipsum', 'cons'], + 'output' => 'Lorem ipsum', + 'payload' => new \stdClass(), + 'weight' => 1, + 'context' => [ + 'location' => [0, 0], + 'price' => 500, + ], + ], + ], + [ + '_id' => 2, + 'title' => 'bar', + 'suggestions' => [ + 'input' => ['Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'cons'], + 'output' => 'Lorem ipsum dolor sit amet...', + 'payload' => new \stdClass(), + 'weight' => 2, + 'context' => [ + 'location' => [1, 1], + 'price' => 500, + ], + ], + ], + [ + '_id' => 3, + 'title' => 'baz', + 'suggestions' => [ + 'input' => ['Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipisicing', 'elit'], + 'output' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit...', + 'payload' => ['my' => 'data'], + 'weight' => 3, + 'context' => [ + 'location' => [3, 3], + 'price' => 700, + ], + ], + ], + ], + ], + ]; + } + + /** + * Executes completion suggester. + */ + public function testContextSuggester() + { + $geoContext = new Context\GeoContext('location', ['lat' => 0, 'lon' => 0]); + $categoryContext = new Context\CategoryContext('price', '500'); + + $context = new Context('suggestions', 'cons'); + $context->addContext($geoContext); + $context->addContext($categoryContext); + + $repository = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $search = $repository->createSearch()->addSuggester($context); + $result = $repository->execute($search, Repository::RESULTS_RAW); + + $this->assertArrayHasKey('score', $result['suggest']['suggestions-completion'][0]['options'][0]); + unset($result['suggest']['suggestions-completion'][0]['options'][0]['score']); + + $this->assertEquals( + [ + 'suggestions-completion' => [ + [ + 'text' => 'cons', + 'offset' => 0, + 'length' => 4, + 'options' => [ + [ + 'text' => 'Lorem ipsum', + 'payload' => [], + ], + ], + ], + ], + ], + $result['suggest'] + ); + } + + /** + * Check if precision setting works as expected. + */ + public function testContextSuggesterPrecision() + { + $geoContext = new Context\GeoContext('location', ['lat' => 0, 'lon' => 0]); + $geoContext->setPrecision('10000km'); + $categoryContext = new Context\CategoryContext('price', '500'); + + $context = new Context('suggestions', 'cons'); + $context->addContext($geoContext); + $context->addContext($categoryContext); + + $repository = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $search = $repository->createSearch()->addSuggester($context); + $result = $repository->execute($search, Repository::RESULTS_RAW); + + $this->assertEmpty($result['suggest']['suggestions-completion'][0]['options']); + } +} From cfa28f86d1e33fd0c5d54fdafa51d22753f4b5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zigmas=20Satkevi=C4=8Dius?= Date: Tue, 2 Dec 2014 12:10:28 +0200 Subject: [PATCH 05/10] Added suggestions iterator. --- Result/DocumentIterator.php | 7 +- Result/Suggestion/Option/CompletionOption.php | 48 +++++ Result/Suggestion/Option/PhraseOption.php | 48 +++++ Result/Suggestion/Option/SimpleOption.php | 70 ++++++ Result/Suggestion/Option/TermOption.php | 48 +++++ Result/Suggestion/OptionIterator.php | 154 +++++++++++++ Result/Suggestion/SuggestionEntry.php | 94 ++++++++ Result/Suggestion/SuggestionIterator.php | 147 +++++++++++++ Result/Suggestions.php | 69 ------ .../Result/SuggestionsIteratorTest.php | 204 ++++++++++++++++++ Tests/Unit/Result/DocumentIteratorTest.php | 33 ++- Tests/Unit/Result/SuggestionsTest.php | 82 ------- 12 files changed, 840 insertions(+), 164 deletions(-) create mode 100644 Result/Suggestion/Option/CompletionOption.php create mode 100644 Result/Suggestion/Option/PhraseOption.php create mode 100644 Result/Suggestion/Option/SimpleOption.php create mode 100644 Result/Suggestion/Option/TermOption.php create mode 100644 Result/Suggestion/OptionIterator.php create mode 100644 Result/Suggestion/SuggestionEntry.php create mode 100644 Result/Suggestion/SuggestionIterator.php delete mode 100644 Result/Suggestions.php create mode 100644 Tests/Functional/Result/SuggestionsIteratorTest.php delete mode 100644 Tests/Unit/Result/SuggestionsTest.php diff --git a/Result/DocumentIterator.php b/Result/DocumentIterator.php index d16679d7..6824cb09 100644 --- a/Result/DocumentIterator.php +++ b/Result/DocumentIterator.php @@ -14,6 +14,7 @@ use ONGR\ElasticsearchBundle\Document\DocumentInterface; use ONGR\ElasticsearchBundle\DSL\Aggregation\Aggregations; use ONGR\ElasticsearchBundle\Result\Aggregation\AggregationIterator; +use ONGR\ElasticsearchBundle\Result\Suggestion\SuggestionIterator; /** * This class is able to iterate over Elasticsearch result documents while casting data into models. @@ -41,7 +42,7 @@ class DocumentIterator extends AbstractResultsIterator private $aggregations; /** - * @var Suggestions + * @var SuggestionIterator */ private $suggestions; @@ -143,12 +144,12 @@ public function getAggregations() /** * Returns suggestions. * - * @return Suggestions + * @return SuggestionIterator */ public function getSuggestions() { if (isset($this->rawData['suggest'])) { - $this->suggestions = new Suggestions($this->rawData['suggest']); + $this->suggestions = new SuggestionIterator($this->rawData['suggest']); // Clear memory. unset($this->rawData['suggest']); diff --git a/Result/Suggestion/Option/CompletionOption.php b/Result/Suggestion/Option/CompletionOption.php new file mode 100644 index 00000000..f5c479b7 --- /dev/null +++ b/Result/Suggestion/Option/CompletionOption.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use ONGR\ElasticsearchBundle\Result\Suggestion\Option; + +/** + * Data holder for completion option, used by context and completion suggesters. + */ +class CompletionOption extends SimpleOption +{ + /** + * @var array + */ + private $payload; + + /** + * Constructor. + * + * @param string $text + * @param float $score + * @param array $payload + */ + public function __construct($text, $score, $payload) + { + $this->payload = $payload; + parent::__construct($text, $score); + } + + /** + * Returns payload data. + * + * @return string + */ + public function getPayload() + { + return $this->payload; + } +} diff --git a/Result/Suggestion/Option/PhraseOption.php b/Result/Suggestion/Option/PhraseOption.php new file mode 100644 index 00000000..651b551a --- /dev/null +++ b/Result/Suggestion/Option/PhraseOption.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use ONGR\ElasticsearchBundle\Result\Suggestion\Option; + +/** + * Data holder for phrase option. + */ +class PhraseOption extends SimpleOption +{ + /** + * @var string + */ + private $highlighted; + + /** + * Constructor. + * + * @param string $text + * @param float $score + * @param string $highlighted + */ + public function __construct($text, $score, $highlighted) + { + $this->highlighted = $highlighted; + parent::__construct($text, $score); + } + + /** + * Returns highlighted suggestion. + * + * @return string + */ + public function getHighlighted() + { + return $this->highlighted; + } +} diff --git a/Result/Suggestion/Option/SimpleOption.php b/Result/Suggestion/Option/SimpleOption.php new file mode 100644 index 00000000..2c4b051a --- /dev/null +++ b/Result/Suggestion/Option/SimpleOption.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Result\Suggestion\Option; + +/** + * Option data class. + */ +class SimpleOption +{ + /** + * @var string + */ + private $text; + + /** + * @var float + */ + private $score; + + /** + * Constructor. + * + * @param string $text + * @param float $score + */ + public function __construct($text, $score) + { + $this->score = $score; + $this->text = $text; + } + + /** + * Suggester score. + * + * @return float + */ + public function getScore() + { + return $this->score; + } + + /** + * Suggested text. + * + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * Sets option score. + * + * @param float $score + */ + public function setScore($score) + { + $this->score = $score; + } +} diff --git a/Result/Suggestion/Option/TermOption.php b/Result/Suggestion/Option/TermOption.php new file mode 100644 index 00000000..3717186d --- /dev/null +++ b/Result/Suggestion/Option/TermOption.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use ONGR\ElasticsearchBundle\Result\Suggestion\Option; + +/** + * Data holder for term option. + */ +class TermOption extends SimpleOption +{ + /** + * @var int + */ + private $freq; + + /** + * Constructor. + * + * @param string $text + * @param float $score + * @param int $freq + */ + public function __construct($text, $score, $freq) + { + $this->freq = $freq; + parent::__construct($text, $score); + } + + /** + * Returns suggested text document frequency. + * + * @return int + */ + public function getFreq() + { + return $this->freq; + } +} diff --git a/Result/Suggestion/OptionIterator.php b/Result/Suggestion/OptionIterator.php new file mode 100644 index 00000000..88d7736f --- /dev/null +++ b/Result/Suggestion/OptionIterator.php @@ -0,0 +1,154 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Result\Suggestion; + +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\CompletionOption; +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\PhraseOption; +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\SimpleOption; +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\TermOption; + +/** + * Suggestions results holder. + */ +class OptionIterator implements \ArrayAccess, \Iterator +{ + /** + * @var array + */ + private $rawData = []; + + /** + * @var SimpleOption[] + */ + private $convertedData = []; + + /** + * Constructor. + * + * @param array $rawData + */ + public function __construct($rawData) + { + $this->rawData = $rawData; + } + + /** + * {@inheritdoc} + */ + public function offsetExists($offset) + { + return isset($this->rawData[$offset]) || isset($this->convertedData[$offset]); + } + + /** + * Offset to retrieve. + * + * @param string|int $offset + * + * @return SimpleOption|null + */ + public function offsetGet($offset) + { + if (!$this->offsetExists($offset)) { + return null; + } + + if (!isset($this->convertedData[$offset])) { + $this->convertedData[$offset] = $this->convert($this->rawData[$offset]); + $this->rawData[$offset] = null; + } + + return $this->convertedData[$offset]; + } + + /** + * {@inheritdoc} + */ + public function offsetSet($offset, $value) + { + throw new \LogicException('Data of this iterator can not be changed after initialization.'); + } + + /** + * {@inheritdoc} + */ + public function offsetUnset($offset) + { + throw new \LogicException('Data of this iterator can not be changed after initialization.'); + } + + // Methods below implements \Iterator interface. + + /** + * {@inheritdoc} + */ + public function current() + { + return $this->offsetGet($this->key()); + } + + /** + * {@inheritdoc} + */ + public function next() + { + next($this->rawData); + } + + /** + * {@inheritdoc} + */ + public function key() + { + return key($this->rawData); + } + + /** + * {@inheritdoc} + */ + public function valid() + { + return $this->key() !== null; + } + + /** + * {@inheritdoc} + */ + public function rewind() + { + reset($this->rawData); + } + + /** + * Converts array to a array of suggestion objects. + * + * @param array $data + * + * @return SimpleOption + */ + private function convert($data) + { + if (isset($data['freq'])) { + return new TermOption($data['text'], $data['score'], $data['freq']); + } + + if (isset($data['highlighted'])) { + return new PhraseOption($data['text'], $data['score'], $data['highlighted']); + } + + if (isset($data['payload'])) { + return new CompletionOption($data['text'], $data['score'], $data['payload']); + } + + return new SimpleOption($data['text'], $data['score']); + } +} diff --git a/Result/Suggestion/SuggestionEntry.php b/Result/Suggestion/SuggestionEntry.php new file mode 100644 index 00000000..ce18551c --- /dev/null +++ b/Result/Suggestion/SuggestionEntry.php @@ -0,0 +1,94 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Result\Suggestion; + +/** + * Suggestions results holder. + */ +class SuggestionEntry +{ + /** + * @var OptionIterator + */ + private $options; + + /** + * @var string + */ + private $text; + + /** + * @var int + */ + private $offset; + + /** + * @var int + */ + private $length; + + /** + * Constructor. + * + * @param string $text + * @param int $offset + * @param int $length + * @param OptionIterator $options + */ + public function __construct($text, $offset, $length, OptionIterator $options) + { + $this->text = $text; + $this->offset = $offset; + $this->length = $length; + $this->options = $options; + } + + /** + * Return original length. + * + * @return int + */ + public function getLength() + { + return $this->length; + } + + /** + * Returns original start offset. + * + * @return int + */ + public function getOffset() + { + return $this->offset; + } + + /** + * Returns original text. + * + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * Returns suggested options. + * + * @return OptionIterator + */ + public function getOptions() + { + return $this->options; + } +} diff --git a/Result/Suggestion/SuggestionIterator.php b/Result/Suggestion/SuggestionIterator.php new file mode 100644 index 00000000..be7b9cc3 --- /dev/null +++ b/Result/Suggestion/SuggestionIterator.php @@ -0,0 +1,147 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Result\Suggestion; + +/** + * Suggestions results holder. + */ +class SuggestionIterator implements \ArrayAccess, \Iterator +{ + /** + * @var array + */ + private $rawData = []; + + /** + * @var SuggestionEntry[] + */ + private $convertedData = []; + + /** + * Constructor. + * + * @param array $rawData + */ + public function __construct($rawData) + { + $this->rawData = $rawData; + } + + /** + * {@inheritdoc} + */ + public function offsetExists($offset) + { + return isset($this->rawData[$offset]) || isset($this->convertedData[$offset]); + } + + /** + * Offset to retrieve. + * + * @param string|int $offset + * + * @return SuggestionEntry[]|null + */ + public function offsetGet($offset) + { + if (!$this->offsetExists($offset)) { + return null; + } + + if (!isset($this->convertedData[$offset])) { + $this->convertedData[$offset] = $this->convert($this->rawData[$offset]); + $this->rawData[$offset] = null; + } + + return $this->convertedData[$offset]; + } + + /** + * {@inheritdoc} + */ + public function offsetSet($offset, $value) + { + throw new \LogicException('Data of this iterator can not be changed after initialization.'); + } + + /** + * {@inheritdoc} + */ + public function offsetUnset($offset) + { + throw new \LogicException('Data of this iterator can not be changed after initialization.'); + } + + // Methods below implements \Iterator interface. + + /** + * {@inheritdoc} + */ + public function current() + { + return $this->offsetGet($this->key()); + } + + /** + * {@inheritdoc} + */ + public function next() + { + next($this->rawData); + } + + /** + * {@inheritdoc} + */ + public function key() + { + return key($this->rawData); + } + + /** + * {@inheritdoc} + */ + public function valid() + { + return $this->key() !== null; + } + + /** + * {@inheritdoc} + */ + public function rewind() + { + reset($this->rawData); + } + + /** + * Converts array to a array of suggestion objects. + * + * @param array $data + * + * @return SuggestionEntry[] + */ + private function convert($data) + { + $out = []; + foreach ($data as $entry) { + $out[] = new SuggestionEntry( + $entry['text'], + $entry['offset'], + $entry['length'], + new OptionIterator($entry['options']) + ); + } + + return $out; + } +} diff --git a/Result/Suggestions.php b/Result/Suggestions.php deleted file mode 100644 index 373aee0e..00000000 --- a/Result/Suggestions.php +++ /dev/null @@ -1,69 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ONGR\ElasticsearchBundle\Result; - -/** - * Suggestions results holder. - */ -class Suggestions implements \ArrayAccess -{ - /** - * @var array - */ - private $rawData; - - /** - * Constructor. - * - * @param array $rawData - */ - public function __construct($rawData) - { - $this->rawData = $rawData; - } - - /** - * {@inheritdoc} - */ - public function offsetExists($offset) - { - return isset($this->rawData[$offset]); - } - - /** - * {@inheritdoc} - */ - public function offsetGet($offset) - { - if (!$this->offsetExists($offset)) { - return null; - } - - return $this->rawData[$offset]; - } - - /** - * {@inheritdoc} - */ - public function offsetSet($offset, $value) - { - throw new \LogicException('Data of this iterator can not be changed after initialization.'); - } - - /** - * {@inheritdoc} - */ - public function offsetUnset($offset) - { - throw new \LogicException('Data of this iterator can not be changed after initialization.'); - } -} diff --git a/Tests/Functional/Result/SuggestionsIteratorTest.php b/Tests/Functional/Result/SuggestionsIteratorTest.php new file mode 100644 index 00000000..ab7529ca --- /dev/null +++ b/Tests/Functional/Result/SuggestionsIteratorTest.php @@ -0,0 +1,204 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\Functional\Result; + +use ONGR\ElasticsearchBundle\DSL\Query\MatchAllQuery; +use ONGR\ElasticsearchBundle\DSL\Suggester\AbstractSuggester; +use ONGR\ElasticsearchBundle\DSL\Suggester\Completion; +use ONGR\ElasticsearchBundle\DSL\Suggester\Context; +use ONGR\ElasticsearchBundle\DSL\Suggester\Phrase; +use ONGR\ElasticsearchBundle\DSL\Suggester\Term; +use ONGR\ElasticsearchBundle\ORM\Repository; +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\CompletionOption; +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\PhraseOption; +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\SimpleOption; +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\TermOption; +use ONGR\ElasticsearchBundle\Test\ElasticsearchTestCase; + +class SuggestionsIteratorTest extends ElasticsearchTestCase +{ + /** + * {@inheritdoc} + */ + protected function getDataArray() + { + return [ + 'default' => [ + 'product' => [ + [ + '_id' => 1, + 'title' => 'foo', + 'price' => 10, + 'description' => 'Lorem ipsum', + 'suggestions' => [ + 'input' => ['Lorem', 'ipsum', 'cons'], + 'output' => 'Lorem ipsum', + 'payload' => ['test' => true], + 'weight' => 1, + 'context' => [ + 'location' => [0, 0], + 'price' => 500, + ], + ], + 'completion_suggesting' => [ + 'input' => ['Lorem', 'ipsum'], + 'output' => 'Lorem ipsum', + 'weight' => 1, + ], + ], + [ + '_id' => 2, + 'title' => 'bar', + 'price' => 100, + 'description' => 'Lorem ipsum dolor sit amet... amte distributed disributed', + ], + [ + '_id' => 3, + 'title' => 'baz', + 'price' => 1000, + 'description' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit...', + ], + ], + ], + ]; + } + + /** + * Data provider for testSuggestionIterator(). + * + * @return array + */ + public function getSuggestIterationData() + { + $out = []; + + // Case #0, Phrase type with all parameters set. + $phrase = new Phrase('description', 'Lorm adip'); + $phrase->setAnalyzer('simple'); + $phrase->setSize(1); + $phrase->setRealWordErrorLikelihood(0.95); + $phrase->setMaxErrors(0.5); + $phrase->setGramSize(2); + $phrase->setHighlight( + [ + 'pre_tag' => '', + 'post_tag' => '', + ] + ); + $expectedOption = new PhraseOption('lorem adip', 0.0, 'lorem adip'); + + $out[] = ['suggesters' => [$phrase], 'expectedOptions' => [$expectedOption]]; + + // Case #1, Phrase type with almost nothing set. + $phrase = new Phrase('description', 'Lorm adip'); + $expectedOption = new SimpleOption('lorem adip', 0.0); + + $out[] = ['suggesters' => [$phrase], 'expectedOptions' => [$expectedOption]]; + + // Case #2, Term type with almost nothing set. + $term = new Term('description', 'ipsu'); + $expectedOption = new TermOption('ipsum', 0.0, 3); + + $out[] = ['suggesters' => [$term], 'expectedOptions' => [$expectedOption]]; + + // Case #3, Multiple suggesters. + $term = new Term('description', 'ipsu'); + $phrase = new Phrase('description', 'Lorm adip'); + $expectedOptions = [new TermOption('ipsum', 0.0, 3), new SimpleOption('lorem adip', 0.0)]; + + $out[] = ['suggesters' => [$term, $phrase], 'expectedOptions' => $expectedOptions]; + + // Case #4, Multiple options within multiple suggesters. + $term = new Term('description', 'distibutd'); + $phrase = new Phrase('description', 'Lorm adip'); + $expectedOptions = [ + new TermOption('disributed', 0.0, 1), + new TermOption('distributed', 0.0, 1), + new SimpleOption('lorem adip', 0.0), + ]; + + $out[] = ['suggesters' => [$term, $phrase], 'expectedOptions' => $expectedOptions]; + + // Case #5, completion option using context suggester, with payload. + $geoContext = new Context\GeoContext('location', ['lat' => 0, 'lon' => 0]); + $categoryContext = new Context\CategoryContext('price', '500'); + $context = new Context('suggestions', 'cons'); + $context->addContext($geoContext); + $context->addContext($categoryContext); + $expectedOption = new CompletionOption('Lorem ipsum', 0.0, ['test' => true]); + + $out[] = ['suggesters' => [$context], 'expectedOptions' => [$expectedOption]]; + + // Case #6, completion option using completion suggester, no payload. + $completion = new Completion('completion_suggesting', 'ipsum'); + $expectedOption = new SimpleOption('Lorem ipsum', 0.0, null); + + $out[] = ['suggesters' => [$completion], 'expectedOptions' => [$expectedOption]]; + + return $out; + } + + /** + * Iteration test. + * + * @param AbstractSuggester[] $suggesters + * @param SimpleOption[] $expectedOptions + * + * @dataProvider getSuggestIterationData() + */ + public function testSuggestionIteration($suggesters, $expectedOptions) + { + /** @var Repository $repo */ + $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $match = new MatchAllQuery(); + $search = $repo->createSearch()->addQuery($match); + + foreach ($suggesters as $suggester) { + $search->addSuggester($suggester); + } + + $iterator = $repo->execute($search, Repository::RESULTS_OBJECT); + + $this->assertInstanceOf('ONGR\ElasticsearchBundle\Result\DocumentIterator', $iterator); + + $suggestions = $iterator->getSuggestions(); + + $optionCount = 0; + foreach ($suggestions as $suggestionEntries) { + foreach ($suggestionEntries as $suggestionEntry) { + $this->assertInstanceOf('ONGR\ElasticsearchBundle\Result\Suggestion\SuggestionEntry', $suggestionEntry); + foreach ($suggestionEntry->getOptions() as $option) { + $option->setScore(0.0); + $this->assertEquals($expectedOptions[$optionCount++], $option); + } + } + } + $this->assertEquals(count($expectedOptions), $optionCount, 'Expecteded option count was not met.'); + } + + /** + * Check if suggestion properties are set as expected. + */ + public function testSuggestionProperties() + { + /** @var Repository $repo */ + $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $match = new MatchAllQuery(); + $search = $repo->createSearch()->addQuery($match); + $search->addSuggester(new Phrase('description', 'Lorm adip', 'test')); + + $suggestions = $repo->execute($search, Repository::RESULTS_OBJECT)->getSuggestions(); + $this->assertEquals('Lorm adip', $suggestions['test'][0]->getText()); + $this->assertEquals(9, $suggestions['test'][0]->getLength()); + $this->assertEquals(0, $suggestions['test'][0]->getOffset()); + } +} diff --git a/Tests/Unit/Result/DocumentIteratorTest.php b/Tests/Unit/Result/DocumentIteratorTest.php index 49b8dec3..ca7d4a0b 100644 --- a/Tests/Unit/Result/DocumentIteratorTest.php +++ b/Tests/Unit/Result/DocumentIteratorTest.php @@ -13,6 +13,8 @@ use ONGR\ElasticsearchBundle\Result\Aggregation\ValueAggregation; use ONGR\ElasticsearchBundle\Result\DocumentIterator; +use ONGR\ElasticsearchBundle\Result\Suggestion\OptionIterator; +use ONGR\ElasticsearchBundle\Result\Suggestion\SuggestionEntry; class DocumentIteratorTest extends \PHPUnit_Framework_TestCase { @@ -258,14 +260,16 @@ public function testGetSuggestions() ], 'suggest' => [ 'foo' => [ - 'text' => 'foobar', - 'offset' => 0, - 'length' => 6, - 'options' => [ - [ - 'text' => 'foobar', - 'freq' => 77, - 'score' => 0.8888889, + [ + 'text' => 'foobar', + 'offset' => 0, + 'length' => 6, + 'options' => [ + [ + 'text' => 'foobar', + 'freq' => 77, + 'score' => 0.8888889, + ], ], ], ], @@ -273,12 +277,21 @@ public function testGetSuggestions() ]; $iterator = new DocumentIterator($rawData, [], []); + $suggestions = $iterator->getSuggestions(); $this->assertInstanceOf( - 'ONGR\ElasticsearchBundle\Result\Suggestions', + 'ONGR\ElasticsearchBundle\Result\Suggestion\SuggestionIterator', $iterator->getSuggestions() ); - $this->assertEquals($rawData['suggest']['foo'], $iterator->getSuggestions()['foo']); + + $expectedSuggestion = new SuggestionEntry( + 'foobar', + 0, + 6, + new OptionIterator($rawData['suggest']['foo'][0]['options']) + ); + + $this->assertEquals($expectedSuggestion, $suggestions['foo'][0]); } /** diff --git a/Tests/Unit/Result/SuggestionsTest.php b/Tests/Unit/Result/SuggestionsTest.php deleted file mode 100644 index 89aed6f9..00000000 --- a/Tests/Unit/Result/SuggestionsTest.php +++ /dev/null @@ -1,82 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ONGR\ElasticsearchBundle\Tests\Unit\Result; - -use ONGR\ElasticsearchBundle\Result\Suggestions; - -class SuggestionsTest extends \PHPUnit_Framework_TestCase -{ - /** - * Returns sample data for tests. - * - * @return array - */ - protected function getTestData() - { - return [ - 'foo' => [ - 'text' => 'foobar', - 'offset' => 0, - 'length' => 6, - 'options' => [ - [ - 'text' => 'foobar', - 'freq' => 77, - 'score' => 0.8888889, - ], - ], - ], - 'bar' => [ - 'text' => 'barbaz', - 'offset' => 0, - 'length' => 6, - 'options' => [], - ], - ]; - } - - /** - * Test for \ArrayAccess interface implementation. - */ - public function testArrayAccess() - { - $iterator = new Suggestions($this->getTestData()); - - $this->assertEquals($this->getTestData()['foo'], $iterator->offsetGet('foo')); - $this->assertEquals($this->getTestData()['bar'], $iterator->offsetGet('bar')); - - // Should return NULL if key does not exist. - $this->assertNull($iterator->offsetGet('baz')); - } - - /** - * Test for offsetSet(). - * - * @expectedException \LogicException - */ - public function testOffsetSet() - { - $iterator = new Suggestions([]); - $iterator->offsetSet('foo', 'bar'); - } - - /** - * Test for offsetUnset(). - * - * @expectedException \LogicException - */ - public function testOffsetUnset() - { - $iterator = new Suggestions([]); - $iterator->offsetUnset('foo'); - } -} From b6e72cf21d782fc79d4b549c77b9bc24538e7605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zigmas=20Satkevi=C4=8Dius?= Date: Thu, 4 Dec 2014 15:16:01 +0200 Subject: [PATCH 06/10] Added elasticsearch suggest api implementation. --- ORM/Repository.php | 34 +++- Tests/Functional/ORM/RepositoryTest.php | 204 +++++++++++++++++++++++- 2 files changed, 228 insertions(+), 10 deletions(-) diff --git a/ORM/Repository.php b/ORM/Repository.php index 42ea2102..ae58fc9c 100644 --- a/ORM/Repository.php +++ b/ORM/Repository.php @@ -15,11 +15,14 @@ use ONGR\ElasticsearchBundle\DSL\Query\TermsQuery; use ONGR\ElasticsearchBundle\DSL\Search; use ONGR\ElasticsearchBundle\DSL\Sort\Sort; +use ONGR\ElasticsearchBundle\DSL\Suggester\AbstractSuggester; +use ONGR\ElasticsearchBundle\DSL\Suggester\Suggesters; use ONGR\ElasticsearchBundle\Result\Converter; use ONGR\ElasticsearchBundle\Result\DocumentIterator; use ONGR\ElasticsearchBundle\Result\DocumentScanIterator; use ONGR\ElasticsearchBundle\Result\RawResultIterator; use ONGR\ElasticsearchBundle\Result\RawResultScanIterator; +use ONGR\ElasticsearchBundle\Result\Suggestion\SuggestionIterator; /** * Repository class. @@ -145,13 +148,6 @@ public function findBy( return $this->execute($search, $resultType); } - /** - * Returns auto complete data. - */ - public function getAutoComplete() - { - } - /** * Returns search instance. * @@ -203,6 +199,30 @@ public function scan( return $this->parseResult($results, $resultsType, $scrollDuration); } + /** + * Get suggestions using suggest api. + * + * @param AbstractSuggester[]|AbstractSuggester $suggesters + * + * @return SuggestionIterator + */ + public function suggest($suggesters) + { + if (!is_array($suggesters)) { + $suggesters = [$suggesters]; + } + + $body = []; + /** @var AbstractSuggester $suggester */ + foreach ($suggesters as $suggester) { + $body = array_merge($suggester->toArray(), $body); + } + $results = $this->manager->getConnection()->getClient()->suggest(['body' => $body]); + unset($results['_shards']); + + return new SuggestionIterator($results); + } + /** * Removes a single document data by ID. * diff --git a/Tests/Functional/ORM/RepositoryTest.php b/Tests/Functional/ORM/RepositoryTest.php index b4f39dba..db77be07 100644 --- a/Tests/Functional/ORM/RepositoryTest.php +++ b/Tests/Functional/ORM/RepositoryTest.php @@ -13,7 +13,15 @@ use ONGR\ElasticsearchBundle\Document\DocumentInterface; use ONGR\ElasticsearchBundle\DSL\Filter\PrefixFilter; +use ONGR\ElasticsearchBundle\DSL\Suggester\Completion; +use ONGR\ElasticsearchBundle\DSL\Suggester\Context; +use ONGR\ElasticsearchBundle\DSL\Suggester\Phrase; +use ONGR\ElasticsearchBundle\DSL\Suggester\Term; use ONGR\ElasticsearchBundle\ORM\Repository; +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\CompletionOption; +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\SimpleOption; +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\TermOption; +use ONGR\ElasticsearchBundle\Result\Suggestion\SuggestionIterator; use ONGR\ElasticsearchBundle\Test\ElasticsearchTestCase; use ONGR\TestingBundle\Document\Product; @@ -31,19 +39,34 @@ protected function getDataArray() '_id' => 1, 'title' => 'foo', 'price' => 10, - 'description' => 'goo', + 'description' => 'goo Lorem', + 'suggestions' => [ + 'input' => ['Lorem', 'ipsum', 'cons'], + 'output' => 'Lorem ipsum', + 'payload' => ['test' => true], + 'weight' => 1, + 'context' => [ + 'location' => [0, 0], + 'price' => 500, + ], + ], + 'completion_suggesting' => [ + 'input' => ['Lorem', 'ipsum'], + 'output' => 'Lorem ipsum', + 'weight' => 1, + ], ], [ '_id' => 2, 'title' => 'bar', 'price' => 1000, - 'description' => 'foo bar', + 'description' => 'foo bar Lorem adips distributed disributed', ], [ '_id' => 3, 'title' => 'gar', 'price' => 100, - 'description' => 'foo bar', + 'description' => 'foo bar Loremo', ], ], ], @@ -352,4 +375,179 @@ public function testDocumentUpdate() 'Document should be updated.' ); } + + /** + * Data provider for testSuggest(). + * + * @return array + */ + public function getSuggestData() + { + $out = []; + + // Case #0: simple single term suggester. + $expectedResults = [ + 'description-term' => [ + [ + 'text' => 'distibutd', + 'offset' => '0', + 'length' => '9', + 'options' => [ + new TermOption('disributed', 0.0, 1), + new TermOption('distributed', 0.0, 1), + ], + ], + ] + ]; + + $suggesters = [new Term('description', 'distibutd')]; + $out[] = ['suggesters' => $suggesters, 'expectedResults' => $expectedResults]; + + // Case #1: simple single phrase suggester. + $expectedResults = [ + 'description-phrase' => [ + [ + 'text' => 'Lorm adip', + 'offset' => '0', + 'length' => '9', + 'options' => [new SimpleOption('lorem adip', 0.0)], + ], + ] + ]; + + $suggesters = [new Phrase('description', 'Lorm adip')]; + $out[] = ['suggesters' => $suggesters, 'expectedResults' => $expectedResults]; + + // Case #2: simple context suggester. + $geoContext = new Context\GeoContext('location', ['lat' => 0, 'lon' => 0]); + $categoryContext = new Context\CategoryContext('price', '500'); + $context = new Context('suggestions', 'cons'); + $context->addContext($geoContext); + $context->addContext($categoryContext); + + $expectedResults = [ + 'suggestions-completion' => [ + [ + 'text' => 'cons', + 'offset' => '0', + 'length' => '4', + 'options' => [new CompletionOption('Lorem ipsum', 0.0, ['test' => true])], + ], + ] + ]; + + $out[] = ['suggesters' => $context, 'expectedResults' => $expectedResults]; + + // Case #3: simple completion suggester. + $completion = new Completion('completion_suggesting', 'ipsum'); + $expectedResults = [ + 'completion_suggesting-completion' => [ + [ + 'text' => 'ipsum', + 'offset' => '0', + 'length' => '5', + 'options' => [new SimpleOption('Lorem ipsum', 0.0, null)], + ], + ] + ]; + + $out[] = ['suggesters' => $completion, 'expectedResults' => $expectedResults]; + + // Case #4: all together. + $geoContext = new Context\GeoContext('location', ['lat' => 0, 'lon' => 0]); + $categoryContext = new Context\CategoryContext('price', '500'); + $context = new Context('suggestions', 'cons'); + $context->addContext($geoContext); + $context->addContext($categoryContext); + $suggesters = [ + new Term('description', 'distibutd'), + new Phrase('description', 'Lorm adip'), + $context, + new Completion('completion_suggesting', 'ipsum'), + ]; + $expectedResults = [ + 'description-term' => [ + [ + 'text' => 'distibutd', + 'offset' => '0', + 'length' => '9', + 'options' => [ + new TermOption('disributed', 0.0, 1), + new TermOption('distributed', 0.0, 1), + ], + ], + ], + 'description-phrase' => [ + [ + 'text' => 'Lorm adip', + 'offset' => '0', + 'length' => '9', + 'options' => [new SimpleOption('lorem adip', 0.0)], + ], + ], + 'suggestions-completion' => [ + [ + 'text' => 'cons', + 'offset' => '0', + 'length' => '4', + 'options' => [new CompletionOption('Lorem ipsum', 0.0, ['test' => true])], + ], + ], + 'completion_suggesting-completion' => [ + [ + 'text' => 'ipsum', + 'offset' => '0', + 'length' => '5', + 'options' => [new SimpleOption('Lorem ipsum', 0.0, null)], + ], + ] + ]; + $out[] = ['suggesters' => $suggesters, 'expectedResults' => $expectedResults]; + + return $out; + } + + /** + * Check if suggest api works as expected. + * + * @param array $suggesters + * @param array $expectedResults + * + * @dataProvider getSuggestData() + */ + public function testSuggest($suggesters, $expectedResults) + { + $manager = $this->getManager(); + $repository = $manager->getRepository('ONGRTestingBundle:Product'); + + $results = $repository->suggest($suggesters); + $this->assertScore($results); + + $this->assertSameSize($expectedResults, $results); + foreach ($expectedResults as $name => $expectedSuggestion) { + foreach ($expectedResults[$name] as $key => $entry) { + $this->assertEquals($entry['text'], $results[$name][$key]->getText()); + $this->assertEquals($entry['offset'], $results[$name][$key]->getOffset()); + $this->assertEquals($entry['length'], $results[$name][$key]->getLength()); + $this->assertEquals($entry['options'], iterator_to_array($results[$name][$key]->getOptions())); + } + } + } + + /** + * Assert suggestion score is set. + * + * @param SuggestionIterator $suggestions + */ + private function assertScore(SuggestionIterator $suggestions) + { + foreach ($suggestions as $suggestion) { + foreach ($suggestion as $suggestionEntry) { + foreach ($suggestionEntry->getOptions() as $option) { + $this->assertTrue($option->getScore() > 0.0); + $option->setScore(0.0); + } + } + } + } } From d1b1611d72b747f1b4cc99ad3328ffe3a99bffa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zigmas=20Satkevi=C4=8Dius?= Date: Thu, 4 Dec 2014 17:37:03 +0200 Subject: [PATCH 07/10] Added missing functional tests for suggesters. --- .../CompletionSuggesterInterface.php | 13 +++-- .../Option/CompletionOptionTest.php | 31 +++++++++++ .../Suggestion/Option/PhraseOptionTest.php | 29 ++++++++++ .../Suggestion/Option/TermOptionTest.php | 30 +++++++++++ .../Result/Suggestion/OptionIteratorTest.php | 53 +++++++++++++++++++ .../Suggestion/SuggestionIteratorTest.php | 53 +++++++++++++++++++ 6 files changed, 204 insertions(+), 5 deletions(-) create mode 100644 Tests/Unit/Result/Suggestion/Option/CompletionOptionTest.php create mode 100644 Tests/Unit/Result/Suggestion/Option/PhraseOptionTest.php create mode 100644 Tests/Unit/Result/Suggestion/Option/TermOptionTest.php create mode 100644 Tests/Unit/Result/Suggestion/OptionIteratorTest.php create mode 100644 Tests/Unit/Result/Suggestion/SuggestionIteratorTest.php diff --git a/Document/Suggester/CompletionSuggesterInterface.php b/Document/Suggester/CompletionSuggesterInterface.php index b9ae4315..79568849 100644 --- a/Document/Suggester/CompletionSuggesterInterface.php +++ b/Document/Suggester/CompletionSuggesterInterface.php @@ -1,9 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace ONGR\ElasticsearchBundle\Document\Suggester; diff --git a/Tests/Unit/Result/Suggestion/Option/CompletionOptionTest.php b/Tests/Unit/Result/Suggestion/Option/CompletionOptionTest.php new file mode 100644 index 00000000..c6c603d3 --- /dev/null +++ b/Tests/Unit/Result/Suggestion/Option/CompletionOptionTest.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\Unit\Result\Suggestion; + +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\CompletionOption; + +/** + * Unit tests for completion option. + */ +class CompletionOptionTest extends \PHPUnit_Framework_TestCase +{ + /** + * Check if getters works as expected. + */ + public function testGetters() + { + $completion = new CompletionOption('test', 1.0, ['my' => 'test']); + $this->assertEquals('test', $completion->getText()); + $this->assertEquals(1.0, $completion->getScore()); + $this->assertEquals(['my' => 'test'], $completion->getPayload()); + } +} diff --git a/Tests/Unit/Result/Suggestion/Option/PhraseOptionTest.php b/Tests/Unit/Result/Suggestion/Option/PhraseOptionTest.php new file mode 100644 index 00000000..fa8c544e --- /dev/null +++ b/Tests/Unit/Result/Suggestion/Option/PhraseOptionTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\Unit\Result\Suggestion; + +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\PhraseOption; + +/** + * Unit tests for completion option. + */ +class PhraseOptionTest extends \PHPUnit_Framework_TestCase +{ + /** + * Check if getters works as expected. + */ + public function testGetters() + { + $option = new PhraseOption('test', 1.0, 'highlighted'); + $this->assertEquals('highlighted', $option->getHighlighted()); + } +} diff --git a/Tests/Unit/Result/Suggestion/Option/TermOptionTest.php b/Tests/Unit/Result/Suggestion/Option/TermOptionTest.php new file mode 100644 index 00000000..89bd1f4c --- /dev/null +++ b/Tests/Unit/Result/Suggestion/Option/TermOptionTest.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\Unit\Result\Suggestion; + +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\CompletionOption; +use ONGR\ElasticsearchBundle\Result\Suggestion\Option\TermOption; + +/** + * Unit tests for completion option. + */ +class TermOptionTest extends \PHPUnit_Framework_TestCase +{ + /** + * Check if getters works as expected. + */ + public function testGetters() + { + $option = new TermOption('test', 1.0, 2.0); + $this->assertEquals(2.0, $option->getFreq()); + } +} diff --git a/Tests/Unit/Result/Suggestion/OptionIteratorTest.php b/Tests/Unit/Result/Suggestion/OptionIteratorTest.php new file mode 100644 index 00000000..c2ca71a5 --- /dev/null +++ b/Tests/Unit/Result/Suggestion/OptionIteratorTest.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\Unit\Result\Suggestion; + +use ONGR\ElasticsearchBundle\Result\Suggestion\OptionIterator; + +/** + * Unit tests for options iterator. + */ +class OptionIteratorTest extends \PHPUnit_Framework_TestCase +{ + /** + * Check if offset get returns null if it's not set. + */ + public function testOffsetGet() + { + $iterator = new OptionIterator([]); + $this->assertNull($iterator['test']); + } + + /** + * Check if offset set throws an exception. + * + * @expectedException \LogicException + * @expectedExceptionMessage Data of this iterator can not be changed after initialization. + */ + public function testOffsetUnset() + { + $highlight = new OptionIterator([]); + $highlight->offsetUnset('test'); + } + + /** + * Check if offset set throws an exception. + * + * @expectedException \LogicException + * @expectedExceptionMessage Data of this iterator can not be changed after initialization. + */ + public function testOffsetSet() + { + $highlight = new OptionIterator([]); + $highlight->offsetSet('test', 'test'); + } +} diff --git a/Tests/Unit/Result/Suggestion/SuggestionIteratorTest.php b/Tests/Unit/Result/Suggestion/SuggestionIteratorTest.php new file mode 100644 index 00000000..b3d3cb8e --- /dev/null +++ b/Tests/Unit/Result/Suggestion/SuggestionIteratorTest.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\Unit\Result\Suggestion; + +use ONGR\ElasticsearchBundle\Result\Suggestion\SuggestionIterator; + +/** + * Unit tests for suggestion iterator. + */ +class SuggestionIteratorTest extends \PHPUnit_Framework_TestCase +{ + /** + * Check if offset get returns null if it's not set. + */ + public function testOffsetGet() + { + $iterator = new SuggestionIterator([]); + $this->assertNull($iterator['test']); + } + + /** + * Check if offset set throws an exception. + * + * @expectedException \LogicException + * @expectedExceptionMessage Data of this iterator can not be changed after initialization. + */ + public function testOffsetUnset() + { + $highlight = new SuggestionIterator([]); + $highlight->offsetUnset('test'); + } + + /** + * Check if offset set throws an exception. + * + * @expectedException \LogicException + * @expectedExceptionMessage Data of this iterator can not be changed after initialization. + */ + public function testOffsetSet() + { + $highlight = new SuggestionIterator([]); + $highlight->offsetSet('test', 'test'); + } +} From 88fac1ef5986f46218459c54f4159c8b9561d585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zigmas=20Satkevi=C4=8Dius?= Date: Fri, 5 Dec 2014 13:48:25 +0200 Subject: [PATCH 08/10] Added documentation for suggesters. --- .../doc/suggesters/indexed_suggesters.md | 221 ++++++++++++++++++ Resources/doc/suggesters/types.md | 57 +++++ Resources/doc/suggesters/usage.md | 77 ++++++ Resources/doc/usage.md | 3 + 4 files changed, 358 insertions(+) create mode 100644 Resources/doc/suggesters/indexed_suggesters.md create mode 100644 Resources/doc/suggesters/types.md create mode 100644 Resources/doc/suggesters/usage.md diff --git a/Resources/doc/suggesters/indexed_suggesters.md b/Resources/doc/suggesters/indexed_suggesters.md new file mode 100644 index 00000000..46279726 --- /dev/null +++ b/Resources/doc/suggesters/indexed_suggesters.md @@ -0,0 +1,221 @@ +# Indexed suggesters + +Indexed suggesters require special mapping and documented data to work, this includes two suggesters: completion and context. + +## Mapping + +### Completion +Starting with a more simple example, completion suggester. +Completion suggester is a simple field which you would just define in a document or an object using a special annotation for suggesters. +Available mapping parameters can be found [here][completion_mapping_parameters]. +For example: + +```php + Note context parameter name must be `context` in order for this mapping to work! + +```php + Note, that type doesn't matter here. + +```php +price = '500'; +$categoryContext->location = ['lat' => 50, 'lon' => 50]; +$suggester = new PriceLocationSuggesting(); +$suggester->setInput(['test']); +$suggester->setOutput('success'); +$suggester->setContext($categoryContext); +$suggester->setPayload(['test']); +$suggester->setWeight(50); + +$completionSuggester = new CompletionSuggesting(); +$completionSuggester->setInput(['a', 'b', 'c']); +$completionSuggester->setOutput('completion success'); +$completionSuggester->setWeight(30); + +$product = new Product(); +$product->contextSuggesting = $suggester; +$product->completionSuggesting = $completionSuggester; + +$manager->persist($product); +$manager->commit(); +``` + +To receive your data, search for it, just like you would with any other object. + +## Suggesting + +Once you have data and mapping, you can start looking for suggestions, it's just like with any other suggesters, an example: +```php + 0, 'lon' => 0]); +$categoryContext = new Context\CategoryContext('price', '500'); +$context = new Context('suggestions', 'cons'); +$context->addContext($geoContext); +$context->addContext($categoryContext); +$suggesters = [ + $context, + new Completion('completion_suggesting', 'ipsum'), +]; +$results = $repository->suggest($suggesters); +``` + +[completion_mapping_parameters]:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-completion.html#completion-suggester-mapping +[geo_mapping]:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/suggester-context.html#_geo_location_mapping +[category_mapping]:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/suggester-context.html#_category_mapping diff --git a/Resources/doc/suggesters/types.md b/Resources/doc/suggesters/types.md new file mode 100644 index 00000000..9edb88d6 --- /dev/null +++ b/Resources/doc/suggesters/types.md @@ -0,0 +1,57 @@ +# Sugggester types + +There are four basic types of suggesters objects to be used in a query and they have different parameters: + +* [Term][term_elastic], suggests terms based on edit distance. + +| Parameter | Description | Setter | +|-------------|-----------------------------------------------------------------|-----------------------| +| text | Text to search suggestions for. | constructor, setText | +| field | Field to look for suggesting on. This field is mandatory. | constructor, setField | +| analyzer | Analyzer to analyse to suggest text with. | setAnalyzer | +| size | Maximum corrections to be returned per suggest text token. | setSize | +| sort | Defines how suggestions should be sorted per suggest text term. | setSort | +| suggestMode | Controls what suggestions are included. | setSuggestMode | + +* [Phrase][phrase_elastic], basically a more complex term suggester. + +| Parameter | Description | Setter | +|-------------------------|---------------------------------------------------------------------------------------------------------------|----------------------------| +| text | Text to search suggestions for. | constructor, setText | +| field | Field to look for suggesting on. This field is mandatory. | constructor, setField | +| analyzer | Analyzer to analyse to suggest text with. | setAnalyzer | +| gramSize | Sets max size of the n-grams (shingles) in the field. | setGramSize | +| realWordErrorLikelihood | The likelihood of a term being a misspelled even if the term exists in the dictionary. | setRealWordErrorLikelihood | +| confidence | Defines a factor applied to the input phrases score. | setConfidence | +| maxErrors | The maximum percentage of the terms that at most considered to be misspellings in order to form a correction. | setMaxErrors | +| highlight | Setup highlighting. If provided must contain array with keys `pre_tag` and `post_tag`. | setHighlight | +| size | Maximum corrections to be returned per suggest text token. | setSize | + +* [Completion][completion_elastic], implements basic auto-complete functionality. Requires [special mapping](indexed_suggesters.md). + +| Parameter | Description | Setter | +|----------------|---------------------------------------------------------------------------|-----------------------| +| text | Text to search suggestions for. | constructor, setText | +| field | Field to look for suggesting on. This field is mandatory. | constructor, setField | +| useFuzzy | Whether or not to use fuzzy query. | useFuzzy | +| fuzziness | The fuzziness factor. | setFuzziness | +| transpositions | Sets if transpositions should be counted as one or two changes. | setTranspositions | +| minLength | Minimum length of the input before fuzzy suggestions are returned. | setMinLength | +| prefixLength | Minimum length of the input, which is not checked for fuzzy alternatives. | setPrefixLength | +| unicodeAware | Are measurements in unicde format. | setUnicodeAware | + +* [Context][context_elastic], implements auto-complete functionality based on context you provide. Requires [special mapping](indexed_suggesters.md). + +| Parameter | Description | Setter | +|-----------|------------------------------------------------------------|------------------------| +| text | Text to search suggestions for. | constructor, setText | +| field | Field to look for suggesting on. This field is mandatory. | constructor, setField | +| context | Context to look for. | addContext, setContext | +| size | Maximum corrections to be returned per suggest text token. | setSize | + +Every context is either geo context or category context, they both have value and name parameters, but geo context has an additional precision parameter. + +[phrase_elastic]:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html +[term_elastic]:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-term.html +[completion_elastic]:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-term.html +[context_elastic]:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/suggester-context.html diff --git a/Resources/doc/suggesters/usage.md b/Resources/doc/suggesters/usage.md new file mode 100644 index 00000000..90a1590d --- /dev/null +++ b/Resources/doc/suggesters/usage.md @@ -0,0 +1,77 @@ +# Suggesters + +[Suggesters][suggesters_link] are used to find a similar looking term using the provided text. + +You can use suggesters in any query as you would normally, or [suggester api][suggesters_link]. + +There are basically four types of suggesters: terms, phrase, completion and context, to find out available parameters for these suggesters check out [this](types.md) section. + +>Completion and context suggesters need indexed data in order to work. To find out how to setup indexing and mapping, +check [indexed suggesters][indexed_suggesters] section. + +## Using suggesters in any query +Using suggesters with simple queries, i.e. `search` api is quite simple. +You can add suggesters just how you would add aggregations, filters, etc... +```php +getRepository('AcmeTestBundle:Product'); +$search = $repository->createSearch(); +$search->addQuery(new MatchAllQuery()); +$termSuggester = new Term('description', 'distibutd'); +$search->addSuggester($termSuggester); +$results = $repository->execute($search); +``` +That's it, getting the results is quite simple. +```php +getSuggestions(); +``` +To see how to use the suggestions iterator check out [this](#using-results) section. + +## Using suggesters with suggest api +```php +getRepository('AcmeTestBundle:Product'); +$termSuggester = new Term('description', 'distibutd'); +$phraseSuggester = new Phrase('description', 'distibuted'), +// You can pass an array of suggesters or a single suggester as well. +$suggestionsIterator = $repository->suggest([$termSuggester, $phraseSuggester]); +$suggestionsIterator2 = $repository->suggest($termSuggester); +``` + +## Using results +Once you have the suggestions iterator, you can get all the information needed from it. +Multiple suggestions have one or more suggestion entries based on your analyzer, and each suggestion entry may or may not have multiple options available. +To use this data, you can loop through the iterator, or just access the data you need using indexes. +```php +getText(); + $suggestionEntryOffset = $suggestionEntry->getOffset(); + $suggestionEntryLength = $suggestionEntry->getLength(); + foreach ($suggestionEntry->getOptions() as $option) { + $optionText = $option->getText(); + $optionScore = $option->getScore(); + } + } +} +$options = $suggestions['description-term'][0]->getOptions(); +``` + +>Note that based on ESB response, an option may be an instance of SimpleOption, CompletionOption, PhraseOption or TermOption. + +SimpleOption contains text and score data. +Each other type of option extends SimpleOption and stores additional data: + +| Option instance type | Additional parameter | Getter | +|----------------------|--------------------------------------------------|------------------| +| PhraseOption | `highlighted`, highlighted text | getHighlighted() | +| TermOption | `frequency`, suggested text document frequency | getFreq() | +| CompletionOption | `payload`, returns payload of a suggest document | getPayload() | + +> Note, just because you're using, for example, completion suggester, doesn't mean you'll get completion options, if payload was not set, you'll get a simple option instead. +Same goes for other options. + +[suggesters_link]:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters.html +[indexed_suggesters]:indexed_suggesters.md diff --git a/Resources/doc/usage.md b/Resources/doc/usage.md index 33010e6c..01996da1 100644 --- a/Resources/doc/usage.md +++ b/Resources/doc/usage.md @@ -78,3 +78,6 @@ $documents = $repository->findBy(['title' => 'Acme']); ```` To perform a more complex queries there is a Search DSL API. Read more about it in [Search DSL](search.md) chapter. + +### Autocomplete +To use autocomplete follow [suggesters](suggesters/usage.md) section. From 59fa3b0738607b0e58d4622c674daf138dedf43c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zigmas=20Satkevi=C4=8Dius?= Date: Fri, 5 Dec 2014 14:56:17 +0200 Subject: [PATCH 09/10] Moved required test data from testing bundle. --- .../doc/suggesters/indexed_suggesters.md | 4 +- Tests/Functional/Client/ConnectionTest.php | 2 +- .../Command/IndexImportCommandTest.php | 2 +- .../Command/TypeUpdateCommandTest.php | 2 +- .../DSL/Aggregation/FilterAggregationTest.php | 2 +- .../DSL/Aggregation/GlobalAggregationTest.php | 2 +- .../DSL/Aggregation/NestedAggregationTest.php | 2 +- .../DSL/Aggregation/RangeAggregationTest.php | 2 +- .../DSL/Aggregation/StatsAggregationTest.php | 2 +- .../DSL/Aggregation/TermsAggregationTest.php | 4 +- .../Aggregation/TopHitsAggregationTest.php | 6 +- ...oolTestWithFuzzyQueryAndSortFilterTest.php | 2 +- ...olTestWithMatchQueryAndLimitFilterTest.php | 2 +- .../Complex/PostFilterAndAggregationTest.php | 2 +- Tests/Functional/DSL/Filter/AndFilterTest.php | 2 +- .../Functional/DSL/Filter/BoolFilterTest.php | 2 +- .../DSL/Filter/ExistsFilterTest.php | 2 +- Tests/Functional/DSL/Filter/IdsFilterTest.php | 2 +- .../DSL/Filter/IndicesFilterTest.php | 2 +- .../Functional/DSL/Filter/LimitFilterTest.php | 2 +- .../DSL/Filter/MatchAllFilterTest.php | 2 +- .../DSL/Filter/MissingFilterTest.php | 2 +- Tests/Functional/DSL/Filter/NotFilterTest.php | 2 +- Tests/Functional/DSL/Filter/OrFilterTest.php | 2 +- .../DSL/Filter/PrefixFilterTest.php | 2 +- .../Functional/DSL/Filter/QueryFilterTest.php | 2 +- .../Functional/DSL/Filter/RangeFilterTest.php | 2 +- .../DSL/Filter/RegexpFilterTest.php | 2 +- .../DSL/Filter/ScriptFilterTest.php | 2 +- .../Functional/DSL/Filter/TermFilterTest.php | 2 +- .../Functional/DSL/Filter/TermsFilterTest.php | 2 +- .../Functional/DSL/Filter/TypeFilterTest.php | 2 +- Tests/Functional/DSL/Highlight/FieldTest.php | 6 +- .../DSL/Highlight/HighlightTest.php | 4 +- .../Functional/DSL/Query/CommonTermsTest.php | 2 +- .../DSL/Query/ConstantScoreTest.php | 2 +- .../DSL/Query/FunctionScoreQueryTest.php | 2 +- .../DSL/Query/FuzzyLikeThisFieldTest.php | 2 +- Tests/Functional/DSL/Query/FuzzyTest.php | 2 +- Tests/Functional/DSL/Query/IdsTest.php | 2 +- .../Functional/DSL/Query/IndicesQueryTest.php | 2 +- Tests/Functional/DSL/Query/MatchAllTest.php | 2 +- Tests/Functional/DSL/Query/MatchTest.php | 2 +- .../Functional/DSL/Query/MoreLikeThisTest.php | 2 +- Tests/Functional/DSL/Query/MultiMatchTest.php | 2 +- .../Functional/DSL/Query/NestedQueryTest.php | 2 +- .../Functional/DSL/Query/QueryStringTest.php | 2 +- Tests/Functional/DSL/Query/RangeTest.php | 2 +- Tests/Functional/DSL/Query/RegexpTest.php | 2 +- .../DSL/Query/SimpleQueryStringTest.php | 2 +- Tests/Functional/DSL/Query/SpanTermTest.php | 2 +- Tests/Functional/DSL/Query/TermTest.php | 4 +- Tests/Functional/DSL/Query/TermsTest.php | 2 +- Tests/Functional/DSL/Query/WildcardTest.php | 2 +- Tests/Functional/DSL/SearchTest.php | 2 +- Tests/Functional/DSL/Sort/GeoSortTest.php | 2 +- Tests/Functional/DSL/Sort/ScriptSortTest.php | 2 +- Tests/Functional/DSL/Sort/SortTest.php | 2 +- .../DSL/Suggester/CompletionTest.php | 2 +- .../Functional/DSL/Suggester/ContextTest.php | 4 +- Tests/Functional/DSL/Suggester/PhraseTest.php | 2 +- Tests/Functional/DSL/Suggester/TermTest.php | 2 +- .../Compiler/MappingPassTest.php | 4 +- .../ElasticsearchExtensionTest.php | 2 +- Tests/Functional/ORM/ManagerTest.php | 26 ++--- Tests/Functional/ORM/RepositoryTest.php | 26 ++--- .../Result/AggregationIteratorFindTest.php | 2 +- .../Result/DocumentIteratorTest.php | 8 +- .../Result/DocumentScanIteratorTest.php | 2 +- .../Result/SuggestionsIteratorTest.php | 4 +- .../Service/ESDataCollectorTest.php | 6 +- .../DependencyInjection/ConfigurationTest.php | 12 +- Tests/Unit/Mapping/MetadataCollectorTest.php | 22 ++-- Tests/Unit/ORM/RepositoryTest.php | 6 +- Tests/Unit/Result/DocumentIteratorTest.php | 8 +- Tests/Unit/Service/JsonFormatterTest.php | 2 +- Tests/app/AppKernel.php | 2 +- Tests/app/config/config_test.yml | 2 +- .../Acme/TestBundle/AcmeTestBundle.php | 22 ++++ .../Acme/TestBundle/Document/Category.php | 25 +++++ .../Acme/TestBundle/Document/CdnObject.php | 29 +++++ .../Acme/TestBundle/Document/Comment.php | 64 +++++++++++ .../Document/CompletionSuggesting.php | 26 +++++ .../Acme/TestBundle/Document/Content.php | 33 ++++++ .../Acme/TestBundle/Document/ImagesNested.php | 51 +++++++++ .../Document/PriceLocationContext.php | 36 ++++++ .../Document/PriceLocationSuggesting.php | 33 ++++++ .../Acme/TestBundle/Document/Product.php | 103 ++++++++++++++++++ .../Acme/TestBundle/Document/UrlObject.php | 59 ++++++++++ .../TestBundle/Document/documentSample.txt | 22 ++++ .../JsonFormatter/formatted_0.json | 0 .../JsonFormatter/formatted_1.json | 0 composer.json | 3 +- 93 files changed, 643 insertions(+), 139 deletions(-) create mode 100644 Tests/app/fixture/Acme/TestBundle/AcmeTestBundle.php create mode 100644 Tests/app/fixture/Acme/TestBundle/Document/Category.php create mode 100644 Tests/app/fixture/Acme/TestBundle/Document/CdnObject.php create mode 100644 Tests/app/fixture/Acme/TestBundle/Document/Comment.php create mode 100644 Tests/app/fixture/Acme/TestBundle/Document/CompletionSuggesting.php create mode 100644 Tests/app/fixture/Acme/TestBundle/Document/Content.php create mode 100644 Tests/app/fixture/Acme/TestBundle/Document/ImagesNested.php create mode 100644 Tests/app/fixture/Acme/TestBundle/Document/PriceLocationContext.php create mode 100644 Tests/app/fixture/Acme/TestBundle/Document/PriceLocationSuggesting.php create mode 100644 Tests/app/fixture/Acme/TestBundle/Document/Product.php create mode 100644 Tests/app/fixture/Acme/TestBundle/Document/UrlObject.php create mode 100644 Tests/app/fixture/Acme/TestBundle/Document/documentSample.txt rename Tests/app/{fixtures => fixture}/JsonFormatter/formatted_0.json (100%) rename Tests/app/{fixtures => fixture}/JsonFormatter/formatted_1.json (100%) diff --git a/Resources/doc/suggesters/indexed_suggesters.md b/Resources/doc/suggesters/indexed_suggesters.md index 46279726..bb62df98 100644 --- a/Resources/doc/suggesters/indexed_suggesters.md +++ b/Resources/doc/suggesters/indexed_suggesters.md @@ -125,7 +125,7 @@ class PriceLocationSuggesting implements ContextSuggesterInterface /** * @var object * - * @ES\Property(type="object", objectName="ONGRTestingBundle:PriceLocationContext", name="context") + * @ES\Property(type="object", objectName="AcmeDemoBundle:PriceLocationContext", name="context") */ private $context; } @@ -138,7 +138,7 @@ And you also need to define your context object, for example. ```php getManager(); $connection = $manager->getConnection(); - $repository = $manager->getRepository('ONGRTestingBundle:Product'); + $repository = $manager->getRepository('AcmeTestBundle:Product'); // CREATE. $connection->bulk('create', 'product', ['_id' => 'baz', 'title' => 'Awesomo']); diff --git a/Tests/Functional/Command/IndexImportCommandTest.php b/Tests/Functional/Command/IndexImportCommandTest.php index 04449eda..3fe93b11 100644 --- a/Tests/Functional/Command/IndexImportCommandTest.php +++ b/Tests/Functional/Command/IndexImportCommandTest.php @@ -39,7 +39,7 @@ public function testIndexImport() ); $manager = $this->getManager('default', false); - $repo = $manager->getRepository('ONGRTestingBundle:Product'); + $repo = $manager->getRepository('AcmeTestBundle:Product'); $search = $repo ->createSearch() ->addQuery(new MatchAllQuery()); diff --git a/Tests/Functional/Command/TypeUpdateCommandTest.php b/Tests/Functional/Command/TypeUpdateCommandTest.php index 6c10eb34..c557ab44 100644 --- a/Tests/Functional/Command/TypeUpdateCommandTest.php +++ b/Tests/Functional/Command/TypeUpdateCommandTest.php @@ -60,7 +60,7 @@ public function setUp() $this->manager = $this->container->get('es.manager'); // Set up custom document to test mapping with. - $this->documentDir = $this->container->get('kernel')->locateResource('@ONGRTestingBundle/Document/'); + $this->documentDir = $this->container->get('kernel')->locateResource('@AcmeTestBundle/Document/'); $this->file = $this->documentDir . 'Article.php'; // Create index for testing. diff --git a/Tests/Functional/DSL/Aggregation/FilterAggregationTest.php b/Tests/Functional/DSL/Aggregation/FilterAggregationTest.php index 77d5dc5c..20cfb49a 100644 --- a/Tests/Functional/DSL/Aggregation/FilterAggregationTest.php +++ b/Tests/Functional/DSL/Aggregation/FilterAggregationTest.php @@ -107,7 +107,7 @@ public function getFilterAggregationData() public function testFilterAggregation($aggregation, $expectedResults) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repo->createSearch()->addAggregation($aggregation); diff --git a/Tests/Functional/DSL/Aggregation/GlobalAggregationTest.php b/Tests/Functional/DSL/Aggregation/GlobalAggregationTest.php index 4bac5284..2081c2f4 100644 --- a/Tests/Functional/DSL/Aggregation/GlobalAggregationTest.php +++ b/Tests/Functional/DSL/Aggregation/GlobalAggregationTest.php @@ -115,7 +115,7 @@ public function getGlobalAggregationData() public function testGlobalAggregation($aggregation, $query, $expectedResults, $hitsCount) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repo->createSearch()->addAggregation($aggregation); if ($query) { diff --git a/Tests/Functional/DSL/Aggregation/NestedAggregationTest.php b/Tests/Functional/DSL/Aggregation/NestedAggregationTest.php index a50ddaa9..f664e56e 100644 --- a/Tests/Functional/DSL/Aggregation/NestedAggregationTest.php +++ b/Tests/Functional/DSL/Aggregation/NestedAggregationTest.php @@ -161,7 +161,7 @@ public function getNestedAggregationData() public function testNestedAggregation($aggregation, $expectedResult, $mapping) { /** @var Repository $repo */ - $repo = $this->getManager('default', true, $mapping)->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager('default', true, $mapping)->getRepository('AcmeTestBundle:Product'); $nestedAggregation = new NestedAggregation('test_nested_agg'); $nestedAggregation->setPath('sub_products'); diff --git a/Tests/Functional/DSL/Aggregation/RangeAggregationTest.php b/Tests/Functional/DSL/Aggregation/RangeAggregationTest.php index 81f4f756..f399c9a9 100644 --- a/Tests/Functional/DSL/Aggregation/RangeAggregationTest.php +++ b/Tests/Functional/DSL/Aggregation/RangeAggregationTest.php @@ -147,7 +147,7 @@ public function getRangeAggregationData() public function testRangeAggregation($aggregation, $expectedResult) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $rangeAggregation = new RangeAggregation($aggregation['name']); $rangeAggregation->setField($aggregation['field']); diff --git a/Tests/Functional/DSL/Aggregation/StatsAggregationTest.php b/Tests/Functional/DSL/Aggregation/StatsAggregationTest.php index a6325412..eb102516 100644 --- a/Tests/Functional/DSL/Aggregation/StatsAggregationTest.php +++ b/Tests/Functional/DSL/Aggregation/StatsAggregationTest.php @@ -51,7 +51,7 @@ protected function getDataArray() public function testStatsAggregation() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $aggregation = new StatsAggregation('test_agg'); $aggregation->setField('price'); diff --git a/Tests/Functional/DSL/Aggregation/TermsAggregationTest.php b/Tests/Functional/DSL/Aggregation/TermsAggregationTest.php index 1bb55cdf..f8d5bef1 100644 --- a/Tests/Functional/DSL/Aggregation/TermsAggregationTest.php +++ b/Tests/Functional/DSL/Aggregation/TermsAggregationTest.php @@ -246,7 +246,7 @@ public function getTermsAggregationDataWithRangeQuery() public function testTermsAggregation($aggregation, $expectedResult) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repo->createSearch()->addAggregation($aggregation); $results = $repo->execute($search, Repository::RESULTS_RAW); @@ -266,7 +266,7 @@ public function testTermsAggregation($aggregation, $expectedResult) public function testTermsAggregationWithRangeQuery($aggregation, $parameters, $expectedResult) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $rangeQuery = new RangeQuery('price', $parameters); diff --git a/Tests/Functional/DSL/Aggregation/TopHitsAggregationTest.php b/Tests/Functional/DSL/Aggregation/TopHitsAggregationTest.php index 13761cfc..ca576aae 100644 --- a/Tests/Functional/DSL/Aggregation/TopHitsAggregationTest.php +++ b/Tests/Functional/DSL/Aggregation/TopHitsAggregationTest.php @@ -114,7 +114,7 @@ public function getTopHitsAggregationData() public function testTopHitsAggregation(AbstractAggregation $aggregation, $expectedHits) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $functions = [ 'script_score' => ['script' => "doc['price'].value"] ]; @@ -143,7 +143,7 @@ public function testTopHitsAggregation(AbstractAggregation $aggregation, $expect public function testTopHitsAggregationUsingGetter(AbstractAggregation $aggregation, $expectedHits) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $functions = [ 'script_score' => ['script' => "doc['price'].value"] ]; @@ -176,7 +176,7 @@ public function testTopHitsAggregationNested() $termAggregation->aggregations->addAggregation($topAggregation); /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repo->createSearch()->addAggregation($termAggregation)->addSort(new Sort('_id', Sort::ORDER_ASC)); $results = $repo->execute($search, Repository::RESULTS_RAW); diff --git a/Tests/Functional/DSL/Complex/BoolTestWithFuzzyQueryAndSortFilterTest.php b/Tests/Functional/DSL/Complex/BoolTestWithFuzzyQueryAndSortFilterTest.php index e24caae4..719d9f70 100644 --- a/Tests/Functional/DSL/Complex/BoolTestWithFuzzyQueryAndSortFilterTest.php +++ b/Tests/Functional/DSL/Complex/BoolTestWithFuzzyQueryAndSortFilterTest.php @@ -135,7 +135,7 @@ public function getTestBoolWithFuzzyQueryAndSortFilterData() public function testBoolWithFuzzyQueryAndSortFilter($field, $value, $parameters, $sort_field, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $FuzzyQuery = new FuzzyQuery($field, $value, $parameters); $SortFilter = new Sort($sort_field); $search = $repo->createSearch()->addQuery($FuzzyQuery); diff --git a/Tests/Functional/DSL/Complex/BoolTestWithMatchQueryAndLimitFilterTest.php b/Tests/Functional/DSL/Complex/BoolTestWithMatchQueryAndLimitFilterTest.php index 218ce5f2..293086f0 100644 --- a/Tests/Functional/DSL/Complex/BoolTestWithMatchQueryAndLimitFilterTest.php +++ b/Tests/Functional/DSL/Complex/BoolTestWithMatchQueryAndLimitFilterTest.php @@ -109,7 +109,7 @@ public function getTestBoolTestWithMatchQueryAndLimitFilterData() public function testBoolWithMatchQueryAndLimitFilter($query, $limit, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $matchQuery = new MatchQuery($query, 'description'); $limitFilter = new LimitFilter($limit); $search = $repo->createSearch()->addQuery($matchQuery); diff --git a/Tests/Functional/DSL/Complex/PostFilterAndAggregationTest.php b/Tests/Functional/DSL/Complex/PostFilterAndAggregationTest.php index df479bee..d4f7703c 100644 --- a/Tests/Functional/DSL/Complex/PostFilterAndAggregationTest.php +++ b/Tests/Functional/DSL/Complex/PostFilterAndAggregationTest.php @@ -73,7 +73,7 @@ protected function getDataArray() */ public function testBoolWithFuzzyQueryAndSortFilter() { - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repo->createSearch(); $rangeFilter = new RangeFilter('price', ['from' => 200, 'to' => 999]); diff --git a/Tests/Functional/DSL/Filter/AndFilterTest.php b/Tests/Functional/DSL/Filter/AndFilterTest.php index 937ad0b3..90127610 100644 --- a/Tests/Functional/DSL/Filter/AndFilterTest.php +++ b/Tests/Functional/DSL/Filter/AndFilterTest.php @@ -108,7 +108,7 @@ public function getAndFilterData() public function testAndFilter($prefixField, $prefixValue, $missingField, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $missing = new MissingFilter($missingField); $prefix = new PrefixFilter($prefixField, $prefixValue); diff --git a/Tests/Functional/DSL/Filter/BoolFilterTest.php b/Tests/Functional/DSL/Filter/BoolFilterTest.php index 179744b7..ac070390 100644 --- a/Tests/Functional/DSL/Filter/BoolFilterTest.php +++ b/Tests/Functional/DSL/Filter/BoolFilterTest.php @@ -100,7 +100,7 @@ public function getBoolFilterData() public function testBoolFilter($mustFilter, $mustNotFilter, $shouldFilter, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); /** @var Search $search */ $search = $repo->createSearch()->addFilter($mustFilter, 'must'); $search->addFilter($mustNotFilter, 'must_not'); diff --git a/Tests/Functional/DSL/Filter/ExistsFilterTest.php b/Tests/Functional/DSL/Filter/ExistsFilterTest.php index fab25e15..c0f7bd2e 100644 --- a/Tests/Functional/DSL/Filter/ExistsFilterTest.php +++ b/Tests/Functional/DSL/Filter/ExistsFilterTest.php @@ -45,7 +45,7 @@ protected function getDataArray() public function testExistsFilter() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $exists = new ExistsFilter('field', 'price'); $search = $repo->createSearch()->addFilter($exists); diff --git a/Tests/Functional/DSL/Filter/IdsFilterTest.php b/Tests/Functional/DSL/Filter/IdsFilterTest.php index 8cab2030..2e260b0e 100644 --- a/Tests/Functional/DSL/Filter/IdsFilterTest.php +++ b/Tests/Functional/DSL/Filter/IdsFilterTest.php @@ -109,7 +109,7 @@ public function getIdsFilterData() public function testIdsFilter($values, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $ids = new IdsFilter($values, $parameters); $search = $repo->createSearch()->addFilter($ids); $results = $repo->execute($search, Repository::RESULTS_ARRAY); diff --git a/Tests/Functional/DSL/Filter/IndicesFilterTest.php b/Tests/Functional/DSL/Filter/IndicesFilterTest.php index 96259cb8..7a798730 100644 --- a/Tests/Functional/DSL/Filter/IndicesFilterTest.php +++ b/Tests/Functional/DSL/Filter/IndicesFilterTest.php @@ -92,7 +92,7 @@ public function getIndicesFilterData() public function testIndicesFilter($filterParams, $noMatchFilterParams, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $filter = new PrefixFilter($filterParams[0], $filterParams[1]); if (is_string($noMatchFilterParams)) { diff --git a/Tests/Functional/DSL/Filter/LimitFilterTest.php b/Tests/Functional/DSL/Filter/LimitFilterTest.php index e721311e..9ffbb625 100644 --- a/Tests/Functional/DSL/Filter/LimitFilterTest.php +++ b/Tests/Functional/DSL/Filter/LimitFilterTest.php @@ -46,7 +46,7 @@ protected function getDataArray() public function testLimitFilter() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $limit = new LimitFilter(1); $search = $repo->createSearch()->addFilter($limit); diff --git a/Tests/Functional/DSL/Filter/MatchAllFilterTest.php b/Tests/Functional/DSL/Filter/MatchAllFilterTest.php index a2b45217..f9b5bfb3 100644 --- a/Tests/Functional/DSL/Filter/MatchAllFilterTest.php +++ b/Tests/Functional/DSL/Filter/MatchAllFilterTest.php @@ -40,7 +40,7 @@ protected function getDataArray() public function testMatchAllFilter() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $matchAll = new MatchAllFilter(); $search = $repo->createSearch()->addFilter($matchAll); diff --git a/Tests/Functional/DSL/Filter/MissingFilterTest.php b/Tests/Functional/DSL/Filter/MissingFilterTest.php index 0db83a6c..2255cf4a 100644 --- a/Tests/Functional/DSL/Filter/MissingFilterTest.php +++ b/Tests/Functional/DSL/Filter/MissingFilterTest.php @@ -45,7 +45,7 @@ protected function getDataArray() public function testMissingFilter() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $missing = new MissingFilter('price'); $search = $repo->createSearch()->addFilter($missing); diff --git a/Tests/Functional/DSL/Filter/NotFilterTest.php b/Tests/Functional/DSL/Filter/NotFilterTest.php index 46fa7178..1d067d22 100644 --- a/Tests/Functional/DSL/Filter/NotFilterTest.php +++ b/Tests/Functional/DSL/Filter/NotFilterTest.php @@ -89,7 +89,7 @@ public function getNotFilterData() public function testNotFilter($missingField, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $missing = new MissingFilter($missingField); $not = new NotFilter($missing, $parameters); $search = $repo->createSearch()->addFilter($not); diff --git a/Tests/Functional/DSL/Filter/OrFilterTest.php b/Tests/Functional/DSL/Filter/OrFilterTest.php index e1b34c6b..b4ab6dcc 100644 --- a/Tests/Functional/DSL/Filter/OrFilterTest.php +++ b/Tests/Functional/DSL/Filter/OrFilterTest.php @@ -108,7 +108,7 @@ public function getOrFilterData() public function testOrFilter($termFieldOne, $termValueOne, $termFieldTwo, $termValueTwo, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $filters = [ new TermFilter($termFieldOne, $termValueOne), diff --git a/Tests/Functional/DSL/Filter/PrefixFilterTest.php b/Tests/Functional/DSL/Filter/PrefixFilterTest.php index 71800607..4e99d3f8 100644 --- a/Tests/Functional/DSL/Filter/PrefixFilterTest.php +++ b/Tests/Functional/DSL/Filter/PrefixFilterTest.php @@ -45,7 +45,7 @@ protected function getDataArray() public function testPrefixFilter() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $prefix = new PrefixFilter('title', 'f', ['_cache' => true]); $search = $repo->createSearch()->addFilter($prefix); diff --git a/Tests/Functional/DSL/Filter/QueryFilterTest.php b/Tests/Functional/DSL/Filter/QueryFilterTest.php index 24125b9b..38652498 100644 --- a/Tests/Functional/DSL/Filter/QueryFilterTest.php +++ b/Tests/Functional/DSL/Filter/QueryFilterTest.php @@ -90,7 +90,7 @@ public function getQueryFilterData() public function testQueryFilter($query, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $not = new QueryFilter($query, $parameters); $search = $repo->createSearch()->addFilter($not); diff --git a/Tests/Functional/DSL/Filter/RangeFilterTest.php b/Tests/Functional/DSL/Filter/RangeFilterTest.php index 60f00f80..de7b8455 100644 --- a/Tests/Functional/DSL/Filter/RangeFilterTest.php +++ b/Tests/Functional/DSL/Filter/RangeFilterTest.php @@ -51,7 +51,7 @@ protected function getDataArray() public function testRangeFilter() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $range = new RangeFilter('price', ['from' => 50, 'to' => 80]); $search = $repo->createSearch()->addFilter($range); diff --git a/Tests/Functional/DSL/Filter/RegexpFilterTest.php b/Tests/Functional/DSL/Filter/RegexpFilterTest.php index 5bd3d78a..a55ebf24 100644 --- a/Tests/Functional/DSL/Filter/RegexpFilterTest.php +++ b/Tests/Functional/DSL/Filter/RegexpFilterTest.php @@ -117,7 +117,7 @@ public function getRegexpFilterData() public function testRegexpFilter($field, $regexp, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $regexp = new RegexpFilter($field, $regexp, $parameters); $search = $repo->createSearch()->addFilter($regexp); diff --git a/Tests/Functional/DSL/Filter/ScriptFilterTest.php b/Tests/Functional/DSL/Filter/ScriptFilterTest.php index 38a67ca0..d465d797 100644 --- a/Tests/Functional/DSL/Filter/ScriptFilterTest.php +++ b/Tests/Functional/DSL/Filter/ScriptFilterTest.php @@ -98,7 +98,7 @@ public function getScriptFilterData() public function testScriptFilter($script, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $script = new ScriptFilter($script, $parameters); $search = $repo->createSearch()->addFilter($script); $results = $repo->execute($search, Repository::RESULTS_ARRAY); diff --git a/Tests/Functional/DSL/Filter/TermFilterTest.php b/Tests/Functional/DSL/Filter/TermFilterTest.php index 0fbf5843..09ff9db8 100644 --- a/Tests/Functional/DSL/Filter/TermFilterTest.php +++ b/Tests/Functional/DSL/Filter/TermFilterTest.php @@ -51,7 +51,7 @@ protected function getDataArray() public function testTermFilter() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $field = 'user'; $term = 'zoo'; diff --git a/Tests/Functional/DSL/Filter/TermsFilterTest.php b/Tests/Functional/DSL/Filter/TermsFilterTest.php index 4c02be69..dcef648c 100644 --- a/Tests/Functional/DSL/Filter/TermsFilterTest.php +++ b/Tests/Functional/DSL/Filter/TermsFilterTest.php @@ -51,7 +51,7 @@ protected function getDataArray() public function testTermsFilter() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $field = 'user'; $terms = [ diff --git a/Tests/Functional/DSL/Filter/TypeFilterTest.php b/Tests/Functional/DSL/Filter/TypeFilterTest.php index 7a39118d..763dae66 100644 --- a/Tests/Functional/DSL/Filter/TypeFilterTest.php +++ b/Tests/Functional/DSL/Filter/TypeFilterTest.php @@ -51,7 +51,7 @@ protected function getDataArray() public function testTypeFilter() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $type = new TypeFilter('product'); $search = $repo->createSearch()->addFilter($type); diff --git a/Tests/Functional/DSL/Highlight/FieldTest.php b/Tests/Functional/DSL/Highlight/FieldTest.php index 9add8793..81e881de 100644 --- a/Tests/Functional/DSL/Highlight/FieldTest.php +++ b/Tests/Functional/DSL/Highlight/FieldTest.php @@ -57,7 +57,7 @@ protected function getDataArray() public function testHighlightedField() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $termQuery = new TermQuery('title', 'foo'); @@ -96,7 +96,7 @@ public function testHighlightedField() public function testFieldHighlightQuery() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $termQuery = new TermQuery('title', 'foo'); @@ -123,7 +123,7 @@ public function testFieldHighlightQuery() public function testNoMatchSize() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $termQuery = new TermQuery('description', 'description'); diff --git a/Tests/Functional/DSL/Highlight/HighlightTest.php b/Tests/Functional/DSL/Highlight/HighlightTest.php index 724a6161..ac831a99 100644 --- a/Tests/Functional/DSL/Highlight/HighlightTest.php +++ b/Tests/Functional/DSL/Highlight/HighlightTest.php @@ -16,7 +16,7 @@ use ONGR\ElasticsearchBundle\DSL\Query\TermQuery; use ONGR\ElasticsearchBundle\ORM\Repository; use ONGR\ElasticsearchBundle\Test\ElasticsearchTestCase; -use ONGR\TestingBundle\Document\Product; +use ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Product; /** * Highlighting functional test @@ -176,7 +176,7 @@ public function testHighlightParse() */ private function buildRepositoryAndTerm() { - $repository = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repository = $this->getManager()->getRepository('AcmeTestBundle:Product'); $termQuery = new TermQuery('title', 'foo'); diff --git a/Tests/Functional/DSL/Query/CommonTermsTest.php b/Tests/Functional/DSL/Query/CommonTermsTest.php index 369a3015..a329f830 100644 --- a/Tests/Functional/DSL/Query/CommonTermsTest.php +++ b/Tests/Functional/DSL/Query/CommonTermsTest.php @@ -104,7 +104,7 @@ public function getTestCommonTermsQueryData() public function testCommonTermsQuery($query, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $commonTermsQuery = new CommonTermsQuery('description', $query, $parameters); diff --git a/Tests/Functional/DSL/Query/ConstantScoreTest.php b/Tests/Functional/DSL/Query/ConstantScoreTest.php index 10336939..81b4ce48 100644 --- a/Tests/Functional/DSL/Query/ConstantScoreTest.php +++ b/Tests/Functional/DSL/Query/ConstantScoreTest.php @@ -50,7 +50,7 @@ protected function getDataArray() public function testConstantScoreQuery() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $constantScoreQuery = new ConstantScoreQuery(new MatchAllQuery()); diff --git a/Tests/Functional/DSL/Query/FunctionScoreQueryTest.php b/Tests/Functional/DSL/Query/FunctionScoreQueryTest.php index 0e61830b..bf772970 100644 --- a/Tests/Functional/DSL/Query/FunctionScoreQueryTest.php +++ b/Tests/Functional/DSL/Query/FunctionScoreQueryTest.php @@ -60,7 +60,7 @@ protected function getDataArray() public function testFunctionScoreQuery() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $functions = [ 'field_value_factor' => [ diff --git a/Tests/Functional/DSL/Query/FuzzyLikeThisFieldTest.php b/Tests/Functional/DSL/Query/FuzzyLikeThisFieldTest.php index c44a0aea..cef08204 100644 --- a/Tests/Functional/DSL/Query/FuzzyLikeThisFieldTest.php +++ b/Tests/Functional/DSL/Query/FuzzyLikeThisFieldTest.php @@ -99,7 +99,7 @@ public function getTestFuzzyLikeThisFieldQueryData() public function testFuzzyLikeThisFieldQuery($field, $likeText, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $fuzzyLikeThisFieldQuery = new FuzzyLikeThisField($field, $likeText, $parameters); $search = $repo->createSearch()->addQuery($fuzzyLikeThisFieldQuery); $results = $repo->execute($search, Repository::RESULTS_ARRAY); diff --git a/Tests/Functional/DSL/Query/FuzzyTest.php b/Tests/Functional/DSL/Query/FuzzyTest.php index 17989e54..29b2f7da 100644 --- a/Tests/Functional/DSL/Query/FuzzyTest.php +++ b/Tests/Functional/DSL/Query/FuzzyTest.php @@ -88,7 +88,7 @@ public function getTestFuzzyQueryData() public function testFuzzyQuery($field, $value, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $fuzzyQuery = new FuzzyQuery($field, $value, $parameters); $search = $repo->createSearch()->addQuery($fuzzyQuery); $results = $repo->execute($search, Repository::RESULTS_ARRAY); diff --git a/Tests/Functional/DSL/Query/IdsTest.php b/Tests/Functional/DSL/Query/IdsTest.php index bca12a1b..62381a2e 100644 --- a/Tests/Functional/DSL/Query/IdsTest.php +++ b/Tests/Functional/DSL/Query/IdsTest.php @@ -83,7 +83,7 @@ public function getTestIdsQueryData() public function testIdsQuery($values, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $idsQuery = new IdsQuery($values); $search = $repo->createSearch()->addQuery($idsQuery); $results = $repo->execute($search, Repository::RESULTS_ARRAY); diff --git a/Tests/Functional/DSL/Query/IndicesQueryTest.php b/Tests/Functional/DSL/Query/IndicesQueryTest.php index 312fd584..d1d5f63b 100644 --- a/Tests/Functional/DSL/Query/IndicesQueryTest.php +++ b/Tests/Functional/DSL/Query/IndicesQueryTest.php @@ -92,7 +92,7 @@ public function getIndicesQueryData() public function testAndFilter($queryParams, $noMatchQueryParams, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $query = new TermQuery($queryParams[0], $queryParams[1]); if (is_string($noMatchQueryParams)) { diff --git a/Tests/Functional/DSL/Query/MatchAllTest.php b/Tests/Functional/DSL/Query/MatchAllTest.php index 359652fd..6e0541ad 100644 --- a/Tests/Functional/DSL/Query/MatchAllTest.php +++ b/Tests/Functional/DSL/Query/MatchAllTest.php @@ -69,7 +69,7 @@ public function getMatchAllData() public function testMatchAllQuery($parameters) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $matchAllQuery = new MatchAllQuery($parameters); $search = $repo->createSearch()->addQuery($matchAllQuery); diff --git a/Tests/Functional/DSL/Query/MatchTest.php b/Tests/Functional/DSL/Query/MatchTest.php index ae082b62..4704406b 100644 --- a/Tests/Functional/DSL/Query/MatchTest.php +++ b/Tests/Functional/DSL/Query/MatchTest.php @@ -84,7 +84,7 @@ public function getTestMatchQueryData() public function testMatchQuery($query, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $matchQuery = new MatchQuery($query, 'description', $parameters); diff --git a/Tests/Functional/DSL/Query/MoreLikeThisTest.php b/Tests/Functional/DSL/Query/MoreLikeThisTest.php index 462ac1da..c6a76eea 100644 --- a/Tests/Functional/DSL/Query/MoreLikeThisTest.php +++ b/Tests/Functional/DSL/Query/MoreLikeThisTest.php @@ -119,7 +119,7 @@ public function getTestMoreLikeThisQueryData() public function testMoreLikeThisQuery($query, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $moreLikeThisQuery = new MoreLikeThisQuery($query, $parameters); diff --git a/Tests/Functional/DSL/Query/MultiMatchTest.php b/Tests/Functional/DSL/Query/MultiMatchTest.php index e5d2b063..a7685897 100644 --- a/Tests/Functional/DSL/Query/MultiMatchTest.php +++ b/Tests/Functional/DSL/Query/MultiMatchTest.php @@ -101,7 +101,7 @@ public function getTestMultiMatchQueryData() public function testMultiMatchQuery($query, $fields, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $multiMatchQuery = new MultiMatchQuery($query, $fields); diff --git a/Tests/Functional/DSL/Query/NestedQueryTest.php b/Tests/Functional/DSL/Query/NestedQueryTest.php index 6a6b7d64..c7e465cb 100644 --- a/Tests/Functional/DSL/Query/NestedQueryTest.php +++ b/Tests/Functional/DSL/Query/NestedQueryTest.php @@ -132,7 +132,7 @@ public function getTestNestedQueryData() public function testNestedQuery($query, $expected, $mapping) { /** @var Repository $repo */ - $repo = $this->getManager('default', true, $mapping)->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager('default', true, $mapping)->getRepository('AcmeTestBundle:Product'); $search = $repo->createSearch()->addQuery($query, 'must'); $results = $repo->execute($search, Repository::RESULTS_ARRAY); diff --git a/Tests/Functional/DSL/Query/QueryStringTest.php b/Tests/Functional/DSL/Query/QueryStringTest.php index 599bbd68..38c16581 100644 --- a/Tests/Functional/DSL/Query/QueryStringTest.php +++ b/Tests/Functional/DSL/Query/QueryStringTest.php @@ -93,7 +93,7 @@ public function getTestQueryStringQueryData() public function testQueryStringQuery($query, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $queryStringQuery = new QueryStringQuery($query, $parameters); diff --git a/Tests/Functional/DSL/Query/RangeTest.php b/Tests/Functional/DSL/Query/RangeTest.php index 1ced8b37..b666d097 100644 --- a/Tests/Functional/DSL/Query/RangeTest.php +++ b/Tests/Functional/DSL/Query/RangeTest.php @@ -82,7 +82,7 @@ public function getTestRangeQueryData() public function testRangeQuery($parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $rangeQuery = new RangeQuery('price', $parameters); diff --git a/Tests/Functional/DSL/Query/RegexpTest.php b/Tests/Functional/DSL/Query/RegexpTest.php index 78862a9f..698da8ee 100644 --- a/Tests/Functional/DSL/Query/RegexpTest.php +++ b/Tests/Functional/DSL/Query/RegexpTest.php @@ -77,7 +77,7 @@ public function getTestRegexpQueryData() public function testRegexpQuery($regexp, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $matchQuery = new RegexpQuery('title', $regexp, $parameters); diff --git a/Tests/Functional/DSL/Query/SimpleQueryStringTest.php b/Tests/Functional/DSL/Query/SimpleQueryStringTest.php index 389e49f3..f77a5012 100644 --- a/Tests/Functional/DSL/Query/SimpleQueryStringTest.php +++ b/Tests/Functional/DSL/Query/SimpleQueryStringTest.php @@ -81,7 +81,7 @@ public function getTestSimpleQueryStringQueryData() public function testSimpleQueryStringQuery($query, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $matchQuery = new SimpleQueryStringQuery($query, $parameters); diff --git a/Tests/Functional/DSL/Query/SpanTermTest.php b/Tests/Functional/DSL/Query/SpanTermTest.php index 63296854..26e689c2 100644 --- a/Tests/Functional/DSL/Query/SpanTermTest.php +++ b/Tests/Functional/DSL/Query/SpanTermTest.php @@ -75,7 +75,7 @@ public function getTestSpanTermQueryData() public function testSpanTermQuery($field, $value, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $termQuery = new SpanTermQuery($field, $value); diff --git a/Tests/Functional/DSL/Query/TermTest.php b/Tests/Functional/DSL/Query/TermTest.php index 08db7ff7..fbc0916f 100644 --- a/Tests/Functional/DSL/Query/TermTest.php +++ b/Tests/Functional/DSL/Query/TermTest.php @@ -84,7 +84,7 @@ public function getTestTermQueryData() public function testTermQuery($field, $value, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $termQuery = new TermQuery($field, $value, $parameters); $search = $repo->createSearch()->addQuery($termQuery); $results = $repo->execute($search, Repository::RESULTS_ARRAY); @@ -96,7 +96,7 @@ public function testTermQuery($field, $value, $parameters, $expected) */ public function testMultipleTerm() { - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $termQuery = new TermQuery('title', 'foo'); $termQuery2 = new TermQuery('price', 11); $search = $repo->createSearch(); diff --git a/Tests/Functional/DSL/Query/TermsTest.php b/Tests/Functional/DSL/Query/TermsTest.php index 509ab5c6..72ac6c1f 100644 --- a/Tests/Functional/DSL/Query/TermsTest.php +++ b/Tests/Functional/DSL/Query/TermsTest.php @@ -74,7 +74,7 @@ public function getTestTermsQueryData() public function testTermsQuery($tags, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $termsQuery = new TermsQuery('title', $tags, $parameters); diff --git a/Tests/Functional/DSL/Query/WildcardTest.php b/Tests/Functional/DSL/Query/WildcardTest.php index fe230f34..3fbc89cb 100644 --- a/Tests/Functional/DSL/Query/WildcardTest.php +++ b/Tests/Functional/DSL/Query/WildcardTest.php @@ -93,7 +93,7 @@ public function getTestWildcardQueryData() public function testWildcardQuery($field, $value, $parameters, $expected) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $wildcardQuery = new WildcardQuery($field, $value, $parameters); $search = $repo->createSearch()->addQuery($wildcardQuery); $results = $repo->execute($search, Repository::RESULTS_ARRAY); diff --git a/Tests/Functional/DSL/SearchTest.php b/Tests/Functional/DSL/SearchTest.php index c3a4fc65..be92ed43 100644 --- a/Tests/Functional/DSL/SearchTest.php +++ b/Tests/Functional/DSL/SearchTest.php @@ -97,7 +97,7 @@ public function setUp() { parent::setUp(); - $this->repository = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $this->repository = $this->getManager()->getRepository('AcmeTestBundle:Product'); } /** diff --git a/Tests/Functional/DSL/Sort/GeoSortTest.php b/Tests/Functional/DSL/Sort/GeoSortTest.php index 1ff0b721..b5ba1c7d 100644 --- a/Tests/Functional/DSL/Sort/GeoSortTest.php +++ b/Tests/Functional/DSL/Sort/GeoSortTest.php @@ -111,7 +111,7 @@ public function geoSortData() public function testGeoSort($sorts, $expectedIds, $expectedDistances) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repo->createSearch(); foreach ($sorts as $sort) { $search->addSort(new GeoSort($sort['field'], $sort['loc'], $sort['order'], $sort['unit'], $sort['mode'])); diff --git a/Tests/Functional/DSL/Sort/ScriptSortTest.php b/Tests/Functional/DSL/Sort/ScriptSortTest.php index aa2bc3a9..cd053351 100644 --- a/Tests/Functional/DSL/Sort/ScriptSortTest.php +++ b/Tests/Functional/DSL/Sort/ScriptSortTest.php @@ -95,7 +95,7 @@ public function scriptSortData() public function testScriptSort($sorts, $expectedIds) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repo->createSearch(); foreach ($sorts as $sort) { $search->addSort(new ScriptSort($sort['script'], $sort['type'], $sort['params'], $sort['order'])); diff --git a/Tests/Functional/DSL/Sort/SortTest.php b/Tests/Functional/DSL/Sort/SortTest.php index 698916a5..41b48083 100644 --- a/Tests/Functional/DSL/Sort/SortTest.php +++ b/Tests/Functional/DSL/Sort/SortTest.php @@ -109,7 +109,7 @@ public function simpleSortData() public function testSimpleSort($sorts, $expectedIds) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repo->createSearch(); foreach ($sorts as $sort) { $search->addSort(new Sort($sort['field'], $sort['order'], $sort['nested'], $sort['mode'])); diff --git a/Tests/Functional/DSL/Suggester/CompletionTest.php b/Tests/Functional/DSL/Suggester/CompletionTest.php index 882549ef..296eb5c1 100644 --- a/Tests/Functional/DSL/Suggester/CompletionTest.php +++ b/Tests/Functional/DSL/Suggester/CompletionTest.php @@ -88,7 +88,7 @@ public function testCompletionSuggester() $repository = $this ->getManager('default', true, $this->getCustomMapping()) - ->getRepository('ONGRTestingBundle:Product'); + ->getRepository('AcmeTestBundle:Product'); $search = $repository->createSearch()->addSuggester($completion); $result = $repository->execute($search, Repository::RESULTS_RAW); diff --git a/Tests/Functional/DSL/Suggester/ContextTest.php b/Tests/Functional/DSL/Suggester/ContextTest.php index c07315b1..ba198871 100644 --- a/Tests/Functional/DSL/Suggester/ContextTest.php +++ b/Tests/Functional/DSL/Suggester/ContextTest.php @@ -87,7 +87,7 @@ public function testContextSuggester() $context->addContext($geoContext); $context->addContext($categoryContext); - $repository = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repository = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repository->createSearch()->addSuggester($context); $result = $repository->execute($search, Repository::RESULTS_RAW); @@ -127,7 +127,7 @@ public function testContextSuggesterPrecision() $context->addContext($geoContext); $context->addContext($categoryContext); - $repository = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repository = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repository->createSearch()->addSuggester($context); $result = $repository->execute($search, Repository::RESULTS_RAW); diff --git a/Tests/Functional/DSL/Suggester/PhraseTest.php b/Tests/Functional/DSL/Suggester/PhraseTest.php index 6386d009..0702bd53 100644 --- a/Tests/Functional/DSL/Suggester/PhraseTest.php +++ b/Tests/Functional/DSL/Suggester/PhraseTest.php @@ -66,7 +66,7 @@ public function testPhraseSuggester() ] ); - $repository = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repository = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repository->createSearch()->addSuggester($phrase); $results = $repository->execute($search, Repository::RESULTS_RAW); diff --git a/Tests/Functional/DSL/Suggester/TermTest.php b/Tests/Functional/DSL/Suggester/TermTest.php index f25dd284..3f403a05 100644 --- a/Tests/Functional/DSL/Suggester/TermTest.php +++ b/Tests/Functional/DSL/Suggester/TermTest.php @@ -56,7 +56,7 @@ public function testTermSuggester() $term = new Term('description', 'ipsu'); $term->setAnalyzer('simple'); - $repository = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repository = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repository->createSearch()->addSuggester($term); $raw = $repository->execute($search, Repository::RESULTS_RAW); diff --git a/Tests/Functional/DependencyInjection/Compiler/MappingPassTest.php b/Tests/Functional/DependencyInjection/Compiler/MappingPassTest.php index 637c584c..de36f18c 100644 --- a/Tests/Functional/DependencyInjection/Compiler/MappingPassTest.php +++ b/Tests/Functional/DependencyInjection/Compiler/MappingPassTest.php @@ -30,7 +30,7 @@ public function testMapping() $container = $this->createClient()->getContainer(); $this->assertArrayHasKey( - 'ONGRTestingBundle', + 'AcmeTestBundle', $container->getParameter('kernel.bundles'), 'Test bundle is not loaded.' ); @@ -42,7 +42,7 @@ public function testMapping() $connection = $container->get('es.manager')->getConnection(); $productMapping = $connection->getMapping('product'); $expectedMapping = $mappingService->getMappingByNamespace( - 'ONGR\TestingBundle\Document\Product' + 'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Product' ); $this->assertEquals($expectedMapping['product']['properties'], $productMapping['properties']); diff --git a/Tests/Functional/DependencyInjection/ElasticsearchExtensionTest.php b/Tests/Functional/DependencyInjection/ElasticsearchExtensionTest.php index 1de07eeb..cca07feb 100644 --- a/Tests/Functional/DependencyInjection/ElasticsearchExtensionTest.php +++ b/Tests/Functional/DependencyInjection/ElasticsearchExtensionTest.php @@ -83,7 +83,7 @@ public function testContainerDefaultParams() 'default' => [ 'connection' => 'default', 'debug' => true, - 'mappings' => ['ONGRTestingBundle'], + 'mappings' => ['AcmeTestBundle'], ], 'bar' => [ 'connection' => 'bar', diff --git a/Tests/Functional/ORM/ManagerTest.php b/Tests/Functional/ORM/ManagerTest.php index 56d23b36..8ac3184f 100644 --- a/Tests/Functional/ORM/ManagerTest.php +++ b/Tests/Functional/ORM/ManagerTest.php @@ -14,13 +14,13 @@ use ONGR\ElasticsearchBundle\Document\DocumentInterface; use ONGR\ElasticsearchBundle\ORM\Manager; use ONGR\ElasticsearchBundle\Test\ElasticsearchTestCase; -use ONGR\TestingBundle\Document\CdnObject; -use ONGR\TestingBundle\Document\Comment; -use ONGR\TestingBundle\Document\CompletionSuggesting; -use ONGR\TestingBundle\Document\Product; -use ONGR\TestingBundle\Document\PriceLocationSuggesting; -use ONGR\TestingBundle\Document\PriceLocationContext; -use ONGR\TestingBundle\Document\UrlObject; +use ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\CdnObject; +use ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Comment; +use ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\CompletionSuggesting; +use ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Product; +use ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\PriceLocationSuggesting; +use ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\PriceLocationContext; +use ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\UrlObject; /** * Functional tests for orm manager. @@ -57,7 +57,7 @@ public function testPersist() $manager->persist($product); $manager->commit(); - $repository = $manager->getRepository('ONGRTestingBundle:Product'); + $repository = $manager->getRepository('AcmeTestBundle:Product'); /** @var Product[] $actualProduct */ $actualProducts = $repository->execute($repository->createSearch()); $this->assertCount(1, $actualProducts); @@ -105,7 +105,7 @@ public function testPersistSuggesters() $manager->persist($product); $manager->commit(); - $repository = $manager->getRepository('ONGRTestingBundle:Product'); + $repository = $manager->getRepository('AcmeTestBundle:Product'); /** @var Product[] $actualProduct */ $actualProducts = $repository->execute($repository->createSearch()); $this->assertCount(1, $actualProducts); @@ -145,7 +145,7 @@ public function getPersistExceptionsData() $product->links = new \ArrayIterator([new UrlObject(), new CdnObject()]); $out[] = [ $product, - 'Expected object of type ONGR\TestingBundle\Document\UrlObject, got ONGR\TestingBundle\Document\CdnObject.', + 'Expected object of type ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\UrlObject, got ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\CdnObject.', ]; // Case #3: invalid type of object is set in single field. @@ -156,7 +156,7 @@ public function getPersistExceptionsData() $product->links = [$url]; $out[] = [ $product, - 'Expected object of type ONGR\TestingBundle\Document\CdnObject, got ONGR\TestingBundle\Document\UrlObject.', + 'Expected object of type ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\CdnObject, got ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\UrlObject.', ]; return $out; @@ -199,7 +199,7 @@ public function testPersistSpecialFields() $manager->persist($comment); $manager->commit(); - $repository = $manager->getRepository('ONGRTestingBundle:Comment'); + $repository = $manager->getRepository('AcmeTestBundle:Comment'); $search = $repository->createSearch(); $results = $repository->execute($search); /** @var DocumentInterface $actualProduct */ @@ -226,7 +226,7 @@ public function testPersistDateField() $manager->persist($comment); $manager->commit(); - $repository = $manager->getRepository('ONGRTestingBundle:Comment'); + $repository = $manager->getRepository('AcmeTestBundle:Comment'); $search = $repository->createSearch(); $results = $repository->execute($search); /** @var DocumentInterface $actualProduct */ diff --git a/Tests/Functional/ORM/RepositoryTest.php b/Tests/Functional/ORM/RepositoryTest.php index db77be07..3ece074e 100644 --- a/Tests/Functional/ORM/RepositoryTest.php +++ b/Tests/Functional/ORM/RepositoryTest.php @@ -23,7 +23,7 @@ use ONGR\ElasticsearchBundle\Result\Suggestion\Option\TermOption; use ONGR\ElasticsearchBundle\Result\Suggestion\SuggestionIterator; use ONGR\ElasticsearchBundle\Test\ElasticsearchTestCase; -use ONGR\TestingBundle\Document\Product; +use ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Product; class RepositoryTest extends ElasticsearchTestCase { @@ -183,7 +183,7 @@ public function getFindByData() */ public function testFindBy($expectedResults, $criteria, $orderBy = [], $limit = null, $offset = null) { - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $fullResults = $repo->findBy($criteria, $orderBy, $limit, $offset); @@ -217,7 +217,7 @@ public function testFind() $manager->persist($product); $manager->commit(); - $repo = $manager->getRepository('ONGRTestingBundle:Product'); + $repo = $manager->getRepository('AcmeTestBundle:Product'); $result = $repo->find(123); @@ -231,7 +231,7 @@ public function testFind() */ public function testFindException() { - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $repo->find(123); } @@ -244,7 +244,7 @@ public function testFindException() public function testFindInMultiTypeRepo() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository(['ONGRTestingBundle:Product', 'ONGRTestingBundle:Content']); + $repo = $this->getManager()->getRepository(['AcmeTestBundle:Product', 'AcmeTestBundle:Content']); $repo->find(1); } @@ -256,7 +256,7 @@ public function testRemove() { $manager = $this->getManager(); - $repo = $manager->getRepository('ONGRTestingBundle:Product'); + $repo = $manager->getRepository('AcmeTestBundle:Product'); $response = $repo->remove(3); @@ -273,7 +273,7 @@ public function testRemoveException() { $manager = $this->getManager(); - $repo = $manager->getRepository('ONGRTestingBundle:Product'); + $repo = $manager->getRepository('AcmeTestBundle:Product'); $repo->remove(500); } @@ -283,11 +283,11 @@ public function testRemoveException() */ public function testCreateDocument() { - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $document = $repo->createDocument(); $this->assertInstanceOf( - 'ONGR\TestingBundle\Document\Product', + 'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Product', $document ); } @@ -300,7 +300,7 @@ public function testCreateDocument() */ public function testCreateDocumentException() { - $repo = $this->getManager()->getRepository(['ONGRTestingBundle:Product', 'ONGRTestingBundle:Content']); + $repo = $this->getManager()->getRepository(['AcmeTestBundle:Product', 'AcmeTestBundle:Content']); $repo->createDocument(); } @@ -310,7 +310,7 @@ public function testCreateDocumentException() public function testRepositoryExecuteWhenZeroResult() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repo->createSearch(); $search->addFilter(new PrefixFilter('title', 'dummy')); @@ -337,7 +337,7 @@ protected function getProductsArray() public function testDocumentUpdate() { $manager = $this->getManager(); - $repository = $manager->getRepository('ONGRTestingBundle:Product'); + $repository = $manager->getRepository('AcmeTestBundle:Product'); /** @var Product $document */ $document = $repository->createDocument(); @@ -518,7 +518,7 @@ public function getSuggestData() public function testSuggest($suggesters, $expectedResults) { $manager = $this->getManager(); - $repository = $manager->getRepository('ONGRTestingBundle:Product'); + $repository = $manager->getRepository('AcmeTestBundle:Product'); $results = $repository->suggest($suggesters); $this->assertScore($results); diff --git a/Tests/Functional/Result/AggregationIteratorFindTest.php b/Tests/Functional/Result/AggregationIteratorFindTest.php index c32a2cac..b158569f 100644 --- a/Tests/Functional/Result/AggregationIteratorFindTest.php +++ b/Tests/Functional/Result/AggregationIteratorFindTest.php @@ -120,7 +120,7 @@ public function getTestIterationData() public function testIteration($path, $expected) { $aggregation = $this->buildAggregation(); - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $search = $repo->createSearch()->addAggregation($aggregation); $results = $repo->execute($search); $result = $results->getAggregations()->find($path); diff --git a/Tests/Functional/Result/DocumentIteratorTest.php b/Tests/Functional/Result/DocumentIteratorTest.php index 92ce8e20..2a27d88d 100644 --- a/Tests/Functional/Result/DocumentIteratorTest.php +++ b/Tests/Functional/Result/DocumentIteratorTest.php @@ -60,7 +60,7 @@ protected function getDataArray() public function testIteration() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $match = new MatchAllQuery(); $search = $repo->createSearch()->addQuery($match); $iterator = $repo->execute($search, Repository::RESULTS_OBJECT); @@ -71,14 +71,14 @@ public function testIteration() $urls = $document->links; $this->assertInstanceOf( - 'ONGR\TestingBundle\Document\Product', + 'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Product', $document ); $this->assertInstanceOf('ONGR\ElasticsearchBundle\Result\ObjectIterator', $urls); foreach ($urls as $url) { $this->assertInstanceOf( - 'ONGR\TestingBundle\Document\UrlObject', + 'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\UrlObject', $url ); } @@ -90,7 +90,7 @@ public function testIteration() */ public function testCurrentWithEmptyIterator() { - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Content'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Content'); $search = $repo ->createSearch() ->addQuery(new MatchAllQuery()); diff --git a/Tests/Functional/Result/DocumentScanIteratorTest.php b/Tests/Functional/Result/DocumentScanIteratorTest.php index f33c714e..ceb47ac3 100644 --- a/Tests/Functional/Result/DocumentScanIteratorTest.php +++ b/Tests/Functional/Result/DocumentScanIteratorTest.php @@ -41,7 +41,7 @@ public function testIteration() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Content'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Content'); $search = $repo->createSearch(); $search->setSize(2); diff --git a/Tests/Functional/Result/SuggestionsIteratorTest.php b/Tests/Functional/Result/SuggestionsIteratorTest.php index ab7529ca..d337f4c9 100644 --- a/Tests/Functional/Result/SuggestionsIteratorTest.php +++ b/Tests/Functional/Result/SuggestionsIteratorTest.php @@ -158,7 +158,7 @@ public function getSuggestIterationData() public function testSuggestionIteration($suggesters, $expectedOptions) { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $match = new MatchAllQuery(); $search = $repo->createSearch()->addQuery($match); @@ -191,7 +191,7 @@ public function testSuggestionIteration($suggesters, $expectedOptions) public function testSuggestionProperties() { /** @var Repository $repo */ - $repo = $this->getManager()->getRepository('ONGRTestingBundle:Product'); + $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $match = new MatchAllQuery(); $search = $repo->createSearch()->addQuery($match); $search->addSuggester(new Phrase('description', 'Lorm adip', 'test')); diff --git a/Tests/Functional/Service/ESDataCollectorTest.php b/Tests/Functional/Service/ESDataCollectorTest.php index 7dcd2127..804564b6 100644 --- a/Tests/Functional/Service/ESDataCollectorTest.php +++ b/Tests/Functional/Service/ESDataCollectorTest.php @@ -51,7 +51,7 @@ protected function getDataArray() public function testGetQueryCount() { $manager = $this->getManager(); - $repository = $manager->getRepository('ONGRTestingBundle:Product'); + $repository = $manager->getRepository('AcmeTestBundle:Product'); $document = $repository->createDocument(); $document->title = 'Awesomo'; @@ -69,7 +69,7 @@ public function testGetQueryCount() public function testGetTime() { $manager = $this->getManager(); - $repository = $manager->getRepository('ONGRTestingBundle:Product'); + $repository = $manager->getRepository('AcmeTestBundle:Product'); $repository->find(3); $this->assertGreaterThan(0.0, $this->getCollector()->getTime(), 'Time should be greater than 0ms'); @@ -81,7 +81,7 @@ public function testGetTime() public function testGetQueries() { $manager = $this->getManager(); - $repository = $manager->getRepository('ONGRTestingBundle:Product'); + $repository = $manager->getRepository('AcmeTestBundle:Product'); $repository->find(2); $queries = $this->getCollector()->getQueries(); diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php index c038c430..e5ff87ec 100644 --- a/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -38,7 +38,7 @@ public function getTestConfigurationData() 'acme' => [ 'connection' => 'acme', 'debug' => false, - 'mappings' => ['ONGRTestingBundle'], + 'mappings' => ['AcmeTestBundle'], ], ], 'document_dir' => 'Document', @@ -56,7 +56,7 @@ public function getTestConfigurationData() 'managers' => [ 'acme' => [ 'connection' => 'acme', - 'mappings' => ['ONGRTestingBundle'], + 'mappings' => ['AcmeTestBundle'], ], ], ], @@ -77,7 +77,7 @@ public function getTestConfigurationData() 'managers' => [ 'acme' => [ 'connection' => 'acme', - 'mappings' => ['ONGRTestingBundle'], + 'mappings' => ['AcmeTestBundle'], ], ], ], @@ -96,7 +96,7 @@ public function getTestConfigurationData() 'managers' => [ 'acme' => [ 'connection' => 'acme', - 'mappings' => ['ONGRTestingBundle'], + 'mappings' => ['AcmeTestBundle'], ], ], ], @@ -117,7 +117,7 @@ public function getTestConfigurationData() 'managers' => [ 'acme' => [ 'connection' => 'acme', - 'mappings' => ['ONGRTestingBundle'], + 'mappings' => ['AcmeTestBundle'], ], ], ], @@ -167,7 +167,7 @@ public function getTestConfigurationData() 'managers' => [ 'acme' => [ 'connection' => 'acme', - 'mappings' => ['ONGRTestingBundle'], + 'mappings' => ['AcmeTestBundle'], ], ], ], diff --git a/Tests/Unit/Mapping/MetadataCollectorTest.php b/Tests/Unit/Mapping/MetadataCollectorTest.php index b7961fd7..c60bcb45 100644 --- a/Tests/Unit/Mapping/MetadataCollectorTest.php +++ b/Tests/Unit/Mapping/MetadataCollectorTest.php @@ -98,7 +98,7 @@ public function testGetMappingCache() ->getMockBuilder('ONGR\ElasticsearchBundle\Mapping\MetadataCollector') ->setConstructorArgs( [ - ['ONGRTestingBundle' => 'ONGR/TestingBundle/ONGRTestingBundle'], + ['AcmeTestBundle' => 'ONGR/TestingBundle/AcmeTestBundle'], $this->getCachedReaderMock(), ] ) @@ -108,13 +108,13 @@ public function testGetMappingCache() $collector ->expects($this->exactly(1)) ->method('getBundleMapping') - ->with('ONGRTestingBundle') + ->with('AcmeTestBundle') ->will($this->returnValue($mapping)); // Caches. - $this->assertEquals($expectedMapping, $collector->getMapping('ONGRTestingBundle')); + $this->assertEquals($expectedMapping, $collector->getMapping('AcmeTestBundle')); // Loads from local cache. - $this->assertEquals($expectedMapping, $collector->getMapping('ONGRTestingBundle')); + $this->assertEquals($expectedMapping, $collector->getMapping('AcmeTestBundle')); } /** @@ -125,11 +125,11 @@ public function testGetMappingCache() public function testGet() { $collector = new MetadataCollector( - ['ONGRTestingBundle' => 'ONGR\TestingBundle\ONGRTestingBundle'], + ['AcmeTestBundle' => 'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\AcmeTestBundle'], new AnnotationReader() ); - $mapping = $collector->getMapping('ONGRTestingBundle'); + $mapping = $collector->getMapping('AcmeTestBundle'); $this->assertArrayContainsArray( [ @@ -165,7 +165,7 @@ public function testGet() public function testBundleNotFound() { $collector = new MetadataCollector([], $this->getCachedReaderMock()); - $collector->getMapping('ONGRTestingBundle'); + $collector->getMapping('AcmeTestBundle'); } /** @@ -176,17 +176,17 @@ public function getTestGetMappingByNamespaceData() $mapping = [ 'product' => [ 'properties' => $this->getProductMapping(), - 'class' => 'ONGR\TestingBundle\Document\Product', + 'class' => 'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Product', ] ]; return [ [ - 'ONGRTestingBundle:Product', + 'AcmeTestBundle:Product', $mapping, ], [ - 'ONGR\TestingBundle\Document\Product', + 'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Product', $mapping, ], ]; @@ -203,7 +203,7 @@ public function getTestGetMappingByNamespaceData() public function testGetMappingByNamespace($namespace, $expectedMapping) { $collector = new MetadataCollector( - ['ONGRTestingBundle' => 'ONGR\TestingBundle\ONGRTestingBundle'], + ['AcmeTestBundle' => 'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\AcmeTestingBundle'], new AnnotationReader() ); diff --git a/Tests/Unit/ORM/RepositoryTest.php b/Tests/Unit/ORM/RepositoryTest.php index 0095fe5c..3d25a7f5 100644 --- a/Tests/Unit/ORM/RepositoryTest.php +++ b/Tests/Unit/ORM/RepositoryTest.php @@ -27,11 +27,11 @@ public function getExecuteData() $out = []; $bundlesMapping = [ - 'ONGRTestingBundle:Product' => [ + 'AcmeTestBundle:Product' => [ 'type' => 'product', 'fields' => [], ], - 'ONGRTestingBundle:Content' => [ + 'AcmeTestBundle:Content' => [ 'type' => 'content', 'fields' => [], ], @@ -39,7 +39,7 @@ public function getExecuteData() // Case #0 Single type. $out[] = [ - ['ONGRTestingBundle:Product'], + ['AcmeTestBundle:Product'], ['product'], $bundlesMapping, ]; diff --git a/Tests/Unit/Result/DocumentIteratorTest.php b/Tests/Unit/Result/DocumentIteratorTest.php index ca7d4a0b..37166e90 100644 --- a/Tests/Unit/Result/DocumentIteratorTest.php +++ b/Tests/Unit/Result/DocumentIteratorTest.php @@ -304,7 +304,7 @@ private function assertContentEquals($iterator, $expectedHeaders) { foreach ($iterator as $key => $item) { $this->assertInstanceOf( - 'ONGR\TestingBundle\Document\Content', + 'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Content', $item ); $this->assertEquals($expectedHeaders[$key], $item->header); @@ -321,7 +321,7 @@ private function assertContentEquals($iterator, $expectedHeaders) private function getBundleMapping() { return [ - 'ONGRTestingBundle:Content' => [ + 'AcmeTestBundle:Content' => [ 'setters' => [ 'header' => [ 'exec' => false, @@ -331,7 +331,7 @@ private function getBundleMapping() 'properties' => [ 'header' => ['type' => 'string'] ], - 'namespace' => 'ONGR\TestingBundle\Document\Content', + 'namespace' => 'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Content', ], ]; } @@ -343,6 +343,6 @@ private function getBundleMapping() */ private function getTypesMapping() { - return ['content' => 'ONGRTestingBundle:Content']; + return ['content' => 'AcmeTestBundle:Content']; } } diff --git a/Tests/Unit/Service/JsonFormatterTest.php b/Tests/Unit/Service/JsonFormatterTest.php index 5866293a..b7d819b4 100644 --- a/Tests/Unit/Service/JsonFormatterTest.php +++ b/Tests/Unit/Service/JsonFormatterTest.php @@ -85,7 +85,7 @@ public function testPrettify($inlineJson, $prettyJson) */ private function getFileContents($filename) { - $contents = file_get_contents(__DIR__ . '/../../app/fixtures/JsonFormatter/' . $filename); + $contents = file_get_contents(__DIR__ . '/../../app/fixture/JsonFormatter/' . $filename); // Checks for new line at the end of file. if (substr($contents, -1) == "\n") { diff --git a/Tests/app/AppKernel.php b/Tests/app/AppKernel.php index 085ad4c7..f8257130 100644 --- a/Tests/app/AppKernel.php +++ b/Tests/app/AppKernel.php @@ -27,7 +27,7 @@ public function registerBundles() return [ new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(), - new ONGR\TestingBundle\ONGRTestingBundle(), + new ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\AcmeTestBundle(), ]; } diff --git a/Tests/app/config/config_test.yml b/Tests/app/config/config_test.yml index de06fb4f..eefc7331 100644 --- a/Tests/app/config/config_test.yml +++ b/Tests/app/config/config_test.yml @@ -24,7 +24,7 @@ ongr_elasticsearch: connection: default debug: true mappings: - - ONGRTestingBundle + - AcmeTestBundle bar: connection: bar mappings: diff --git a/Tests/app/fixture/Acme/TestBundle/AcmeTestBundle.php b/Tests/app/fixture/Acme/TestBundle/AcmeTestBundle.php new file mode 100644 index 00000000..dbb07da0 --- /dev/null +++ b/Tests/app/fixture/Acme/TestBundle/AcmeTestBundle.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +/** + * AcmeTestBundle for testing. + */ +class AcmeTestBundle extends Bundle +{ + +} diff --git a/Tests/app/fixture/Acme/TestBundle/Document/Category.php b/Tests/app/fixture/Acme/TestBundle/Document/Category.php new file mode 100644 index 00000000..c08a5061 --- /dev/null +++ b/Tests/app/fixture/Acme/TestBundle/Document/Category.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document; + +use ONGR\ElasticsearchBundle\Annotation as ES; + +/** + * Category document for testing. + * + * @ES\Object + */ +class Category +{ + + public $hiddenField; +} diff --git a/Tests/app/fixture/Acme/TestBundle/Document/CdnObject.php b/Tests/app/fixture/Acme/TestBundle/Document/CdnObject.php new file mode 100644 index 00000000..675405c5 --- /dev/null +++ b/Tests/app/fixture/Acme/TestBundle/Document/CdnObject.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document; + +use ONGR\ElasticsearchBundle\Annotation as ES; + +/** + * CdnObject document for testing. + * + * @ES\Object + */ +class CdnObject +{ + /** + * @var string + * + * @ES\Property(name="cdn_url", type="string") + */ + public $cdn_url; +} diff --git a/Tests/app/fixture/Acme/TestBundle/Document/Comment.php b/Tests/app/fixture/Acme/TestBundle/Document/Comment.php new file mode 100644 index 00000000..eb13c59e --- /dev/null +++ b/Tests/app/fixture/Acme/TestBundle/Document/Comment.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document; + +use ONGR\ElasticsearchBundle\Annotation as ES; +use ONGR\ElasticsearchBundle\Document\DocumentInterface; +use ONGR\ElasticsearchBundle\Document\DocumentTrait; + +/** + * Comment document for testing. + * + * @ES\Document(type="comment", parent="AcmeTestBundle:Content", ttl={"enabled":true, "default": "1d"}) + */ +class Comment implements DocumentInterface +{ + use DocumentTrait; + + /** + * @var string + * + * @ES\Property(type="string", name="userName") + */ + public $userName; + + /** + * @var \DateTime + * + * @ES\Property(name="createdAt", type="date") + */ + private $createdAt; + + /** + * Constructor. + */ + public function __construct() + { + $this->createdAt = new \DateTime(); + } + + /** + * @return \DateTime + */ + public function getCreatedAt() + { + return $this->createdAt; + } + + /** + * @param \DateTime $createdAt + */ + public function setCreatedAt(\DateTime $createdAt) + { + $this->createdAt = $createdAt; + } +} diff --git a/Tests/app/fixture/Acme/TestBundle/Document/CompletionSuggesting.php b/Tests/app/fixture/Acme/TestBundle/Document/CompletionSuggesting.php new file mode 100644 index 00000000..12661be2 --- /dev/null +++ b/Tests/app/fixture/Acme/TestBundle/Document/CompletionSuggesting.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document; + +use ONGR\ElasticsearchBundle\Annotation as ES; +use ONGR\ElasticsearchBundle\Document\Suggester\CompletionSuggesterInterface; +use ONGR\ElasticsearchBundle\Document\Suggester\CompletionSuggesterTrait; + +/** + * Suggesting document for testing. + * + * @ES\Object + */ +class CompletionSuggesting implements CompletionSuggesterInterface +{ + use CompletionSuggesterTrait; +} diff --git a/Tests/app/fixture/Acme/TestBundle/Document/Content.php b/Tests/app/fixture/Acme/TestBundle/Document/Content.php new file mode 100644 index 00000000..c171ebfc --- /dev/null +++ b/Tests/app/fixture/Acme/TestBundle/Document/Content.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document; + +use ONGR\ElasticsearchBundle\Annotation as ES; +use ONGR\ElasticsearchBundle\Document\DocumentInterface; +use ONGR\ElasticsearchBundle\Document\DocumentTrait; + +/** + * Content document for testing. + * + * @ES\Document(type="fooContent") + */ +class Content implements DocumentInterface +{ + use DocumentTrait; + + /** + * @var string + * + * @ES\Property(type="string", name="header") + */ + public $header; +} diff --git a/Tests/app/fixture/Acme/TestBundle/Document/ImagesNested.php b/Tests/app/fixture/Acme/TestBundle/Document/ImagesNested.php new file mode 100644 index 00000000..b0c1d619 --- /dev/null +++ b/Tests/app/fixture/Acme/TestBundle/Document/ImagesNested.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document; + +use ONGR\ElasticsearchBundle\Annotation as ES; + +/** + * Images nested document for testing. + * + * @ES\Nested + */ +class ImagesNested +{ + /** + * @var string + * + * @ES\Property(name="url", type="string") + */ + public $url; + + /** + * @var string + * + * + * @ES\Property(name="title", type="string", index="no") + */ + public $title; + + /** + * @var string + * + * @ES\Property(name="description", type="string", index="no") + */ + public $description; + + /** + * @var object + * + * @ES\Property(name="cdn", type="object", objectName="AcmeTestBundle:CdnObject") + */ + public $cdn; +} diff --git a/Tests/app/fixture/Acme/TestBundle/Document/PriceLocationContext.php b/Tests/app/fixture/Acme/TestBundle/Document/PriceLocationContext.php new file mode 100644 index 00000000..5eaf202f --- /dev/null +++ b/Tests/app/fixture/Acme/TestBundle/Document/PriceLocationContext.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document; + +use ONGR\ElasticsearchBundle\Annotation as ES; + +/** + * SuggestingContext document for testing. + * + * @ES\Object + */ +class PriceLocationContext +{ + /** + * @var string + * + * @ES\Property(name="price", type="string") + */ + public $price; + + /** + * @var array + * + * @ES\Property(name="location", type="string") + */ + public $location; +} diff --git a/Tests/app/fixture/Acme/TestBundle/Document/PriceLocationSuggesting.php b/Tests/app/fixture/Acme/TestBundle/Document/PriceLocationSuggesting.php new file mode 100644 index 00000000..3fcfd73a --- /dev/null +++ b/Tests/app/fixture/Acme/TestBundle/Document/PriceLocationSuggesting.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document; + +use ONGR\ElasticsearchBundle\Annotation as ES; +use ONGR\ElasticsearchBundle\Document\Suggester\ContextSuggesterInterface; +use ONGR\ElasticsearchBundle\Document\Suggester\ContextSuggesterTrait; + +/** + * Suggesting document for testing. + * + * @ES\Object + */ +class PriceLocationSuggesting implements ContextSuggesterInterface +{ + use ContextSuggesterTrait; + + /** + * @var object + * + * @ES\Property(type="object", objectName="AcmeTestBundle:PriceLocationContext", name="context") + */ + private $context; +} diff --git a/Tests/app/fixture/Acme/TestBundle/Document/Product.php b/Tests/app/fixture/Acme/TestBundle/Document/Product.php new file mode 100644 index 00000000..fc528a3f --- /dev/null +++ b/Tests/app/fixture/Acme/TestBundle/Document/Product.php @@ -0,0 +1,103 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document; + +use ONGR\ElasticsearchBundle\Annotation as ES; +use ONGR\ElasticsearchBundle\Document\DocumentInterface; +use ONGR\ElasticsearchBundle\Document\DocumentTrait; + +/** + * Product document for testing. + * + * @ES\Document(type="product") + */ +class Product implements DocumentInterface +{ + use DocumentTrait; + + /** + * @var string + * + * @ES\Property(type="string", name="title", fields={@ES\MultiField(name="raw", type="string")}) + */ + public $title; + + /** + * @var string + * + * @ES\Property(type="string", name="description") + */ + public $description; + + /** + * @var PriceLocationSuggesting + * + * @ES\Suggester\ContextSuggesterProperty( + * name = "suggestions", + * objectName = "AcmeTestBundle:PriceLocationSuggesting", + * payloads = true, + * context = { + * @ES\Suggester\Context\GeoLocationContext(name="location", precision = "5m", neighbors = true, default = "u33"), + * @ES\Suggester\Context\CategoryContext(name="price", default = {"red", "green"}, path = "description") + * } + * ) + */ + public $contextSuggesting; + + /** + * @var CompletionSuggesting + * + * @ES\Suggester\CompletionSuggesterProperty( + * name = "completion_suggesting", + * objectName = "AcmeTestBundle:CompletionSuggesting", + * index_analyzer = "simple", + * search_analyzer = "simple", + * payloads = false, + * ) + */ + public $completionSuggesting; + + /** + * @var float + * + * @ES\Property(type="float", name="price") + */ + public $price; + + /** + * @var string + * + * @ES\Property(type="geo_point", name="location") + */ + public $location; + + /** + * @var UrlObject[]|\Iterator + * + * @ES\Property(type="object", objectName="AcmeTestBundle:UrlObject", multiple=true, name="url") + */ + public $links; + + /** + * @var ImagesNested[]|\Iterator + * + * @ES\Property(type="nested", objectName="AcmeTestBundle:ImagesNested", multiple=true, name="images") + */ + public $images; + + /** + * @var Category[]|\Iterator + * + * @ES\Property(type="object", objectName="AcmeTestBundle:Category", multiple=true, name="categories") + */ + public $categories; +} diff --git a/Tests/app/fixture/Acme/TestBundle/Document/UrlObject.php b/Tests/app/fixture/Acme/TestBundle/Document/UrlObject.php new file mode 100644 index 00000000..3354ff53 --- /dev/null +++ b/Tests/app/fixture/Acme/TestBundle/Document/UrlObject.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document; + +use ONGR\ElasticsearchBundle\Annotation as ES; + +/** + * UrlObject document for testing. + * + * @ES\Object + */ +class UrlObject +{ + /** + * @var string + * + * @ES\Property(name="url", type="string") + */ + public $url; + + /** + * @var string + * + * @ES\Property(name="key", type="string", index="no") + */ + public $urlKey; + + /** + * @var CdnObject + * + * @ES\Property(name="cdn", type="object", objectName="AcmeTestBundle:CdnObject") + */ + public $cdn; + + /** + * @param string $urlKey + */ + public function setUrlKey($urlKey) + { + $this->urlKey = $urlKey; + } + + /** + * @return string + */ + public function getUrlKey() + { + return $this->urlKey; + } +} diff --git a/Tests/app/fixture/Acme/TestBundle/Document/documentSample.txt b/Tests/app/fixture/Acme/TestBundle/Document/documentSample.txt new file mode 100644 index 00000000..8f4fdc53 --- /dev/null +++ b/Tests/app/fixture/Acme/TestBundle/Document/documentSample.txt @@ -0,0 +1,22 @@ + Date: Fri, 5 Dec 2014 16:06:15 +0200 Subject: [PATCH 10/10] Added missing sorting for suggestion tests. --- Tests/Functional/ORM/ManagerTest.php | 6 ++++-- .../Result/SuggestionsIteratorTest.php | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Tests/Functional/ORM/ManagerTest.php b/Tests/Functional/ORM/ManagerTest.php index 8ac3184f..c8d179ae 100644 --- a/Tests/Functional/ORM/ManagerTest.php +++ b/Tests/Functional/ORM/ManagerTest.php @@ -145,7 +145,8 @@ public function getPersistExceptionsData() $product->links = new \ArrayIterator([new UrlObject(), new CdnObject()]); $out[] = [ $product, - 'Expected object of type ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\UrlObject, got ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\CdnObject.', + 'Expected object of type ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\UrlObject, ' . + 'got ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\CdnObject.', ]; // Case #3: invalid type of object is set in single field. @@ -156,7 +157,8 @@ public function getPersistExceptionsData() $product->links = [$url]; $out[] = [ $product, - 'Expected object of type ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\CdnObject, got ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\UrlObject.', + 'Expected object of type ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\CdnObject, ' . + 'got ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\UrlObject.', ]; return $out; diff --git a/Tests/Functional/Result/SuggestionsIteratorTest.php b/Tests/Functional/Result/SuggestionsIteratorTest.php index d337f4c9..395ac47a 100644 --- a/Tests/Functional/Result/SuggestionsIteratorTest.php +++ b/Tests/Functional/Result/SuggestionsIteratorTest.php @@ -22,6 +22,7 @@ use ONGR\ElasticsearchBundle\Result\Suggestion\Option\PhraseOption; use ONGR\ElasticsearchBundle\Result\Suggestion\Option\SimpleOption; use ONGR\ElasticsearchBundle\Result\Suggestion\Option\TermOption; +use ONGR\ElasticsearchBundle\Result\Suggestion\SuggestionEntry; use ONGR\ElasticsearchBundle\Test\ElasticsearchTestCase; class SuggestionsIteratorTest extends ElasticsearchTestCase @@ -113,7 +114,7 @@ public function getSuggestIterationData() // Case #3, Multiple suggesters. $term = new Term('description', 'ipsu'); $phrase = new Phrase('description', 'Lorm adip'); - $expectedOptions = [new TermOption('ipsum', 0.0, 3), new SimpleOption('lorem adip', 0.0)]; + $expectedOptions = [new SimpleOption('lorem adip', 0.0), new TermOption('ipsum', 0.0, 3)]; $out[] = ['suggesters' => [$term, $phrase], 'expectedOptions' => $expectedOptions]; @@ -121,9 +122,9 @@ public function getSuggestIterationData() $term = new Term('description', 'distibutd'); $phrase = new Phrase('description', 'Lorm adip'); $expectedOptions = [ + new SimpleOption('lorem adip', 0.0), new TermOption('disributed', 0.0, 1), new TermOption('distributed', 0.0, 1), - new SimpleOption('lorem adip', 0.0), ]; $out[] = ['suggesters' => [$term, $phrase], 'expectedOptions' => $expectedOptions]; @@ -170,13 +171,21 @@ public function testSuggestionIteration($suggesters, $expectedOptions) $this->assertInstanceOf('ONGR\ElasticsearchBundle\Result\DocumentIterator', $iterator); - $suggestions = $iterator->getSuggestions(); + $suggestions = iterator_to_array($iterator->getSuggestions()); + + sort($suggestions); + sort($expectedOptions); $optionCount = 0; + /** @var SuggestionEntry[] $suggestionEntries */ foreach ($suggestions as $suggestionEntries) { foreach ($suggestionEntries as $suggestionEntry) { $this->assertInstanceOf('ONGR\ElasticsearchBundle\Result\Suggestion\SuggestionEntry', $suggestionEntry); - foreach ($suggestionEntry->getOptions() as $option) { + $options = iterator_to_array($suggestionEntry->getOptions()); + sort($options); + + /** @var SimpleOption $option */ + foreach ($options as $option) { $option->setScore(0.0); $this->assertEquals($expectedOptions[$optionCount++], $option); }