westdc-zf1/application/default/views/scripts/search/index.phtml

211 lines
6.5 KiB
PHTML

<?php
$__ = array('q', 'm', 'f', 's', 'p', 'ie', 'oe', 'syn', 'xml');
foreach ($__ as $_)
$$_ = isset($_GET[$_]) ? $_GET[$_] : '';
// input encoding
if (!empty($ie) && !empty($q) && strcasecmp($ie, 'UTF-8'))
{
$q = XS::convert($q, $cs, $ie);
$eu .= '&ie=' . $ie;
}
// output encoding
if (!empty($oe) && strcasecmp($oe, 'UTF-8'))
{
function xs_output_encoding($buf)
{
return XS::convert($buf, $GLOBALS['oe'], 'UTF-8');
}
ob_start('xs_output_encoding');
$eu .= '&oe=' . $oe;
}
else
{
$oe = 'UTF-8';
}
// recheck request parameters
$q = get_magic_quotes_gpc() ? stripslashes($q) : $q;
$f = empty($f) ? '_all' : $f;
${'m_check'} = ($m == 'yes' ? ' checked' : '');
${'syn_check'} = ($syn == 'yes' ? ' checked' : '');
${'f_' . $f} = ' checked';
${'s_' . $s} = ' selected';
$search=$this->search;
$this->headTitle($this->config->title->site);
$this->headTitle('首页');
$this->headTitle('搜索');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/search.css');
?>
<div class="outer">
<!-- search form -->
<form id="q-form" method="get">
<div id="q-input">
<input class="text" type="text" name="q" size="40" title="输入任意关键词皆可搜索" value="<?php echo htmlspecialchars($q); ?>" />
<input class="button" type="submit" value=" 搜索! " />
</div>
<div id="q-options">
<h4>选项</h4>
<ul>
<li><input type="radio" name="f" value="title" <?php if (!empty($f_title)) echo $f_title; ?> />Title</li>
<li><input type="radio" name="f" value="_all" <?php if (!empty($f__all)) echo $f__all; ?> />全文</li>
<li><input type="checkbox" name="m" value="yes" <?php echo $m_check; ?> />模糊搜索</li>
<li><input type="checkbox" name="syn" value="yes" <?php echo $syn_check; ?> />同义词</li>
<li>
<select name="s" size="1">
<option value="relevance">相关性</option>
</select>
排序
</li>
</ul>
</div>
</form>
<!-- hot search -->
<?php if (count($this->hot) > 0): ?>
<div id="hot-search" class="res_div2">
<h4>热门搜索</h4>
<ul>
<?php foreach($this->hot as $word => $freq): ?>
<li><a href="/search?q=<?php echo urlencode($word); ?>"><?php echo $word; ?></a><small>(<?php echo $freq; ?>)</small></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<!-- begin search result -->
<?php if (!empty($q)): ?>
<!-- neck bar -->
<div id="res-neck">
大约有 <strong><?php echo number_format($this->count); ?></strong> 项符合查询结果,
库内数据总量为 <strong><?php echo number_format($this->total); ?></strong> 项。
(搜索耗时:<?php printf('%.4f', $this->search_cost); ?>秒 - 页面处理时间:<?php printf('%.4f', $this->total_cost); ?>秒)
[<a href="<?php echo "$this->base_url&xml=yes&p=$p" ;?> " target="_blank">XML</a>]
</div>
<!-- error -->
<?php if (!empty($this->error)): ?>
<div id="res-error"><strong>错误:</strong><?php echo $this->error; ?></div>
<?php endif; ?>
<!-- fixed query -->
<?php if (count($this->corrected) > 0): ?>
<div id="res-fixed" class="res_div2">
<h4>您是不是要找:</h4>
<ul>
<?php foreach ($this->corrected as $word): ?>
<li><a href="<?php echo $_SERVER['SCRIPT_NAME'] . '?q=' . urlencode($word); ?>"><?php echo $word; ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php if (count($this->expanded) > 0): ?>
<div id="res-fixed" class="res_div2">
<h4>您是不是要找:</h4>
<ul>
<?php foreach ($this->expanded as $word): ?>
<li><a href="<?php echo $_SERVER['SCRIPT_NAME'] . '?q=' . urlencode($word); ?>"><?php echo $word; ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<!-- empty result -->
<?php if ($this->count === 0 && empty($this->error)): ?>
<div id="res-empty">
<p>找不到和 <strong><?php echo htmlspecialchars($q); ?></strong> 相符的内容或信息。建议您:</p>
<ul>
<li>请检查输入字词有无错误。</li>
<li>请换用另外的查询字词。</li>
<li>请改用较短、较为常见的字词。</li>
</ul>
</div>
<?php endif; ?>
<!-- result doc list -->
<div id="res-list">
<?php foreach ($this->docs as $doc): ?>
<div class="res-doc">
<h2>
<a href="/data/<?php echo $doc->uuid; ?>"><?php echo $doc->rank(); ?>. <?php echo $this->search->highlight(htmlspecialchars($doc->title)); ?></a>
<small>[<?php echo $doc->percent(); ?>%]</small>
</h2>
<p><?php echo $search->highlight(htmlspecialchars($doc->description)); ?></p>
<ul>
<li><span>关键词:</span> <?php echo $search->highlight(htmlspecialchars($doc->keyword)); ?></li>
<li><span>元数据:</span> <?php echo $search->highlight(htmlspecialchars($doc->data)); ?></li>
</ul>
</div>
<?php endforeach; ?>
</div>
<!-- pager -->
<?php if (!empty($this->pager)): ?>
<div id="res-pager" class="res_div2">
<strong>分页:</strong>
<?php echo $this->pager; ?>
</div>
<?php endif; ?>
<!-- related query -->
<?php if (count($this->related) > 0): ?>
<div id="res-related" class="res_div2">
<h4>相关搜索</h4>
<ul>
<?php foreach ($this->related as $word): ?>
<li><a href="<?php echo '/search?q=' . urlencode($word); ?>"><?php echo $word; ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<!-- end search result -->
<?php endif; ?>
</div><!-- outer -->
<!-- load jquery from google -->
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/redmond/jquery-ui.css" type="text/css" media="all" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<!-- ready script -->
<script language="javascript">
$(function(){
// input tips
$('#q-input .text').focus(function(){
if ($(this).val() == $(this).attr('title')) {
$(this).val('').removeClass('tips');
}
}).blur(function(){
if ($(this).val() == '' || $(this).val() == $(this).attr('title')) {
$(this).addClass('tips').val($(this).attr('title'));
}
}).blur().autocomplete({
'source':'/search/suggest',
'select':function(ev,ui) {
$('#q-input .text').val(ui.item.label);
$('#q-form').submit();
}
});
// submit check
$('#q-form').submit(function(){
var $input = $('#q-input .text');
if ($input.val() == $input.attr('title')) {
alert('请先输入关键词');
$input.focus();
return false;
}
});
});
</script>