Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Behat/SearchManagerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private function doIndexTheFollowingObjects($className, PyStringNode $string)
foreach ($objectsData as $objectData) {
$object = new $this->entityClasses[$className]();
foreach ($objectData as $key => $value) {
if (is_string($value) && ($date = \DateTime::createFromFormat('Y-m-d', $value)) !== false) {
if (is_string($value) && false !== ($date = \DateTime::createFromFormat('Y-m-d', $value))) {
$value = $date;
}
$object->$key = $value;
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ CHANGELOG
=========

* dev-master
* ENHANCEMENT #114 Updated elasticsearch dependency
* ENHANCEMENT #111 Increased php memory_limit and fixed elasticsearch-installation for travis

* 0.16.2 (2017-06-16)
* HOTFIX #3406 (Sulu) Modified ElasticSearchAdapter search function, removed size paramter once limit is empty

Expand Down
4 changes: 2 additions & 2 deletions Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function execute(InputInterface $input, OutputInterface $output)

$startTime = microtime(true);

if ($this->env !== 'prod') {
if ('prod' !== $this->env) {
$output->writeln(
$formatterHelper->formatBlock(
sprintf(
Expand Down Expand Up @@ -197,7 +197,7 @@ private function reindexClass(
while (true) {
$objects = $provider->provide($classFqn, $offset, $batchSize);

if (count($objects) === 0) {
if (0 === count($objects)) {
$provider->cleanUp($classFqn);
$this->resumeManager->setCheckpoint($providerName, $classFqn, $count);
$progress->finish();
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Compiler/ConverterPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
class ConverterPass implements CompilerPassInterface
{
const SERVICE_ID = 'massive_search.converter';

const TAG_NAME = 'massive_search.converter';

/**
Expand Down
12 changes: 12 additions & 0 deletions Resources/docs/searching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ when represented as JSON:
"score": 0.39123123123123
}

Search results are paged. By default, only the first page is returned and a page contains 10 results. This can be
controlled on the SearchQuery like this:

.. code-block:: php

<?php
$hits = $searchManager
->createSearch('My Article')
->setLimit(100) // A page now contains 100 results
->setOffset(1) // Return the second page of results
->execute();

Indexing and deindexing
-----------------------

Expand Down
6 changes: 6 additions & 0 deletions Search/Adapter/ElasticSearchAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@
class ElasticSearchAdapter implements AdapterInterface
{
const ID_FIELDNAME = '__id';

const INDEX_FIELDNAME = '__index';

const CLASS_TAG = '__class';

const URL_FIELDNAME = '__url';

const TITLE_FIELDNAME = '__title';

const DESCRIPTION_FIELDNAME = '__description';

const LOCALE_FIELDNAME = '__locale';

const IMAGE_URL = '__image_url';

/**
Expand Down
1 change: 1 addition & 0 deletions Search/Adapter/TestAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
class TestAdapter implements AdapterInterface
{
protected $documents = [];

protected $factory;

public function __construct(Factory $factory)
Expand Down
11 changes: 9 additions & 2 deletions Search/Adapter/ZendLuceneAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@
class ZendLuceneAdapter implements AdapterInterface
{
const ID_FIELDNAME = '__id';

const INDEX_FIELDNAME = '__index';

const CLASS_TAG = '__class';

const AGGREGATED_INDEXED_CONTENT = '__content';

const URL_FIELDNAME = '__url';

const TITLE_FIELDNAME = '__title';

const LOCALE_FIELDNAME = '__locale';

const DESCRIPTION_FIELDNAME = '__description';

const IMAGE_URL = '__image_url';

/**
Expand Down Expand Up @@ -114,13 +121,13 @@ public function index(Document $document, $indexName)
$type = $field->getType();
$value = $field->getValue();

if ($type === Field::TYPE_NULL) {
if (Field::TYPE_NULL === $type) {
continue;
}

// Zend Lucene does not support "types". We should allow other "types" once they
// are properly implemented in at least one other adapter.
if ($type !== Field::TYPE_STRING && $type !== Field::TYPE_ARRAY) {
if (Field::TYPE_STRING !== $type && Field::TYPE_ARRAY !== $type) {
throw new \InvalidArgumentException(
sprintf(
'Search field type "%s" is not known. Known types are: %s',
Expand Down
3 changes: 0 additions & 3 deletions Search/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ public function getStatus();
*/
public function listIndexes();

/**
* {@inheritdoc}
*/
public function flush(array $indexNames);

/**
Expand Down
2 changes: 1 addition & 1 deletion Search/Decorator/LocalizationDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function isVariant($indexName, $decoratedIndexName, array $options = [])
*/
private function removeLocale($decoratedIndexName)
{
if (preg_match('/(.*)(-.*-i18n)/', $decoratedIndexName, $matches) === 0) {
if (0 === preg_match('/(.*)(-.*-i18n)/', $decoratedIndexName, $matches)) {
return $decoratedIndexName;
}

Expand Down
2 changes: 1 addition & 1 deletion Search/Decorator/PrefixDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function isVariant($indexName, $decoratedIndexName, array $options = [])
*/
private function removePrefix($decoratedIndexName)
{
if (strpos($decoratedIndexName, $this->prefix . '_') === 0) {
if (0 === strpos($decoratedIndexName, $this->prefix . '_')) {
$decoratedIndexName = substr($decoratedIndexName, strlen($this->prefix) + 1);

return $decoratedIndexName;
Expand Down
1 change: 1 addition & 0 deletions Search/Event/HitEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class HitEvent extends Event
{
protected $hit;

protected $metadata;

public function __construct(QueryHit $hit, ClassMetadata $metadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function ($elements, $expression) {
throw new \Exception('Map function does not support compilation');
},
function (array $values, $elements, $expression) {
if (count($elements) === 0) {
if (0 === count($elements)) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion Search/Metadata/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function loadMetadataFromFile(\ReflectionClass $class, $file)
));
}

if (count($xml->children()) == 0) {
if (0 == count($xml->children())) {
throw new \InvalidArgumentException(sprintf('No mapping in file "%s"', $file));
}

Expand Down
1 change: 0 additions & 1 deletion Search/Metadata/Provider/DefaultProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Massive\Bundle\SearchBundle\Search\Document;
use Massive\Bundle\SearchBundle\Search\Metadata\ProviderInterface;
use Metadata\MetadataFactory;
use Metadata\MetadataFactoryInterface;

/**
Expand Down
8 changes: 4 additions & 4 deletions Search/ObjectToDocumentConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private function populateDocument($document, $object, $fieldMapping, $prefix = '
$mapping
);

if ($mapping['type'] == 'complex') {
if ('complex' == $mapping['type']) {
if (!isset($mapping['mapping'])) {
throw new \InvalidArgumentException(
sprintf(
Expand Down Expand Up @@ -185,7 +185,7 @@ private function populateDocument($document, $object, $fieldMapping, $prefix = '
$type = $mapping['type'];
$value = $this->fieldEvaluator->getValue($object, $mapping['field']);

if ($type !== Field::TYPE_STRING && $type !== Field::TYPE_ARRAY) {
if (Field::TYPE_STRING !== $type && Field::TYPE_ARRAY !== $type) {
$value = $this->converterManager->convert($value, $type);

if (is_null($value)) {
Expand All @@ -197,7 +197,7 @@ private function populateDocument($document, $object, $fieldMapping, $prefix = '
}
}

if ($value !== null && false === is_scalar($value) && false === is_array($value)) {
if (null !== $value && false === is_scalar($value) && false === is_array($value)) {
throw new \InvalidArgumentException(
sprintf(
'Search field "%s" resolved to not supported type "%s". Only scalar (single) or array values can be indexed.',
Expand All @@ -207,7 +207,7 @@ private function populateDocument($document, $object, $fieldMapping, $prefix = '
);
}

if ($mapping['type'] !== 'complex') {
if ('complex' !== $mapping['type']) {
$document->addField(
$this->factory->createField(
$prefix . $fieldName,
Expand Down
2 changes: 2 additions & 0 deletions Search/QueryHit.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
class QueryHit implements \JsonSerializable
{
protected $document;

protected $score;

protected $id;

/**
Expand Down
2 changes: 2 additions & 0 deletions Search/Reindex/Provider/DoctrineOrmProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public function provide($classFqn, $offset, $maxResults)

return $this->sliceEntities($offset, $maxResults);
}

$queryBuilder = $result;
}

$queryBuilder->setFirstResult($offset);
Expand Down
5 changes: 5 additions & 0 deletions Search/SearchEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
class SearchEvents
{
const SEARCH = 'massive_search.search';

const HIT = 'massive_search.hit';

const PRE_INDEX = 'massive_search.pre_index';

const INDEX_REBUILD = 'massive_search.index_rebuild';

const INDEX = 'massive_search.index';

const DEINDEX = 'massive_search.deindex';
}
1 change: 1 addition & 0 deletions Search/SearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SearchQuery
{
// constants for search order
const SORT_ASC = 'asc';

const SORT_DESC = 'desc';

/**
Expand Down
6 changes: 6 additions & 0 deletions Tests/Resources/TestBundle/EntityDist/Car.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
class Car
{
public $id;

public $title;

public $body;

public $numberOfWheels;

public $cost;

public $date;

public $image;
}
3 changes: 3 additions & 0 deletions Tests/Resources/TestBundle/EntityDist/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
class Contact
{
public $id;

public $title;

public $emails;

public $addresses;
}
3 changes: 3 additions & 0 deletions Tests/Resources/TestBundle/EventSubscriber/TestSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
class TestSubscriber implements EventSubscriberInterface
{
public $hitDocument;

public $documentReflection;

public $nbHits = 0;

public $preIndexDocument;

public $preIndexMetadata;

public static function getSubscribedEvents()
Expand Down
6 changes: 6 additions & 0 deletions Tests/Resources/TestBundle/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@
class Product
{
public $id;

public $title;

public $body;

public $date;

public $url;

public $locale;

public $image;

public function getId()
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Search/Metadata/ClassMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function setUp()
}

/**
* @expectedException InvalidArgumentException
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Context name "foo_context" has already been registered
*/
public function testAddIndexExisting()
Expand Down
1 change: 0 additions & 1 deletion Tests/Unit/Search/Metadata/FieldEvaluatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Massive\Bundle\SearchBundle\Search\ObjectToDocumentConverter;
use Massive\Bundle\SearchBundle\Tests\Resources\TestBundle\Product;
use Prophecy\Argument;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

class FieldEvaluatorTest extends \PHPUnit_Framework_TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping\ClassMetadata as OrmClassMetadata;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Massive\Bundle\SearchBundle\Search\Metadata\ClassMetadata as SearchClassMetadata;
use Massive\Bundle\SearchBundle\Search\Reindex\Provider\DoctrineOrmProvider;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Search/SearchManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function testIndexNonObject()
}

/**
* @expectedException Massive\Bundle\SearchBundle\Search\Exception\MetadataNotFoundException
* @expectedException \Massive\Bundle\SearchBundle\Search\Exception\MetadataNotFoundException
* @expectedExceptionMessage There is no search mapping
*/
public function testIndexNoMetadata()
Expand Down
2 changes: 1 addition & 1 deletion Tests/travis.php.ini
Original file line number Diff line number Diff line change
@@ -1 +1 @@
memory_limit = 2048M
memory_limit = 4096M
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

"zendframework/zend-stdlib": "2.3.1 as 2.0.0rc5",
"zendframework/zendsearch": "2.*@dev",
"elasticsearch/elasticsearch": "^2.1",
"elasticsearch/elasticsearch": "^2.1||^6.0",
"symfony-cmf/testing": "^1.3",
"symfony/symfony": "~2.7||~3.0",
"matthiasnoback/symfony-dependency-injection-test": "0.7.*",
Expand Down
Loading