Sunday 15 March 2015

symfony2 - creating custom repository fos elastic search -



symfony2 - creating custom repository fos elastic search -

im trying create simple custom repository in order understand how elastic search repository works. documentation pretty straight forwards still dont understand how works, im getting error ´the service definition "fos_elastica.manager" not exist.´. far think problem in controller since dont understand how intialize them, know if im in right way in configuration of custom repository , simple query made.

im getting error configuration whenever seek create search,

service definition "fos_elastica.manager" not exist.

this configuration far: //app/config.yml

fos_elastica: clients: default: { host: localhost, port: 9200 } indexes: sava: client: default types: blog: mappings: id: type: integer body : ~ title : ~ tags: ~ persistence: identifier: id driver: orm model: sava\blogbundle\entity\tblpost finder: ~ provider: ~ listener: ~ repository: sava\blogbundle\searchrepository\tblpostrepository

this controller action:

namespace sava\blogbundle\controller; //custom querys utilize fos\elasticabundle\manager\repositorymanager; utilize fos\elasticabundle\repository; // utilize symfony\component\dependencyinjection\containerbuilder; class tblpostcontroller extends controller { public function getpostaction(request $request) { $container = new containerbuilder(); $repositorymanager = $container->get('fos_elastica.manager'); $repository = $repositorymanager->getrepository('blogbundle:tblpost'); $items2 = $repository->matchexact($categoria,$searchquery ); homecoming $this->render('savablogbundle:tblpost:index.html.twig', array( 'results' => $items2, 'entities' => $items2 )); }

this post repository:

<?php namespace sava\blogbundle\entity; utilize doctrine\orm\mapping orm; utilize fos\elasticabundle\repository; class tblpostrepository extends fos\elasticabundle\repository { public function matchexact($campo, $searchquery) { //$finder = $this->get('fos_elastica.finder.sava.blog'); $query = new query(); if($searchquery=='') { $innerquery = new query\matchall(); } else{ $innerquery = new query\match(); $innerquery->setfield( $campo , array('query' => $searchquery)); } $query->setquery($innerquery); $query->setsize(1000000); $query->setexplain(true); homecoming $this->find($query); } }

and since im using yml tblpost.orm, did generate entities.

whenever postaction throws me cant find container, , dont see illustration in how intiaze it, how create custom query?

edit 1:

so changed this:

$container = new containerbuilder(); $repositorymanager = $container->get('fos_elastica.manager');

to this:

$elastica = $this->container->get('fos_elastica.manager');// single entry point, no fancy services $searchrepository = $elastica->getrepository('savablogbundle:tblpostrepository');// single type

and im getting error:

no search finder configured sava\blogbundle\entity\tblpostrepository

i've had same issue, soultion instead of savablogbundle:tblpostrepository should utilize entity, example:

$searchrepository = $elastica->getrepository('savablogbundle:tblpost`)

symfony2 elastica foselasticabundle

No comments:

Post a Comment