-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search multi indexes for multi-language results #227
Comments
I had kind of the same problem but with projects instead of articles. I just made one index, in your case this would be called "article". Then the hard part, mapping your elastica search results to the model (since you got a custom id, you got to add a custom mapper). Extend the existing mapper class and add the following method: protected function findByIdentifiers(array $identifierValues, $hydrate)
{
if (empty($identifierValues)) {
return array();
}
foreach($identifierValues as $key => $value){
$identifierValues[$key] = current(explode("_", $value));
}
$hydrationMode = $hydrate ? Query::HYDRATE_OBJECT : Query::HYDRATE_ARRAY;
$qb = $this->registry
->getManagerForClass($this->objectClass)
->getRepository($this->objectClass)
->createQueryBuilder('o');
/* @var $qb \Doctrine\ORM\QueryBuilder */
$qb->where($qb->expr()->in('o.'.$this->options['identifier'], ':values'))
->setParameter('values', $identifierValues);
return $qb->getQuery()->setHydrationMode($hydrationMode)->execute();
} This will take the array with result-identifiers, and cut the _language from them so you have an array of article-id's. You then add a service for this: article.search.elastica_to_model_transformer:
class: Article
arguments: [@doctrine, ArticleBundle\Entity\Article, [identifier: id, hydrate: true]] and put the following in your search-config: persistence:
elastica_to_model_transformer:
service: article.search.elastica_to_model_transformer You can then search for articles in multiple languages. |
is there a simple way to do this ? In ES, you can search on multiples indexes /types at same time. |
Would be cool to have some kind of pointer about the way to go... |
+1 on this, better solution for searching translatable entities would be much appriciated |
+1, wait better solution |
+1, Still no solution here? |
The problem of working with a custom provider, is that the listener is not working anymore. A better solution would be to write a custom |
Hi, Here's a part of my solution: use Elastica\Request as ElasticaRequest;
//...
$userQuery = "bob";
$client = $this->container->get('fos_elastica.client');
$query = array(
'query' => array(
'query_string' => array(
'query' => $userQuery,
)
),
'from' => '6', //optional (default 0)
'size' => '5' //optional (default 10)
);
$results = $client->request('/myIndex/_search', ElasticaRequest::GET, $query);
$results->getData(); //Elasticsearch JSON response Further more reading : http://elastica.io/examples/ |
i have use nested to translations like that come directly from the entity :
result { |
I've created a multi-lingual website with Symfony2 using the (Gedmo) Translatable behavior extension for Doctrine2. This works fine but now i'm looking for a way to use the ElasticaBundle to create a nice searchoption. I want German users to search in the German-translation but also in the English translation.
At the moment i'm trying to use separate indexes for each language. My config.yml looks like this:
This works fine if you want to search through one index but searching two indexes seems not possible with this bundle or am I wrong?
Is there a way to do this? Any help will be appreciated!
Rick
The text was updated successfully, but these errors were encountered: