Skip to content
This repository has been archived by the owner on Apr 22, 2022. It is now read-only.

Fixes entity not being removed from ES #117

Open
wants to merge 48 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
a386d19
Fixed consistency
fprochazka Sep 11, 2014
8c84e7f
Implemented DependentMappingDriver
fprochazka Sep 11, 2014
aaac049
Implemented DependentMappingDriver
fprochazka Sep 11, 2014
2047e6a
Merge branch 'patch-3' into devel
fprochazka Sep 11, 2014
330362c
phpdoc
fprochazka Sep 16, 2014
5ec307d
Virtual properties
fprochazka Sep 16, 2014
489b9de
AnnotationDriver refactoring
fprochazka Oct 2, 2014
d560020
AnnotationDriver refactoring
fprochazka Oct 2, 2014
57b8e8d
Fixed caching of ClassMetadata::methodMappings
fprochazka Oct 2, 2014
4ad5584
ElasticCompletionField
mkoubik Nov 22, 2014
b63be19
drop dead code
fprochazka Dec 26, 2014
b4d452b
Drop broken AnnotationDriver
fprochazka Dec 29, 2014
cd2a48a
refactor exceptions
fprochazka Dec 29, 2014
d1d560d
Fixed JMSSerializer
fprochazka Dec 29, 2014
b614546
dead code AnnotationSerializer
fprochazka Dec 29, 2014
2f5c882
introduced ChainSerializer
fprochazka Dec 29, 2014
df012e2
Added default optional SearchableListener & Searchable interface
fprochazka Dec 29, 2014
301c7ef
Fixed search events
fprochazka Dec 29, 2014
33984fb
Refactored mapping; Introduced NeonDriver; Introduced decorator Depen…
fprochazka Dec 29, 2014
8e4addf
Introduce SchemaManager
fprochazka Dec 29, 2014
699cab2
Refactored SearchManager & UnitOfWork
fprochazka Dec 29, 2014
75e997c
Refactored Query
fprochazka Dec 29, 2014
c6a7b3d
Refactored EntityRepository
fprochazka Dec 29, 2014
0f51c3f
composer: require-dev includes jms/serializer, elastica and neon
fprochazka Dec 29, 2014
74f7bf6
fixed exceptions autoloading
fprochazka Dec 29, 2014
30cc63d
fixed type error
fprochazka Dec 29, 2014
4560101
Fixed cannot use IndexMetadata as array
fprochazka Dec 29, 2014
5d15146
Fixed loading metadata in NeonDriver
fprochazka Dec 29, 2014
8ae9174
Fixed sections inheritance; todo remove nette\di
fprochazka Dec 29, 2014
892155e
Rename SearchableListener to Tools\OrmSearchableListener
fprochazka Dec 29, 2014
336d737
readme fixed
fprochazka Dec 29, 2014
378fc26
Expect ORM\Event not Search\Event in OrmSearchableListener
fprochazka Dec 29, 2014
60cf953
Fixed race condition when creating index aliases
mkoubik Jan 9, 2015
82b95e8
Merge pull request #1 from fprochazka/fix-create-index
fprochazka Jan 9, 2015
0789622
Autofix type property settings to underscore
fprochazka Apr 10, 2015
a6a9824
Experimental: ClassMetadata->riverImplementation
fprochazka Apr 10, 2015
0a955e0
Fixed serialization of riverImplementation in ClassMetadata
fprochazka Apr 14, 2015
afab25d
Fixed deep clone of ClassMetadata
fprochazka Apr 14, 2015
37f0b7a
Fixed loading '0' value in metadata
fprochazka Apr 14, 2015
7b5b376
Use ClassUtils::getRealClass in UnitOfWork
fprochazka May 15, 2015
cd29a19
Fixed usage of ClassUtils::getRealClass in UoW
fprochazka May 21, 2015
34eeba8
phpdoc
fprochazka Jul 9, 2015
1de14f0
Schedule getters on UnitOfWork
fprochazka Jul 9, 2015
c6d0808
Allow to configure index prefixing
fprochazka Jul 19, 2015
f99f6bf
ChainSerializer: if a serializer serializes type T, it also serialize…
mkoubik Jul 21, 2015
1dcec05
NeonDriver: one mapping can be used also for inherited entities via '…
mkoubik Jul 21, 2015
db46613
Merge pull request #4 from mkoubik/inheritance
fprochazka Jul 31, 2015
85a431e
Fixes the problem with entities not being removed from ES
Nov 1, 2015
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
47 changes: 11 additions & 36 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ $searchManager = new Doctrine\Search\SearchManager(
```

## Mappings ##
Basic entity mappings for index and type generation can be annotated as shown in the following example. Mappings
can be rendered into a format suitable for automatically generating indexes and types using a build script
Basic entity mappings for index and type generation can be annotated as shown in the following example. Mappings
can be rendered into a format suitable for automatically generating indexes and types using a build script
(advanced setup required).
```php
<?php
Expand All @@ -64,7 +64,7 @@ use Doctrine\ORM\Mapping as ORM;
class Post
{
/**
* @ORM\Id
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @MAP\ElasticField(type="integer", includeInAll=false)
*/
Expand All @@ -81,7 +81,7 @@ class Post
* @MAP\ElasticField(type="string", includeInAll=true)
*/
private $content;

/**
* @MAP\ElasticField(name="tags", type="string", includeInAll=false, index="not_analyzed")
*/
Expand All @@ -92,37 +92,12 @@ class Post
```

## Indexing ##
Documents can be serialized for indexing currently in the following ways. If required an event listener can
Documents can be serialized for indexing currently in the following ways. If required an event listener can
be used with your ORM as shown in this example. If an event listener is not needed, entities can be persisted
or removed directly using the search manager.
```php
<?php
namespace Entities\Listener;

use Doctrine\ORM\Event\LifecycleEventArgs;
use Entities\Behaviour\SearchableEntityInterface;
The repository contains `OrmSearchableListener`, which can be used for this.

class SearchableListener implements
{
protected function getSearchManager() {
return $this->getDatabaseConnection('elasticsearch');
}

public function postPersist(LifecycleEventArgs $oArgs) {
$oEntity = $oArgs->getEntity();
if($oEntity instanceof SearchableEntityInterface) {
$this->getSearchManager()->persist($oEntity);
}
}

public function postRemove(LifecycleEventArgs $oArgs) {
$oEntity = $oArgs->getEntity();
if($oEntity instanceof SearchableEntityInterface) {
$this->getSearchManager()->remove($oEntity);
}
}
}
```

### CallbackSerializer ###
This approach simply expects a `toArray()` method on the entity, although this method be configured as required.
Expand All @@ -132,7 +107,7 @@ entities that need to be persisted to the search engine (see above example).
...
use Entities\Behaviour\SearchableEntityInterface

class Post implements SearchableEntityInterface
class Post implements SearchableEntityInterface
{
...
public function toArray() {
Expand All @@ -147,7 +122,7 @@ class Post implements SearchableEntityInterface
```

### JMS Serializer ###
You can alternatively use the advanced serialization power of the `JMS Serializer` to automatically handle
You can alternatively use the advanced serialization power of the `JMS Serializer` to automatically handle
serialization for you based on annotations such as those shown in this example.
```php
...
Expand All @@ -169,11 +144,11 @@ class Post implements SearchableEntityInterface
* @JMS\Groups({"public", "search"})
*/
private $title;

/**
* @ORM\Column(type="text")
* @MAP\ElasticField(type="string", includeInAll=true)
* @JMS\Expose
* @JMS\Expose
* @JMS\Groups({"public", "search"})
*/
private $content;
Expand All @@ -197,7 +172,7 @@ $hydrationQuery = $entityManager->createQueryBuilder()
->where('p.id IN (:ids)')
->orderBy('field')
->getQuery();

$query = $searchManager->createQuery()
->from('Entities\Post')
->searchWith(new Elastica\Query())
Expand Down
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@
"doctrine/common": ">=2.3.0"
},
"suggest": {
"ruflin/Elastica": "Elastica version correlating to your ElasticSearch installation is required."
"ruflin/Elastica": "Elastica version correlating to your ElasticSearch installation is required.",
"nette/neon": "Neon is a developer friendly format for config files, similar to YAML."
},
"require-dev": {
"doctrine/orm": "~2.4",
"jms/serializer": "~0.16",
"ruflin/elastica": "~1.3.0",
"nette/neon": "~2.2",
"phpunit/phpunit": "~4.2"
},
"autoload": {
"psr-0": {
"Doctrine\\Search": "lib/"
}
},
"classmap": [
"lib/Doctrine/Search/exceptions.php"
]
},
"autoload-dev": {
"psr-0": {
Expand Down
2 changes: 1 addition & 1 deletion demo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
echo PHP_EOL."*** Single lookup with no results ***".PHP_EOL;
try {
$user = $sm->find('Doctrine\Tests\Models\Comments\User', 'unknownid');
} catch (Doctrine\Search\Exception\NoResultException $exception) {
} catch (\Doctrine\Search\NoResultException $exception) {
print_r($exception->getMessage());
echo PHP_EOL;
}
Expand Down
43 changes: 30 additions & 13 deletions lib/Doctrine/Search/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ class Configuration
*/
private $attributes;

/**
* @param string $prefix
*/
public function setIndexPrefix($prefix)
{
$this->attributes['indexPrefix'] = $prefix;
}

/**
* @return string|NULL
*/
public function getIndexPrefix()
{
return isset($this->attributes['indexPrefix']) ? $this->attributes['indexPrefix'] : NULL;
}

/**
* Gets the cache driver implementation that is used for the mapping metadata.
* (Annotation is the default)
Expand All @@ -46,11 +62,11 @@ class Configuration
*/
public function getMetadataDriverImpl()
{
if (!isset($this->attributes['concreteMetadataDriver'])) {
$this->attributes['concreteMetadataDriver'] = $this->newDefaultAnnotationDriver();
if (!isset($this->attributes['metadataDriver'])) {
$this->attributes['metadataDriver'] = $this->newDefaultAnnotationDriver();
}

return $this->attributes['concreteMetadataDriver'];
return $this->attributes['metadataDriver'];
}

/**
Expand All @@ -60,7 +76,7 @@ public function getMetadataDriverImpl()
*/
public function setMetadataDriverImpl(MappingDriver $concreteDriver)
{
$this->attributes['concreteMetadataDriver'] = $concreteDriver;
$this->attributes['metadataDriver'] = $concreteDriver;
}

/**
Expand Down Expand Up @@ -94,9 +110,9 @@ public function getMetadataCacheImpl()
*/
public function newDefaultAnnotationDriver(array $paths = array())
{
$reader = new \Doctrine\Common\Annotations\AnnotationReader();

return new \Doctrine\Search\Mapping\Driver\AnnotationDriver($reader, $paths);
throw new NotImplementedException;
// $reader = new \Doctrine\Common\Annotations\AnnotationReader();
// return new \Doctrine\Search\Mapping\Driver\AnnotationDriver($reader, $paths);
}

/**
Expand Down Expand Up @@ -161,20 +177,21 @@ public function getEntitySerializer()
}

/**
* @param ObjectManager $entityManager
* @param ObjectManager $objectManager
*/
public function setEntityManager(ObjectManager $entityManager)
public function setObjectManager(ObjectManager $objectManager)
{
$this->attributes['entityManager'] = $entityManager;
$this->attributes['objectManager'] = $objectManager;
}

/**
* @return ObjectManager
*/
public function getEntityManager()
public function getObjectManager()
{
if (isset($this->attributes['entityManager'])) {
return $this->attributes['entityManager'];
if (isset($this->attributes['objectManager'])) {
return $this->attributes['objectManager'];
}
}

}
Loading