全文搜索引擎,多列,布尔模式

时间:2015-02-05 19:41:33

标签: php android full-text-search search-engine boolean-search

我正在为一个Android应用程序制作一个搜索引擎,该应用程序进行全文搜索,并针对' + word1 + word2'进行多列匹配。在布尔模式下。 但是,我无法获得任何搜索结果。

E.g。搜索字段类型 - "开阔海域" 然后,Sql将搜索Match ... Against(' + open + sea' IN BOOLEAN MODE)

并显示每个结果点击的可选结果列表,将在新页面上提供特定结果的详细信息。

抱歉,我是Android应用开发的新手。

这是我的search.php

的php代码
<?php

 @ $db = new mysqli('localhost','username','password','db');

  if (mysqli_connect_errno()) {
     echo 'Error: Could not connect to database.  
     Please try again later.';
     exit;
  }

if(!empty($_POST)){

     $term = $_POST['query'];

    $words = explode(" ", trim($term));
    $termArray = array();
    foreach($words as $word){
        if(!empty($word)){
            $termArray[] = "+$word";
                         }
                }
    $searchquery = implode(" ", $termArray);

  if (!$term) {
     echo 'You have not entered any search details. Please go back and try again.';
     exit;
    }
    //initial query

    $query = "SELECT * 
                FROM servicetable 
                    WHERE MATCH(title,cat,brand,company) 
                        AGAINST ('".$searchquery."' IN BOOLEAN MODE)
                            ORDER BY title ASC";

    $result = $db->$query;
    $num_results = $result->num_rows;

    //show user what user searched.   
    echo $searchquery;

    echo "<p>Results found: ".$num_results."</p>";

   //counts results.    
   if ($num_results == 0)    
   {    
      echo "Sorry, but we can not find an entry to match your query<br><br>";    
   }    

  for ($i=0; $i <$num_results; $i++) {
     $row = $result->fetch_assoc();
     echo "<p><strong>".($i+1).". Outlet Name: ";
     echo stripslashes($row['title']);

     echo "</strong><br />Category: ";
     echo stripslashes($row['cat']);
     echo "<br />Opening Hours: ";
     echo stripslashes($row['ophours']);
     echo "<br />Brand: ";
     echo stripslashes($row['brand']);
          echo "</strong><br />Company: ";
     echo stripslashes($row['company']);
     echo "</p>";
  }

  $result->free();
  $db->close();
} else {
?>
        <h1>Search</h1> 
        <form name="form1" action="search.php" method="post"> 
            Enter Search:<br /> 
            <input type="text" name="query" id="query" placeholder="Search a service"/> 
                        <br/>
            <input type="submit" value="Search Now" name="completedsearch"  /> 
        </form> 

    <?php
}

?> 

1 个答案:

答案 0 :(得分:0)

您好我发现了我的错误:

此行修正 - &gt;

$result = $db->query($query);