The simple way is to just:
return array('hits'=>$hits, 'query'=>$query);
And let the upstream code handle the process.
I've not tried it in a few years but you can also do it via a join - the
simplest approach in Symfony would be to use DBFinder.
In essence $hits needs to represent a virtual table where the ID = pk &
another field 'sortOrder' represents the order to return the results in.
This would allow something like:
$results = DbFinder::from('myTable')->
join('myTableLuceneIndex')->
whereIn('v.id', $pks)->
find();
Although as DBFinder allows your own functions to be used this can be
simplified to:
$results = DbFinder::from('myTable')->
whereInLuceneIndex($queryString)->
orderByLuceneRelavence($queryString)->
find();
DBFinder can be found: http://www.symfony-project.org/plugins/DbFinderPlugin
and the above is general pseudo code - you'd have to dig into the details
yourself unless somebody who's more familiar with DBFinder pipes up :)
-----Original Message-----
From: [email protected] [mailto:[email protected]]
On Behalf Of Thibault Jouannic
Sent: 01 May 2009 14:22
To: symfony users
Subject: [symfony-users] Zend serch and sorting by score
Hi group !
On my symfony website, I've build a search engine following the jobeet
tutorial (day 17). Everything's fine, except one thing. The Zend
Lucene engine is kind enough to sort its results by relevance.
However, this order is lost when I build the doctrine query :
$hits = $this->getLuceneIndex()->find($queryString);
$pks = array();
foreach($hits as $hit)
$pks[] = $hit->pk;
$query->whereIn('v.id', $pks);
return $query;
Is there an easy way I could tell mysql and / or doctrine to keep the
same order in the query's results as in the IN clause ? If no, does
anybody as an idea about how could I achieve the same result ?
Thanks
Thibault.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---