全文搜索引擎,多列,布尔模式
我正在制作一个搜索引擎,用于执行全文搜索并在布尔模式下针对'+ word1 + word2'进行多列匹配的Android应用程序。 但是,我无法获得任何搜索结果。
例如搜索字段类型 - “开阔海域”,Sql将搜索Match ...对('+ open + sea'IN BOOLEAN MODE)
并显示单击每个结果的可选结果列表,将在新页面上提供特定结果的详细信息。
对不起,我是Android应用程序开发的新手。
这是我的php代码search.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
}
?>
嗨,我发现我的错误:
这条线更正 - >
$result = $db->query($query);
链接地址: http://www.djcxy.com/p/75291.html