修改sphider search.php文件,请帮帮我

时间:2015-01-04 10:22:07

标签: javascript php jquery html mysql

我在sphider网站索引和搜索脚本的search.php文件中遇到了麻烦。我需要你的帮助。    实际上我想在我的网站上添加sphider搜索脚本来搜索带有关键字的页面。但我有一个问题。我在网站的每个页面都附加了一个搜索框,现在我想把sphider的search.php文件放在表单操作中。但当我检查时,我知道它没有;搜索结果但旁边显示了search.php文件中的搜索框,当我输入任何关键字并按Enter键时,它会显示结果。所以我的问题是。如何从此search.php文件中删除此搜索框,仅获取搜索结果。

'search.php?query = [---这里是在框中输入的搜索关键字 - ]& search = 1'

这是从search.php搜索框点击输入后显示的网址,但是当我在页面搜索引擎中输入所有详细信息时它没有做任何事情,只是要求搜索该框...所以请各位帮助我....

<?php
/*******************************************
* Sphider Version 1.3.x
* This program is licensed under the GNU GPL.
* By Ando Saabas          ando(a t)cs.ioc.ee
********************************************/
//error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); 
error_reporting(E_ALL); 
$include_dir = "./include"; 
include ("$include_dir/commonfuncs.php");
//extract(getHttpVars());

if (isset($_GET['query']))
	$query = $_GET['query'];
if (isset($_GET['search']))
	$search = $_GET['search'];
if (isset($_GET['domain'])) 
	$domain = $_GET['domain'];
if (isset($_GET['type'])) 
	$type = $_GET['type'];
if (isset($_GET['catid'])) 
	$catid = $_GET['catid'];
if (isset($_GET['category'])) 
	$category = $_GET['category'];
if (isset($_GET['results'])) 
	$results = $_GET['results'];
if (isset($_GET['start'])) 
	$start = $_GET['start'];
if (isset($_GET['adv'])) 
	$adv = $_GET['adv'];
	
	
$include_dir = "./include"; 
$template_dir = "./templates"; 
$settings_dir = "./settings"; 
$language_dir = "./languages";


require_once("$settings_dir/database.php");
require_once("$language_dir/en-language.php");
require_once("$include_dir/searchfuncs.php");
require_once("$include_dir/categoryfuncs.php");


include "$settings_dir/conf.php";

include "$template_dir/$template/header.html";
include "$language_dir/$language-language.php";


if ($type != "or" && $type != "and" && $type != "phrase") { 
	$type = "and";
}

if (preg_match("/[^a-z0-9-.]+/", $domain)) {
	$domain="";
}


if ($results != "") {
	$results_per_page = $results;
}

if (get_magic_quotes_gpc()==1) {
	$query = stripslashes($query);
} 

if (!is_numeric($catid)) {
	$catid = "";
}

if (!is_numeric($category)) {
	$category = "";
} 



if ($catid && is_numeric($catid)) {

	$tpl_['category'] = sql_fetch_all('SELECT category FROM '.$mysql_table_prefix.'categories WHERE category_id='.(int)$_REQUEST['catid']);
}
	
$count_level0 = sql_fetch_all('SELECT count(*) FROM '.$mysql_table_prefix.'categories WHERE parent_num=0');
$has_categories = 0;

if ($count_level0) {
	$has_categories = $count_level0[0][0];
}



require_once("$template_dir/$template/search_form.html");


function getmicrotime(){
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
    }



function poweredby () {
	global $sph_messages;
    //If you want to remove this, please donate to the project at http://www.sphider.eu/donate.php
    print $sph_messages['Powered by'];?>  <a href="http://www.sphider.eu/"><img src="sphider-logo.png" border="0" style="vertical-align: middle" alt="Sphider"></a>

    <?php 
}


function saveToLog ($query, $elapsed, $results) {
        global $mysql_table_prefix;
    if ($results =="") {
        $results = 0;
    }
    $query =  "insert into ".$mysql_table_prefix."query_log (query, time, elapsed, results) values ('$query', now(), '$elapsed', '$results')";
	mysql_query($query);
                    
	echo mysql_error();
                        
}

switch ($search) {
	case 1:

		if (!isset($results)) {
			$results = "";
		}
		$search_results = get_search_results($query, $start, $category, $type, $results, $domain);
		require("$template_dir/$template/search_results.html");
	break;
	default:
		if ($show_categories) {
			if ($_REQUEST['catid']  && is_numeric($catid)) {
				$cat_info = get_category_info($catid);
			} else {
				$cat_info = get_categories_view();
			}
			require("$template_dir/$template/categories.html");
		}
	break;
	}

include "$template_dir/$template/footer.html";
?>
 //*

 I have removed 
require_once("$template_dir/$template/search_form.html");
 and checked whether it work. But no it didn't work. So i'm getting frustrated.. 
 Somebody please help me.. 

1 个答案:

答案 0 :(得分:0)

看看这一行:

$search_results = get_search_results($query, $start, $category, $type, $results, $domain);

这是从上面包含searchfuncs.php的文件中调用的函数。我想在您自己的搜索栏中使用Sphider搜索功能执行以下操作(假设使用了MVC模式):

  1. 在您的搜索栏的控制器中加入searchfunc.php
  2. 从搜索栏设置关键字格式以符合Sphider的约定,并为步骤3准备所需的参数
  3. 从自定义控制器
  4. 调用get_search_results()功能
  5. 现在您正在获得结果,您可能想要创建自定义视图来处理搜索结果,或者返回sphider/templates/standard/search_results.html以获取默认Sphider结果所需的HTML。