Closed hanzx closed 8 years ago
can you provide your solr-mapping?
For ca key :
/**
* Category names
* @var Category[]
*
* @Solr\Field(name="ca", type="strings", getter="getName")
* @ORM\OneToMany(targetEntity="ArtikulBundle\Entity\Solr\Category", mappedBy="categories", cascade={"persist"})
*
*/
private $ca;
Category:
class Category
{
/**
* @ORM\Column(type="string")
*/
protected $name;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
}
Your mapping looks good. Maybe your data is inconsistent and the doctrine-hydrator can't find the target entity.
Make sure your relation between Product
and Category
is persisted properly.
when I use command "doctrine:schema:update --force" ->
[Doctrine\ORM\Mapping\MappingException]
Class "ArtikulBundle\Entity\Solr\Category" is not a valid entity or mapped
super class.
It works only when I add annotations to class (/**
In your example is class without annotations.
class Tag
{
/**
* @return string
*/
public function getName()
{
return $this->name;
}
}
Have you some your code for inspiration ?
You configure with @ORM\OneToMany(targetEntity="ArtikulBundle\Entity\Solr\Category", mappedBy="categories", cascade={"persist"})
a db-relation to Category
, this means Category
must be an entity too.
I have
* Class Category
* @package ArtikulBundle\Entity\Solr
*
* @ORM\Entity
* @ORM\Table(name="category")
*/
class Category
{
/**
* @var
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $name;
/**
* @ORM\ManyToOne(targetEntity="ArtikulBundle\Entity\Solr\Product",inversedBy="ca")
*
*/
still return empty ca,
-ca: ArrayCollection {#599 ▼
-elements: []
}
function hydrate in ValueHydrator class, variable $document contain my key 'ca' = $property with $value ['name1','name2'] and function isComplexValue stop it, because it is array; when i did debugging : function query in Solr.php $document contain key 'ca' with value ['name1','name2'];
$entities = array();
foreach ($response as $document) {
$entities[] = $this->entityMapper->toEntity($document, $entity);
}
if ($this->isComplexValue($property, $value, $metaInformation)) {
continue;
}
{"response":{"numFound":918075,"start":0,"docs":[{"id":"0001887-88698229149","ca":["Náplně a tonery - originální"],"cai":[796,758,747,659],"version":1541700906018406400}]}}
I am desperate :)
I know the hydration is a bit confusing:
2.1. is the reason why your response values ['name1','name2']
are not mapped. To solve your problem I need your data. But please check in https://github.com/floriansemm/SolrBundle/blob/master/Doctrine/Hydration/DoctrineHydrator.php#L48 if your product-entity ca-property has correct values
oh, I know what I do wrong. I had different function logic,,,I have empty tables. I need only data from solr, not have to data saved in mysql db. It all works. I need get only multivalued attribute from solr without use mysql, i dont need this values saved in mysql, if you understand me.It is posible ? Sorry my english is bad:) Can I work with facets in this bundle? How ?
You can tell the bundle which data it should use: mysql or Solr https://github.com/floriansemm/SolrBundle#configure-hydrationmodes
Solr uses the Solarium-Client which supports Faced Field
hello :) i understand how ii works, but.... when i use mode HYDRATE_DOCTRINE, everything works, i have data in mysql and my attribute ca return multivalues, nice!!! but when i use mode HYDRATE_INDEX, ca in solr is multivalue, query return result for attribute ca null... this is my problem, i need only solr data, all attriburtes in solr schema with multivalued are returned as null.
you should get your ca values in mode HYDRATE_INDEX. sounds like a bug...
this is my problem from start:)can you check it ? thx
I think my last commit 8714d20 solves your problem
:( return null for multivalue attribute in solr
public function findById($id)
{
$query = $this->solr->createQuery($this->entity);
$query->setHydrationMode(HydrationModes::HYDRATE_INDEX);
$query->addSearchTerm('id', '0000284-34');//0000284-34 ; 0002355-107299869
$result = $query->getResult();
return $result;
}
try this:
public function findById($id)
{
$query = $this->solr->createQuery($this->entity);
$query->setHydrationMode(HydrationModes::HYDRATE_INDEX);
$query->addSearchTerm('id', 'category_0000284-34');//0000284-34 ; 0002355-107299869
$result = $query->getResult();
return $result;
}
in https://github.com/floriansemm/SolrBundle/blob/master/Repository/Repository.php#L46 you can see how the base-repository builds a search-query.
$repo = $this->get('solr.client')->getRepository('AppBundle:Product');
$prod = $repo->find('0000396-1341');
return null.
dump($query) in Repository->find($id); ??product_0000396-1341, is it okey?
#filterControlCharacters: true
#fields: array:1 [▼
"id" => "product_0000396-1341"
]
}
findAll() not work too, only work findBy(['id'=>'0000396-1341']), but not show multivalues
Hello, i have a problem. Solrbundle response not return data for keys [ca,cai and other multivalues]. Thanks.
Query:
Solr response
Solr bundle response: