【问题标题】:How to search multiple words title in different combinations如何以不同的组合搜索多个单词标题
【发布时间】:2014-12-16 06:01:14
【问题描述】:

我的职位类似于“销售和业务发展经理”。 当我搜索这个词时,我想要这样的结果:

条件1:首先显示完整的搜索词职位结果。

条件2:显示3个词的组合结果为第二优先。

条件3:将2个单词组合结果显示为第三优先

如何在 php mysql 中实现这个逻辑。以及如何根据条件对结果数据进行排序

我试过这样

 $str='Sales and Business Development Manager';
    $arr=explode(" ",$str);
    $cnt=count($arr);
    $search1=" where job title like '%$str%'";
    if($cnt>3)
     {
      $word1=$arr[0]." ".$arr[1]." ".$arr[2];
      $word2=$arr[1]." ".$arr[2]." ".$arr[3];
      $word3=$arr[2]." ".$arr[3]." ".$arr[0];
      $word4=$arr[3]." ".$arr[0]." ".$arr[1];
      $word5=$arr[2]." ".$arr[0]." ".$arr[1];
      $word6=$arr[1]." ".$arr[0]." ".$arr[2];
      $search2.=" or job title like '%$word1%" or job title like '%$word2%' or job title like   '%$word3%' or job title like '%$word4%' or job title like '%$word5%';
     }
     $qry=mysql_query("select * from jobs $search1 $search2"); 

我也在使用全文搜索。 请告诉我如何实现这种类型的逻辑。根据搜索词搜索和排序数据。

【问题讨论】:

标签: php mysql


【解决方案1】:

你可以试试这个。我在给出的示例代码中放入了一些 cmets。

代码:

$str='Sales and Business Development Manager';
$arr=explode(" ",$str);
$cnt=count($arr);
$search1=" WHERE job title LIKE '%$str%'"; /* SHOULD FIX THAT job title COLUMN NAME */

$search2="";

  for($x=0;$x<=$cnt;$x++){ /* LOOP THE RESULT OF THE EXPLODE */

    $search2=$search2." OR title LIKE '%".$arr[$x]."%'"; /* PUT THEM ALL TOGETHER IN A SINGLE VARIABLE */

  }

$qry=mysql_query("SELECT * FROM jobs $search1 $search2");  /* YOUR QUERY */

评论:

  • 请替换 job title 列名。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-29
    • 2017-05-05
    • 2015-06-05
    • 2021-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多