rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 程序开发 » PHP

zend_lucene_search 建索引

<?php
/*
 搜索引擎 建索引
*/
$time=time();
require_once('Zend/Search/Lucene.php');
require_once('config.inc.php');

//包含分词文件
require_once('SCWSAnalyzer.php');
$stop_words=array();
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new SCWSAnalyzer($stop_words));

$db=new Mysql();
$db->open();

$index = new Zend_Search_Lucene('data/my-index');
 //$index = new Zend_Search_Lucene('/258sd/zend_search/data/my-index');
$doc = new Zend_Search_Lucene_Document();
for($i=0;$i<2000;$i++)
{
 $info_arr=getList();
 foreach($info_arr as $key => $val) 
 {
  $doc->addField(Zend_Search_Lucene_Field::Text($key,$val)); 
 }
 $index->addDocument($doc);
 //改变index_tag=2;
 change_index_tag($info_arr['goods_id']);
 echo $i.'__'.$info_arr['goods_id']."\r\n";
}

$index->commit();
$db->close();
function getList()
{
 global $db;
 global $goods;
 global $goods_attr;
 $sql="select goods_id ,goods_name,goods_thumb from `".$goods."` where  index_tag=1 and  goods_id>2029 limit 0,1";
 $res=$db->query($sql);
 while($info=$db->fetch($res))
 {
  $goods_id=$info['goods_id'];
  $name=$info['goods_name'];
  $img=$info['goods_thumb'];
  $sql_author="select attr_value as author from `".$goods_attr."` where goods_id='$goods_id' and attr_id=2";
  $author=$db->fetch($db->query($sql_author));
  $sql_isbn="select attr_value as isbn from `".$goods_attr."` where goods_id='$goods_id' and attr_id=10";
  $isbn=$db->fetch($db->query($sql_isbn));
  $sql_publisher="select attr_value as publisher from `".$goods_attr."` where goods_id='$goods_id' and attr_id=3";
  $publisher=$db->fetch($db->query($sql_publisher));
  $temp_arr['goods_id']=$goods_id;
  $temp_arr['name']=$name;
  $temp_arr['img']=$img;
  $temp_arr['isbn']=$isbn['isbn'];
  $temp_arr['author']=$author['author'];
  $temp_arr['publisher']=$publisher['publisher'];
 } 
 return $temp_arr; 
}
function change_index_tag($id)
{
 global $db;
 global $goods;
 $sql="update `".$goods."` set index_tag=2 where goods_id ='$id'";
 $db->query($sql);
}
echo time()-$time;
?>

顶一下
(0)
踩一下
(0)