简体   繁体   中英

Select with MATCH AGAINST breaks in newer Zend Framework

We've been building an application against Zend Framework 1.12.7 - one of our developers installed a slightly newer version (1.12.9) and the behaviour of Zend_Db_Table_Select (or Zend_Db_Select) has changed a bit and is breaking one of our searches.

Specifically, we had:

$select->from("search", array(
        "*",
        "bodyScore" => $dbAdapter->quoteInto("MATCH(body) AGAINST (?)", $search),
        "headingsScore" => $dbAdapter->quoteInto("MATCH(headings) AGAINST (?)", $search),
        "titleScore" => $dbAdapter->quoteInto("MATCH(title) AGAINST (?)", $search),
    ));

$search is a string, $select is a Zend_Db_Table_Select, and $dbAdapter is a Zend_Db_Adapter_Pdo_Mysql

In 1.12.7, this would generate the following query:

SELECT 
  `search`.*, 
  MATCH(body) AGAINST ('neoral') AS `bodyScore`, 
  MATCH(headings) AGAINST ('neoral') AS `headingsScore`, 
  MATCH(title) AGAINST ('neoral') AS `titleScore` FROM `search` ...

In 1.12.9, it generates: SELECT search .*, search . MATCH(body) AGAINST ('neoral') AS bodyScore , search . MATCH(headings) AGAINST ('neoral') AS headingsScore , search . MATCH(title) AGAINST ('neoral') AS titleScore FROM search ...

I understand the principle behind this and that it is more correct syntax in general. However, for this particular query it results in column MATCH(body) AGAINST ('neoral') not found in "field_list" errors.

What would be the (hopefully more correct way) of constructing my query so that it works in 1.12.9?

In this case you would use Zend_Db_Expr . For instance in your code:

$select->from("search", array(
    "*",
    "bodyScore" => new Zend_Db_Expr($dbAdapter->quoteInto("MATCH(body) AGAINST (?)", $search)),
    "headingsScore" => new Zend_Db_Expr($dbAdapter->quoteInto("MATCH(headings) AGAINST (?)", $search)),
    "titleScore" => new Zend_Db_Expr($dbAdapter->quoteInto("MATCH(title) AGAINST (?)", $search)),
));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM