【问题标题】:Implementing smiliar_text or Levenshtein query实现 smiliar_text 或 Levenshtein 查询
【发布时间】:2017-10-27 22:36:34
【问题描述】:

我试图查询更智能的搜索结果,我在网上查看了 Leveshtein 和 similiar_text,但我相信 Leveshtein 算法是最好的选择,我如何在我的查询中实现 LEvenshtein 的算法?我在magento上找不到任何好的资源,甚至在attributeSelect上都找不到这个函数,这是我的初始代码。

function queryBuy($string){
    $items = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToSelect('name')
            ->addFieldToFilter(array(
                        array('attribute'=>'name','like'=> "%".$string."%"),
    ));

我应该使用原始 SQL 吗? magento 有什么方法可以用吗?

【问题讨论】:

标签: php mysql magento magento-1.9


【解决方案1】:

这样试试

$items = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToSelect('name')
            ->addAttributeToFilter('name',
                        array('like'=> "% ".$string." %") //spaces on each side
    );

您也可以查看this answer

【讨论】:

    【解决方案2】:

    您可以使用

    更改集合查询的任何部分
    $collection->getSelect()
    

    示例

    $collection->getSelect()->where("some field LIKE %expression%"
    

    【讨论】:

      猜你喜欢
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      • 2017-09-23
      • 2013-12-27
      • 1970-01-01
      • 2017-04-13
      相关资源
      最近更新 更多