doulianqi3870 2014-04-06 18:10
浏览 50

PHP MySQL搜索查询 - 在搜索“mysearch”时如何查找“我的搜索”等结果?

I havent been able to find the answer to this, maybe I have overlooked it, but this is a very simple question:

I have a search module for Joomla/Virtuemart and I have 1 problem with the search results generated by this module.

When I type this search word "mysearch" I want it to find all results with words that are part of the search query, e.g. title: "This is my search" or "What a nice search"

How do I accomplish this with MySQL?

This is my working code:

$ab = explode(' ', $keyword);
  $ccc='';
          $ccc2='';
          foreach ($ab as $k)
          {
            if (!empty($k))
           {

          if($ccc==''){         
          $ccc.= " concat(product_name, customtitle) RLIKE '".$db->getEscaped($k)."' AND";
                }
                else{
           $ccc.= " concat(product_name, customtitle) RLIKE '".$db->getEscaped($k)."' AND";
                }

                    if($ccc2==''){
          $ccc2.= " product_sku RLIKE '".$db->getEscaped($k)."' AND";
                }
                else{
            $ccc2.= " product_sku RLIKE '".$db->getEscaped($k)."' AND";
                }


       }
       else { 
       $ccc2.= " product_sku RLIKE '0' AND";
       $ccc.= " concat(product_name, customtitle) RLIKE '0' AND";
       }
    }

$ccc = rtrim($ccc, "AND");  
$ccc2 = rtrim($ccc2, "AND");    




$q ="(SELECT p.virtuemart_product_id, l.product_name
 from #__virtuemart_products p join
      #__virtuemart_products_".VMLANG." l
      on p.virtuemart_product_id = l.virtuemart_product_id
 WHERE ".$ccc." AND
       p.published = '1'
 LIMIT 0,".$prods."
)
union (select p.virtuemart_product_id, l.product_name
 from #__virtuemart_products p join
      #__virtuemart_products_".VMLANG." l
      on p.virtuemart_product_id = l.virtuemart_product_id
 where ".$ccc2." and
       p.published = '1'
 LIMIT 0,".$prods.")";
  • 写回答

2条回答 默认 最新

  • dqndc26628 2014-04-06 18:16
    关注

    To the best of my knowledge....not possible with MySQL.

    If you want true fuzzy matching, you need a search system designed for it. The Lucene library is great for this and is used in some amazing OSS projects.

    Check out ElasticSearch and Solr.

    of the two I recommend ElasticSearch.

    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致