0
私はfoselasticaを使用していますが、エラーが表示されます"すべてのElastica結果(7)に対応するDoctrineオブジェクトが見つかりません(7)ID:52,51,50,48,49 、47、46" は、リポジトリ内の削除クエリの後、しかし、クエリは、MySQLデータベースに削除しない:私は教義を使用する場合Symfony ElasticSearchはリポジトリ削除クエリの後に同期しません
class CandidatesRepository extends EntityRepository
{
public function candidatesFileimportDelete($id)
{
$q = $this->createQueryBuilder('c')->delete()
->where('c.fileImportId = :id')->setParameter('id', $id);
return $q->getQuery()->getResult();
}
}
を削除するには、同期を行い、すべての候補者は、ES
から削除されます$candidates = $this->getDoctrine()
->getRepository(Candidates::class)
->findAll();
foreach($candidates as $candidate){
$em = $this->getDoctrine()->getManager();
$em->remove($candidate);
$em->flush();
}
コードサンプル:
エンティティ
/**
* @ORM\Entity
* @ORM\Table(name="candidates_user")
* @ORM\Entity(repositoryClass="CandidatesBundle\Entity\Repository\CandidatesRepository")
*/
class Candidates
{
// filled with privatre properties and public getters and setters
}
config.yml
fos_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
candidates:
types:
candidates:
mappings:
id: { type: integer }
name: { type: string }
job: { type: string }
approached: {type: integer}
level: {type: string }
skills: {type: string}
email: {type: string}
mobile: {type: string}
city: {type: string}
province: {type: string}
country: {type: string}
linkedinUrl: {type: string}
addedCompany: {type: string}
note: {type: string}
dateAdded: {type: date}
deleted: {type: integer }
dateDeleted: {type: date}
platform: {type: string}
fileImportId: {type: integer}
persistence:
driver: orm
model: CandidatesBundle\Entity\Candidates
provider:
batch_size: 10
debug_logging: false
listener:
is_indexable_callback: "isSearchable"
insert: true
update: true
delete: true
finder: ~
repository: CandidatesBundle\Entity\Repository\CandidatesRepository
候補
/**
* Search all active candidates
*/
public function getAllCandidates($request, $showDeleted = false)
{
$finder = $this->container->get('fos_elastica.finder.candidates.candidates');
$boolQuery = new \Elastica\Query\BoolQuery();
if (!empty($request->get('s')) && $request->get('c')) {
if (in_array($request->get('c'), self::SEARCH_CATEGORIES, true)) {
$boolQuery->addMust(
$this->setQueryString(array($request->get('c')), $request->get('s'))
);
}
}
if ($showDeleted == false) {
$boolQuery->addMust(
$this->setTerm('deleted', array(0))
);
}
$query = $this->setSort($boolQuery, array('dateAdded' => array('order' => 'asc')));
if (!empty($request->get('sort')) && $request->get('cat')) {
if (in_array($request->get('cat'), self::CAT, true) &&
in_array($request->get('sort'), self::SORT)) {
$query = $this->setSort($boolQuery, array($request->get('cat') => array('order' => $request->get('sort'))));
}
}
$candidates = $finder->find($query, 3000);
return $candidates;
}
必要なバンドル収集するために私の弾性サービスの一部:
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-migrations-bundle": "1.2",
"doctrine/orm": "^2.5",
"friendsofsymfony/elastica-bundle": "^4.0",
"friendsofsymfony/user-bundle": "~2.0",
"gedmo/doctrine-extensions": "^2.4",
"incenteev/composer-parameter-handler": "^2.0",
"liuggio/excelbundle": "^2.1",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^3.0.2",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.3.10",
"symfony/symfony": "3.3.*",
"twig/twig": "^1.0||^2.0"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^2.3",
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0"
},
を10
はいできます。私はそれをテストし、多分私は削除クエリの後に手動でイベントをトリガすることができます –