0

im trying to query a smarter search result, i checked online about Leveshtein and similiar_text but i believe Leveshtein algorithm is the best optionm how could i implement in my query the algorithm of LEvenshtein? I cant find any good resource on magento or even using this function on the attributeSelect, here is my initial code.

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

Should i make in Raw SQL? Does magento have any method available where i could use it?

Info E
  • 147
  • 1
  • 13
  • Related: https://stackoverflow.com/questions/13909885/how-to-add-levenshtein-function-in-mysql?noredirect=1&lq=1 – Barmar Oct 27 '17 at 23:01

2 Answers2

0

try it like this

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

you can also check this answer

Piyush
  • 457
  • 7
  • 18
0

You can change any part of collection query with

$collection->getSelect()

Example

$collection->getSelect()->where("some field LIKE %expression%"
Vladimir Samsonov
  • 1,344
  • 2
  • 11
  • 18