douxiu6835 2015-01-04 10:22
浏览 70

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

I'm in trouble with search.php file of sphider website indexing and search script. I need your help. Actually i want to put sphider search script in my website to search the pages with keywords. But i have a problem. i have attached a search box in each page of website and now i want to put search.php file of sphider in form action. But when i checked i got that it don;t search results but beside it shows a search box in search.php file and when i enter any keyword and hit enter then it shows the results. So my question is. How to remove this search box from this search.php file and only get the search result.

' search.php?query= [---Here comes the search keywords entered in box--] &search=1'

this is URL that shows after hitting enter from search.php search box but when putting all details right in my page search engine it doesn't do anything and only ask to search through that box... So guys please help me....

<?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.. 

</div>
  • 写回答

1条回答 默认 最新

  • dongliling6336 2015-08-25 16:07
    关注

    Take a look at this line:

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

    This is a function being called from a file that is included above searchfuncs.php I you want to use the Sphider search functionality with your own search bar do the following (assuming MVC pattern is used):

    1. Include searchfunc.php in your controller for your searchbar
    2. Format your keywords from the searchbar to fit conventions for Sphider and prepare the required parameters for step #3
    3. Call the get_search_results() function from your custom controller
    4. Now that you are getting results you may want to create a custom view to handle the search results, or else refer back to sphider/templates/standard/search_results.html for the required HTML for default Sphider results.
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计