Esempio n. 1
0
        $posts[] = $rows;
    }
}
//print_r($posts);
$options = array('before_match' => "<span style='color:red'>", 'after_match' => '</span>');
?>
<h3>搜索结果</h3>
<table border="1" >
	<tr>
		<th>id</th>
		<th>weight</th>
		<th>title</th>
		<th>content</th>
	</tr>
<?php 
foreach ($posts as $items) {
    $rows = @$sp->buildExcerpts($items, 'ind_post', $key, $options);
    //print_r($rows);
    echo "<tr>";
    echo "<td>" . $items['id'] . "</td>";
    echo "<td>" . $items['weight'] . "</td>";
    echo "<td>" . $rows[2] . "</td>";
    echo "<td>" . $rows[3] . "</td>";
    echo "</tr>";
}
?>
</table>



Esempio n. 2
0
 $i = $start;
 for ($pg; $pg < $gPageSize && $i < $row_num; $pg++) {
     #	$Timer2->start();////////////////
     if ($light) {
         $row = mysql_fetch_assoc($rst);
         if (strlen($row['description'])) {
             $row['description'] = m_substr($row['description'], 0, 80);
         } else {
             $row['description'] = m_substr($row['fullcontent'], 0, 80);
         }
         if ($row['title']) {
             $row['title'] = m_substr($row['title'], 0, 80);
         } else {
             $row['title'] = m_substr($row['url'], 0, 80);
         }
         $rst2 = $sphinx->buildExcerpts($row, "mysql", $keyword, $opts);
         //"mysql"为索引名!
     } else {
         $rst2 = mysql_fetch_array($rst);
     }
     $i = $i + 1;
     echo "<pre>";
     #echo "Hits:{$rst2[5]}  ";
     echo "<a href=\"{$rst2[1]}\" class='fot' target='_blank'>{$rst2[2]}</a><br>";
     //	echo "关键字:{$rst2[3]}<br>";
     echo "{$rst2[3]}<br>";
     echo "<span style='color:#006400;'>{$rst2[4]} | {$rst2[1]}</span><br>";
     echo "</pre>";
     #	$Timer2->stop();////////////////
     #	$format_number2 = number_format($Timer2->show(false), 3, '.', '');
     #	echo "<p>本条耗时<b style='color:red;'>{$format_number2}s</b>。<br></p>";
Esempio n. 3
0
	//设置字符集
	mysql_set_charset("utf8");
	
	//准备sql语句
	$sql = "select id,title,content from post where id in(".$ids.")";
	
	//发送sql语句
	$result = mysql_query($sql);
	
	//处理结果皆
	
	$opts = array(
	#格式化摘要,高亮字体设置
	#在匹配关键字之前插入的字符串,默认是<b>
	"before_match"  => "<span style='font-weight:bold;color:red'>",
	#在匹配关键字之后插入的字符串,默认是</b>
	"after_match"  => "</span>"
	);
	
	while($row = mysql_fetch_assoc($result)){
		$res = $sphinx->buildExcerpts($row,"main",$keyword,$opts);
		echo "标题:".$res['1']."<br />";
		echo "内容:".$res['2']."<br />";
		echo "<hr>";
	}
	//关闭
	mysql_close($conn);