search;
$search->setCharset('@charset@');
if (empty($q))
{
// just show hot query
$hot = $search->getHotQuery();
}
else
{
// fuzzy search
$search->setFuzzy($m === 'yes');
// synonym search
$search->setAutoSynonyms($syn === 'yes');
// set query
if (!empty($f) && $f != '_all')
{
$search->setQuery($f . ':(' . $q . ')');
}
else
{
$search->setQuery($q);
}
// set sort
if (($pos = strrpos($s, '_')) !== false)
{
$sf = substr($s, 0, $pos);
$st = substr($s, $pos + 1);
$search->setSort($sf, $st === 'ASC');
}
// set offset, limit
$p = max(1, intval($p));
$n = XSSearch::PAGE_SIZE;
$search->setLimit($n, ($p - 1) * $n);
// get the result
$search_begin = microtime(true);
$docs = $search->search();
$search_cost = microtime(true) - $search_begin;
// get other result
$count = $search->getLastCount();
$total = $search->getDbTotal();
if ($xml !== 'yes')
{
// try to corrected, if resul too few
if ($count < 1 || $count < ceil(0.001 * $total))
$corrected = $search->getCorrectedQuery();
// get related query
$related = $search->getRelatedQuery();
}
// gen pager
if ($count > $n)
{
$pb = max($p - 5, 1);
$pe = min($pb + 10, ceil($count / $n) + 1);
$pager = '';
do
{
$pager .= ($pb == $p) ? '' . $p . '' : '[' . $pb . ']';
}
while (++$pb < $pe);
}
}
}
catch (XSException $e)
{
$error = strval($e);
}
// calculate total time cost
$total_cost = microtime(true) - $total_begin;
// XML OUPUT
if ($xml === 'yes' && !empty($q))
{
header("Content-Type: text/xml; charset=$oe");
echo "\n";
echo "\n";
if ($error !== '')
echo " \n";
foreach ($docs as $doc)
{
echo " rank() . "\" percent=\"" . $doc->percent() . "%\">\n";
foreach ($doc as $k => $v)
{
echo " <$k>";
if (is_numeric($v))
echo $v;
else
echo "\n \n ";
echo "$k>\n";
}
echo " \n";
}
echo "\n";
exit(0);
}
// output the data
include dirname(__FILE__) . '/search.tpl';