I've got symfony2 project set up with elastica via FOSElasticaBundle. I've got indexing set up for User document(Mongo) using basic settings. Now when I do a search for users I'd like that search to be prioritized by specified user's followers (to be returned of the top of search). The followers are stored in separate document (structure: id, follower_id, folowee_id). What would be the best approach to do so?
Asked
Active
Viewed 148 times
1 Answers
0
Ok, so after research it seems that only way is to first make a find on follow document, then eventually merge results with find on user. First added indexing on follow entity like:
follow:
mappings:
follower: ~
followee :
type : object
properties :
id : ~
Now I can easily make a search with followee id and followers text string (prefix):
$baseQuery = new \Elastica\Query\Prefix();
$baseQuery->setPrefix('follower', $text);
$filter = new \Elastica\Filter\Term();
$filter->setTerm('id', $id);
$subquery = new \Elastica\Query\Filtered($baseQuery, $filter);
$query = new \Elastica\Query();
$query->setSize(10);
$query->setQuery($subquery);
$results = $service->find($query);

impiix
- 46
- 6