Results 1 to 4 of 4

Thread: Search Error! Post the Help

  1. #1
    Join Date
    Aug 2001
    Location
    Toronto, Ontario
    Posts
    678

    Default Search Error! Post the Help

    Considering how important the search feature is for this script and for most websites.

    You would think it would be important to fix this problem and allow everyone to download the fix.

    I can't believe this error has been on so long without anyone noticing it till now.

    The response to this bug is, email me and I will help you with it?

    What is up with that?

    This is a crucial bug.. that everyone should know about and should be fixed ASAP!!

  2. #2
    Join Date
    Jan 2002
    Posts
    279

    Default

    Replace search.php with this!



    <?php

    include("application.php");

    // ---------------
    // functions
    // ---------------

    function ShowSearchResult() {

    // vars global configuration

    global $conn, $dbServer, $dbHostname, $dbUsername, $dbPassword, $dbName,
    $theme_path, $category_separator, $HTTP_SERVER_VARS,
    $max_rows, $max_pages, $max_chapters, $number_of_links_format,
    $bold_keyword, $bold_format, $theme_name;

    // vars url & form
    global $pg_which;

    // vars messages
    global $msg;

    // vars template
    global $keyword, $category, $link, $pagination, $error_msg, $num_categories, $num_links;



    if(empty($keyword) || strlen($keyword)<3) {
    $error_msg = $msg["10024"];
    DisplayTemplate($theme_path."search_error.html","\ $error_msg");
    DisplayTemplate($theme_path."footer.html","\$cat") ;

    exit();
    }

    $keyword = chop($keyword);
    $keyword_org = $keyword;
    $keywords = explode(" ", $keyword);
    $keywords_org = $keywords;

    if(empty($pg_which)) $record_log = true;

    // build query

    $query = "select * from idx_category where 0=0";

    $i=0;
    while($i<count($keywords)) {
    if(substr($keywords[$i],0,1)=="+") {
    $keywords[$i] = substr($keywords[$i],1);
    $query .= " and (name like '%$keywords[$i]%')";
    $eval = 1;
    }
    if(substr($keywords[$i],0,1)=="-") {
    $keywords[$i] = substr($keywords[$i],1);
    $query .= " and (name not like '%$keywords[$i]%')";
    $eval = 1;
    }
    if(substr($keywords[$i],0,1)=="|") {
    $keywords[$i] = substr($keywords[$i],1);
    if($i==0) { $query .= " and (name like '%$keywords[$i]%')"; }
    else { $query .= " or (name like '%$keywords[$i]%')"; }
    $eval = 1;
    }
    else {
    if($eval != 1) {
    $query .= " and (name like '%$keywords[$i]%')";
    }
    }
    $i++;
    }
    $query .= " and visible = 1";


    $result = $conn->Execute($query);
    if($result) $num_categories = $result->RecordCount();

    $category_obj = new clsCategory;
    $category_obj->InitDB($dbServer,$dbHostname,$dbUsername,$dbPassw ord,$dbName);
    $category_obj->table_name = "idx_category";

    if(empty($pg_which)||$pg_which==1) {

    $category_obj->link_table_name = "idx_link";
    $category_obj->separator = $category_separator;
    $category_obj->header = $msg["10021"];

    $category_obj->bold_format = $bold_format;
    $category_obj->bold = $bold_keyword;
    $category_obj->keywords = $keywords;

    $category_obj->number_of_columns = 1;
    $category_obj->number_of_links_format = $number_of_links_format;
    $category_obj->show_subcat = false;
    $category_obj->query = $query;
    $category_obj->type_of_list = "SEARCH_RESULT";

    $category = $category_obj->Display();
    }

    // query links //

    $keywords = $keywords_org;

    $users_obj = new clsUsers;
    $users_obj->InitDB($dbServer,$dbHostname,$dbUsername,$dbPassw ord,$dbName);
    $users_obj->table_name = "idx_users";

    $c = $category_obj->GetHiddenCategories();
    $c2 = $category_obj->GetMemberOnlyCategories();

    $query = "select * from idx_link where 0=0";

    $i=0;
    while($i<count($keywords)) {
    if(substr($keywords[$i],0,1)=="+") {
    $keywords[$i] = substr($keywords[$i],1);
    $query .= " and (title like '%$keywords[$i]%' or description like '%$keywords[$i]%')";
    $eval = 1;
    }
    if(substr($keywords[$i],0,1)=="-") {
    $keywords[$i] = substr($keywords[$i],1);
    $query .= " and (title not like '%$keywords[$i]%' and description not like '%$keywords[$i]%')";
    $eval = 1;
    }
    if(substr($keywords[$i],0,1)=="|") {
    $keywords[$i] = substr($keywords[$i],1);
    if ($i==0) { $query .= " and (title like '%$keywords[$i]%' or description like '%$keywords[$i]%')"; }
    else { $query .= " or (title like '%$keywords[$i]%' or description like '%$keywords[$i]%')"; }
    $eval = 1;
    }
    else {
    if($eval != 1) {
    $query .= " and (title like '%$keywords[$i]%' or description like '%$keywords[$i]%')";
    }
    }
    $i++;
    }

    // filter unhide
    $i=0;
    while($i<count($c)) {
    $query .= " and category_id != $c[$i]";
    $i++;
    }

    // filter member only
    if(!$users_obj->GetUserAuthentication()==0) {

    $i=0;
    while($i<count($c2)) {
    $query .= " and category_id != $c2[$i]";
    $i++;
    }
    }

    $query .= " order by bid desc";


    $result = $conn->Execute($query);
    if($result) $num_links = $result->RecordCount();


    $keyword = stripslashes($keyword_org);

    if($num_categories==0 && $num_links==0) {
    $error_msg = $msg["10025"];
    DisplayTemplate($theme_path."search_error.html","\ $error_msg");
    DisplayTemplate($theme_path."footer.html","\$cat") ;

    exit();
    }



    $links_obj = new clsLink;
    $links_obj->InitDB($dbServer,$dbHostname,$dbUsername,$dbPassw ord,$dbName);

    $links_obj->query = $query;
    $links_obj->table_name = "idx_link";
    $links_obj->category_table_name = "idx_category";
    $links_obj->template_file = $theme_path."rows.html";
    $links_obj->date_format = $msg["10023"];

    $links_obj->header = $msg["10022"];
    $links_obj->paging = true;
    $links_obj->pg_size = $max_rows;
    $links_obj->cp_size = $max_pages;
    $links_obj->cp_more = $max_chapters;
    $links_obj->href = "search.php";
    $links_obj->more_param = "&keyword=$keyword";

    $links_obj->bold_format = $bold_format;
    $links_obj->bold = $bold_keyword;
    $links_obj->keywords = $keywords;

    $links_obj->rating_image_path = "themes/".$theme_name."/images/rating/";
    $links_obj->rev_rating_image_path = "themes/".$theme_name."/images/review/";

    $link = $links_obj->Display();
    $pagination = $links_obj->pagination;


    // insert keyword to searchlog table

    if($record_log) {
    $date = date("Y-m-d h:i:s");
    $ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
    $query = "insert into idx_searchlog (keyword,time,ip,result) values ('$keyword','$date','$ip','$num_links')";
    $result = $conn->Execute($query);
    }

    DisplayTemplate($theme_path."search.html","\$keywo rd,\$category,\$link,\$num_links,\$num_categories, \$pagination");
    }





    // ---------------
    // main program
    // ---------------

    $conn = ConnectDB();
    $title = $titles["1110"];

    $theme_name = GetTheme($COOKIE_USERNAME);
    if(empty($theme_name)) $theme_name = "default";

    $theme_path = $theme_path.$theme_name."/";
    include($theme_path."msg.php");

    if(!empty($COOKIE_USERNAME)) $max_rows = GetNOLSearch($COOKIE_USERNAME);

    DisplayTemplate($theme_path."header.html","\$title ,\$cat");
    ShowSearchResult();
    DisplayTemplate($theme_path."footer.html","\$cat") ;

    ?>

  3. #3
    Join Date
    Aug 2001
    Location
    Indonesia
    Posts
    211

    Default

    You can download the fix of search problem in www.indexu.com/download/search.php or www.indexu.com/download/search.zip (zip extension). Or just copy and past from craven's posting.

  4. #4
    Join Date
    Aug 2001
    Location
    Toronto, Ontario
    Posts
    678

    Default

    Craven's posting as well as many other copy and paste scripts have several problems with words being cut off.

    for ex.

    $category_obj = new clsCategory;
    $category_obj-> InitDB($dbServer,$dbHostname,$dbUsername,$dbPasswo
    rd,$dbName);


    you will get many errors like this one.

    $dbpasswo
    rd,$dbName);

    where password is cut into two words

    never ever copy an paste from forums cause they tend to cut off words and give you fatal error messages.

    Unless you recognize them, you'll be in for a treat.

    always use download files.

Similar Threads

  1. power search doesn't search certain cats
    By Rob Picken in forum v5.x
    Replies: 9
    Last Post: 06-15-2004, 02:03 PM
  2. Replies: 0
    Last Post: 02-13-2004, 08:56 PM
  3. Search
    By joyorudis in forum v3.2
    Replies: 0
    Last Post: 09-18-2002, 07:50 AM
  4. Search Box on third party sites !
    By ideavirus in forum v3.2
    Replies: 0
    Last Post: 08-31-2002, 07:59 AM
  5. Search Log Improvements
    By Hart_House in forum v3.2
    Replies: 0
    Last Post: 08-30-2001, 11:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •