How to use mapper to execute SQL?

55 views
Skip to first unread message

Gosforth

unread,
Oct 19, 2017, 3:52:53 PM10/19/17
to Fat-Free Framework
I have code:

$this->db = \Registry::get('DB');
$mapper = new \DB\SQL\Mapper($this->db,'table');

Then SQL:

SELECT * FROM table WHERE MATCH (name, code) AGAINST ('some text' IN BOOLEAN MODE);

How to execute this SQL?

Regards




ikkez

unread,
Oct 19, 2017, 4:56:02 PM10/19/17
to f3-fra...@googlegroups.com
Hi. Just assign this as a filter

$this->db = \Registry::get('DB');
$mapper
= new \DB\SQL\Mapper($this->db,'table');

$text
= 'some text';
$mapper
->find(["MATCH (name,code) AGAINST (:search IN BOOLEAN MODE)", ':search' => $text ]);

If you also want to sort the results by relevance, you need to add this match as adhoc field like this:

$mapper->relevance = "MATCH (name,code) AGAINST (:search1 IN BOOLEAN MODE)";
$mapper
->find(["MATCH (name,code) AGAINST (:search2 IN BOOLEAN MODE)", ':search1' => $text, ':search2' => $text ], ['order'=>'relevance desc']);

now cross the fingers and hope it works ;)

Gosforth

unread,
Oct 20, 2017, 2:29:59 PM10/20/17
to Fat-Free Framework
Thank you Ikkez!!


Reply all
Reply to author
Forward
0 new messages