Created
September 11, 2014 09:34
-
-
Save kaizhuQin/58df97b22bd4e1ef4c53 to your computer and use it in GitHub Desktop.
php:xunsearch 索引建立 和 搜索
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require '/data/sdk/php/lib/XS.php'; | |
$xs = new XS('demo'); // 建立 XS 对象,项目名称为:demo | |
// 创建文档对象 | |
$doc = new XSDocument; | |
// 添加到索引数据库中 | |
$index = $xs->index; | |
// $res = $index->add($doc); | |
$con = mysql_connect("localhost","root","666666"); | |
if (!$con) | |
{ | |
die('Could not connect: ' . mysql_error()); | |
} | |
mysql_select_db("xunso", $con); | |
$result = mysql_query("SELECT * FROM news_articles"); | |
while($row = mysql_fetch_array($result)) | |
{ | |
$data = array( | |
'pid' => $row['id'], // 此字段为主键,必须指定 | |
'subject' => $row['title'], | |
'message' => $row['content'], | |
'chrono' => time() | |
); | |
$doc->setFields($data); | |
$res = $index->add($doc); | |
var_dump($res); | |
} | |
mysql_close(); | |
/****************************************************/ | |
require '/data/sdk/php/lib/XS.php'; | |
$xs = new XS('demo'); // 建立 XS 对象,项目名称为:demo | |
$search = $xs->search; // 获取 搜索对象 | |
$docs = $search->count("清华"); // 执行搜索,将搜索结果文档保存在 $docs 数组中 | |
var_dump($docs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment