[英]How to do a MATCH AGAINST with tableGateway in Zend Framework 2?
I need to do a [MATCH ( title, description ) AGAINST ( 'text' )] in a ZF2 application using tableGateway like in the ZF2 skeleton application.我需要在 ZF2 应用程序中使用 tableGateway 执行 [MATCH (title, description) AGAINST ('text')],就像在 ZF2 骨架应用程序中一样。
I had high hopes when tried with \\Zend\\Db\\Sql\\Where , but couldn't find any way.尝试使用 \\Zend\\Db\\Sql\\Where 时,我寄予厚望,但找不到任何方法。 Any advices or examples on how to do that ?
关于如何做到这一点的任何建议或示例?
My first contribution to stackoverflow. 我对stackoverflow的第一个贡献。
You can do it this way in ZF2 TableGateway: 你可以在ZF2 TableGateway中这样做:
$rowSet = $this->someTableGateway->select(function (Select $select) {
$select->columns(array(new \Zend\Db\Sql\Expression("MATCH(column) AGAINST('Query') AS score")))
->where("MATCH(column) AGAINST('\"Query\"' in boolean mode)")
->order('score DESC');
});
var_dump($rowSet->toArray());
I also didn't find any way to use MATCH AGAINST, so I guess you can use LIKE instead : 我也没有找到任何使用MATCH AGAINST的方法,所以我想你可以使用LIKE代替:
$rowset = $someTable->select(function (Select $select) {
$select->where->like('CONCAT(title, description)', '%text%');
});
It seems there is no possible way to do MATCH AGAINST with tableGateway. 似乎没有办法用tableGateway做MATCH AGAINST。 Only solution is by doing it using the "default" way by using \\Zend\\Db\\Adapter\\Adapter -> query($qry)
只有通过使用\\ Zend \\ Db \\ Adapter \\ Adapter - > query($ qry)使用“默认”方式进行解决方案
How about this? 这个怎么样?
$db->select()->from('your_table')
->where('MATCH (`title, description`) AGAINST (?)', $text)
And it also works in boolean mode: 它也适用于布尔模式:
$db->select()->from('your_table')
->where('MATCH (`title, description`) AGAINST (? IN BOOLEAN MODE)', $text)
You should use the expression($expression, $parameters) from the Zend\\Db\\Sql\\Where (Predicate/PredicateSet) API. 您应该使用Zend \\ Db \\ Sql \\ Where(Predicate / PredicateSet)API中的表达式($ expression,$ parameters)。
https://framework.zend.com/manual/2.2/en/modules/zend.db.sql.html#expression-expression-parameter https://framework.zend.com/manual/2.2/en/modules/zend.db.sql.html#expression-expression-parameter
For exemple : 举个例子 :
$select->where->expression(" MATCH(title, description) AGAINST( ? ))", $text);
这对我有用。
$select->where("MATCH(title, description) AGAINST ('{$text}' IN NATURAL LANGUAGE MODE)");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.