由于我需要不适合的搜索功能,我对myqsl之类的搜索和全文搜索感到厌倦,并且我想在我的vps ipage托管上不使用搜索词和使用搜索词的情况下都实现sphinx。
我有一个数据库,其中包含表(1)课程,(2)国家和(3)大学。
国家/地区表中的列包括姓名,友好名称,在,人口,总统,旗帜, 总部地址,大约民主日。我只想索引名称而不是索引 人口,总统,国旗。
University表中包含诸如name,friendly_name,at,no_of Department, 副校长,教职员工,照片,关于大学。我只想索引名称和 about_university,但不在任何部门,图片。
课程表中包含名称,友好名称,部门,学费, type_of_degree,货币,pay_after_grad,about_profession。我只想索引名称和 about_profession,pay_after_grad,type_of_degree,school_fee但货币。
require_once('C:/sphinx/api/sphinxapi.php');
$s = new SphinxClient;
$s->setServer("127.0.0.1", 9312); // NOT "localhost" under Windows 7!
$s->SetLimits(0, 25);
$result = $s->Query ("" , "market_shop_product" );
$no=0;
print_r($result['warning']);
if ($result['total'] > 0) {
echo 'Total: ' . $result['total'] . "<br>\n";
echo 'Total Found: ' . $result['total_found'] . "<br>\n";
echo '<table>';
foreach ($result['matches'] as $id => $otherStuff) {
if (isset($search))
{$row = mysqli_fetch_assoc(mysqli_query($con, "SELECT country.*, COUNT(univeristy.country) AS amount FROM country
LEFT JOIN univeristy ON country.id=univeristy.country
LEFT JOIN course ON univeristy.id = course.country
MATCH(country.`name`, country.`address`, country.`about`, country.`country`, country.`city`) AGAINST('{$search}' IN NATURAL LANGUAGE MODE) OR
MATCH(`university`.`university`, `university`.`deal`) AGAINST('{$search}') OR
MATCH(`course`.`name`, `course`.`price`, `course`.`measure`)
AGAINST('{$search}')"));} else {$row = mysqli_fetch_assoc(mysqli_query($con, "SELECT country.*, COUNT(university.country) AS amount FROM country
LEFT JOIN univeristy ON country.id=univeristy.country
LEFT JOIN course ON univeristy.id = course.country
WHERE(country.`country`='{$country}') GROUP by market.id ORDER BY amount DESC
"));}
extract($row);
++ $no;
echo " $name - $country <br>";
}
} else {
echo 'No results found';
}
这是为sphinx.conf
sql_query = \
SELECT country.`id`,country.`name`, country.`friendly_url`, country.`address`, country.`country`, country.`city`, country.`about`, country.`state`, university.name, university.about_university, course.about_profession, course.pay_after_grad, course.type_of_degree, course.school_fee, course.name AS cour \
FROM country \
LEFT JOIN university ON country.id = university.country \
LEFT JOIN course ON country.id = course.country
sql_attr_uint = country
SQL
SELECT `university`, CONCAT('is a ', `deal`, ' university') AS sell, `pic`, 'university' AS source, CONCAT(friendly_university, '/{$url}') AS link FROM university WHERE country='{$country}' AND MATCH (`university`, `deal`) AGAINST('{$search}' IN NATURAL LANGUAGE MODE) LIMIT 8
UNION ALL
SELECT `name`, CONCAT( 'average price is ',`currency`, AVG(`price`)) AS priceaverage, `image`, 'course' AS source, CONCAT(friendly_course, 'AT{$url}') AS link FROM course WHERE `country`='{$country}' AND `univeristy`='{$page}' AND MATCH(`name`, `price`, `measure`) AGAINST('{$search}' IN NATURAL LANGUAGE MODE) LIMIT 8
";