Improve Search function in Downloads

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   Improve Search function in Downloads
jhayann1
CZ Newbie
jhayann1 has been a member for over 19 year's 19 Year Member
usa.gif pennsylvania.gif
Gender: Female
Website:
Status: Offline
Joined: Jul 27, 2005
0.00 posts per day
Posts: 5
Points: 240
   
The search function of my Enhanced Downloads v1.7 sucks, and I can't get any help from the makers as their site doesn't exist anymore, so I hope someone here can help me.

Can someone walk me thru how to change the following things with the Downloads search function? (In order of importance...)

(1) the ability to search not just the title and description, but also the author's name ($name), the "compatible with" ($ns_compat) option, and maybe even the ALT (or TITLE) tags of images used within the description.

(2) the ability to search for more than 1 keyword, separating them with a comma (or space).

(3) highlight the search results' keywords using CSS' span tag or whatever works.



Here's a link to my Downloads section (you can view downloads without registering):
[ Register or login to view links on this board.]


This is the search stuff on my Downloads module's index.html:


function search($query, $min, $orderby, $show) {
    global $prefix, $db, $admin, $prbgcolor2, $module_name, $prbgcolor1, $tttextcolor, $ns_theme, $mod_title, $mod_title_directory;
    $result_sr = $db->sql_query("SELECT ns_dl_num_per_page, ns_dl_num_results, ns_dl_main_dec from ".$prefix."_ns_downloads");
    list($ns_dl_num_per_page, $ns_dl_num_results, $ns_dl_main_dec) = $db->sql_fetchrow($result_sr);

    include("header.php");
    if (!isset($min)) $min=0;
    if (!isset($max)) $max=$min+$ns_dl_num_results;
    if(isset($orderby)) {
   $orderby = convertorderbyin($orderby);
    } else {
   $orderby = "title ASC";
    }
    if ($show!="") {
   $ns_dl_num_results = $show;
    } else {
   $show=$ns_dl_num_results;
    }
    $query = check_html($query, nohtml);
    $query = addslashes($query);
    $result = $db->sql_query("SELECT lid, cid, title, url, description, date, hits, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage, ns_des_img FROM ".$prefix."_downloads_downloads WHERE title LIKE '%$query%' OR description LIKE '%$query%' ORDER BY $orderby LIMIT $min,$ns_dl_num_results");
    $fullcountresult = $db->sql_query("SELECT lid, title, description, date, hits, downloadratingsummary, totalvotes, totalcomments FROM ".$prefix."_downloads_downloads WHERE title LIKE '%$query%' OR description LIKE '%$query%' ");
    $totalselecteddownloads = $db->sql_numrows($fullcountresult);
    $nrows = $db->sql_numrows($result);
    $x=0;
    $the_query = stripslashes($query);
    $the_query = str_replace("\'", "'", $the_query);

    menu(1);
    echo "<br><a name=\"searchresults\">";
    ns_mod_title2("search_results","<h4>"._SEARCHRESULTS."</h4>");
   OpenTable();
    if ($query != "") {
       if ($nrows>0) {
      echo "<p align=\"center\"><b>"._SEARCHRESULTS4.":</b> <em>$the_query</em></p>";
      echo "<h3>"._USUBCATEGORIES."</h3>";
      $result2 = $db->sql_query("select cid, title from ".$prefix."_downloads_categories where title LIKE '%$query%' ORDER BY title DESC");
      while(list($cid, $stitle) = $db->sql_fetchrow($result2)) {
                    $cid = intval($cid);
          $res = $db->sql_query("select * from ".$prefix."_downloads_downloads where cid='$cid'");
          $numrows = $db->sql_numrows($res);
          $result3 = $db->sql_query("select cid,title,parentid from ".$prefix."_downloads_categories where cid='$cid'");
           list($cid3,$title3,$parentid3) = $db->sql_fetchrow($result3);
                $cid3 = intval($cid3);
          if ($parentid3>0) $title3 = getparent($parentid3,$title3);
          $title3 = ereg_replace($query, "<b>$query</b>", $title3);
      ns_dl_image();
          echo "<p><a href=\"modules.php?name=$module_name&d_op=viewdownload&amp;cid=$cid\">$title3</a> <b>($numrows)</b></p>";
      }
      if ($numrows < 1) {
      echo "<h3>"._NOSUBCATEGORIES."</h3>";
      }
      
//      echo "<h5>"._UDOWNLOADS."</h5>";
      

//sort table - search   
OpenTable2();
    $orderbyTrans = convertorderbytrans($orderby);
   echo "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"1\"><tr><th align=\"center\">";
   if (($mod_title == 1) AND (file_exists("themes/$ns_theme/$mod_title_directory/$module_name/sortdownloads.gif"))) {
   echo "<img src=\"themes/$ns_theme/$mod_title_directory/$module_name/sortdownloads.gif\" border=\"0\" title=\""._SORTDOWNLOADS."\">";
   } else {
   echo ""._SORTDOWNLOADS."";
   }
echo "</th></tr><tr><td align=\"center\"><br /><b>"._TITLE."</b> <a href=\"modules.php?name=$module_name&d_op=viewdownload&amp;cid=$cid&amp;orderby=titleA#categorystart\"><span style=\"vertical-align=-20%\"><img src=\"images/custom/arrow_up.gif\" border=\"0\" title=\""._TITLEAZ."\"></span></a>&nbsp;<a href=\"modules.php?name=$module_name&d_op=viewdownload&amp;cid=$cid&amp;orderby=titleD#categorystart\"><span style=\"vertical-align=-20%\"><img src=\"images/custom/arrow_down.gif\" border=\"0\" title=\""._TITLEZA."\"></span></a><b>&nbsp;|&nbsp;</b><b>"._DATE."</b> <a href=\"modules.php?name=$module_name&d_op=viewdownload&amp;cid=$cid&amp;orderby=dateD#categorystart\"><span style=\"vertical-align=-20%\"><img src=\"images/custom/arrow_up.gif\" border=\"0\" title=\""._DATE2."\"></span></a>&nbsp;<a href=\"modules.php?name=$module_name&d_op=viewdownload&amp;cid=$cid&amp;orderby=dateA#categorystart\"><span style=\"vertical-align=-20%\"><img src=\"images/custom/arrow_down.gif\" border=\"0\" title=\""._DATE1."\"></span></a> <b>&nbsp;|&nbsp;</b><b>"._RATING."</b> <a href=\"modules.php?name=$module_name&d_op=viewdownload&amp;cid=$cid&amp;orderby=ratingD#categorystart\"><span style=\"vertical-align=-20%\"><img src=\"images/custom/arrow_up.gif\" border=\"0\" title=\""._RATING2."\"></span></a>&nbsp;<a href=\"modules.php?name=$module_name&d_op=viewdownload&amp;cid=$cid&amp;orderby=ratingA#categorystart\"><span style=\"vertical-align=-20%\"><img src=\"images/custom/arrow_down.gif\" border=\"0\" title=\""._RATING1."\"></span></a> <b>&nbsp;|&nbsp;</b><b>"._POPULARITY."</b> <a href=\"modules.php?name=$module_name&d_op=viewdownload&amp;cid=$cid&amp;orderby=hitsD#categorystart\"><span style=\"vertical-align=-20%\"><img src=\"images/custom/arrow_up.gif\" border=\"0\" title=\""._POPULARITY2."\"></span></a>&nbsp;<a href=\"modules.php?name=$module_name&d_op=viewdownload&amp;cid=$cid&amp;orderby=hitsA#categorystart\"><span style=\"vertical-align=-20%\"><img src=\"images/custom/arrow_down.gif\" border=\"0\" title=\""._POPULARITY1."\"></span></a><b></b><br><br><b>"._DSITESSORTED.":</b> $orderbyTrans</font></center></td></tr></table>";
CloseTable2();

           ns_download_image();
       while(list($lid, $cid, $title, $url, $description, $time, $hits, $downloadratingsummary, $totalvotes, $totalcomments, $filesize, $version, $homepage, $ns_compat, $ns_des_img) = $db->sql_fetchrow($result)) {
            $lid = intval($lid);
            $cid = intval($cid);
            $hits = intval($hits);
            $totalvotes = intval($totalvotes);
            $totalcomments = intval($totalcomments);
            $filesize = intval($filesize);
      
       $downloadratingsummary = number_format($downloadratingsummary, $ns_dl_main_dec);
       $title = stripslashes($title);
            $description = stripslashes($description);      
       $transfertitle = str_replace (" ", "_", $title);
       $title = ereg_replace($query, "<b>$query</b>", $title);
        global $prefix, $db, $admin;
       echo "<br>";
         
                
   ns_dl_image();
       echo "<h6><a href=\"modules.php?name=$module_name&d_op=getit&amp;lid=$lid\" title=\"Click on Title to Download\">$title</a>";
       newdownloadgraphic($datetime, $time);     
           popgraphic($hits);
         echo "</h6>";      
   ns_download_image_pop($lid, $ns_des_img, $description, $title);
       $result3 = $db->sql_query("select cid,title,parentid from ".$prefix."_downloads_categories where cid='$cid'");
       list($cid3,$title3,$parentid3) = $db->sql_fetchrow($result3);
                $cid3 = intval($cid3);
           if ($parentid3>0) $title3 = getparent($parentid3,$title3);
       echo "<br /><p><b>"._CATEGORY.":</b> <a href=modules.php?name=$module_name&d_op=viewdownload&cid=$cid#categorystart>$title3</a><br>";
       mktime ("LC_TIME", "$locale");
       ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
       $datetime = strftime(""._LINKSDATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
       $datetime = ucfirst($datetime);
   echo "<b>"._VERSION.":</b> $version<br>";
   echo "<b>"._FILESIZE.":</b> ".CoolSize($filesize)."<br>";
   echo "<b>"._ADDEDON.":</b> $datetime<br>";
   echo "<b>"._UDOWNLOADS.":</b> $hits<br>";
           /* voting & comments stats */
            $totalvotes = intval($totalvotes);
           if ($totalvotes == 1) {
      $votestring = _VOTE;
       } else {
      $votestring = _VOTES;
       }
           if ($downloadratingsummary!="0" || $downloadratingsummary!="0.0") {
      echo "<b>"._RATING.":</b> $downloadratingsummary ($totalvotes $votestring)</p><br>";
       }
        ns_download_foot($homepage, $lid, $transfertitle, $totalcomments);
       detecteditorial($lid, $transfertitle, 1);
        ns_dl_admin($lid, $admin);
      echo "<br>";
       $x++;
   }
       $orderby = convertorderbyout($orderby);
    } else {
   echo "<br><br><center><font class=\"option\"><b>"._NOMATCHES."</b></font><br><br>"._GOBACK."<br></center>";
    }
    /* Calculates how many pages exist. Which page one should be on, etc... */
   echo "<center>";
    $downloadpagesint = ($totalselecteddownloads / $ns_dl_num_per_page);         
    $downloadpageremainder = ($totalselecteddownloads % $ns_dl_num_per_page);      
    if ($downloadpageremainder != 0) {               
       $downloadpages = ceil($downloadpagesint);            
       if ($totalselecteddownloads < $ns_dl_num_per_page) {
          $downloadpageremainder = 0;
       }
    } else {
       $downloadpages = $downloadpagesint;
    }
    /* Page Numbering */
    if ($downloadpages!=1 && $downloadpages!=0) {
   if (($mod_title == 1) AND (file_exists("themes/$ns_theme/$mod_title_directory/$module_name/selectpage.gif"))) {
   echo "<p align=\"center\"><img src=\"themes/$ns_theme/$mod_title_directory/$module_name/selectpage.gif\" border=\"0\" title=\""._SELECTPAGE."\"></p>";
   } else {
        echo "<p><hr /></p><br /><p align=\"center\"><em>"._SELECTPAGE."</em></p>";
   }
        echo "<table cellpadding=\"1\" cellspacing=\"2\" border=\"0\" align=\"center\"><tr>";
        $prev=$min-$ns_dl_num_per_page;
        if ($prev>=0) {
           echo "<td valign=\"middle\" align=\"center\">&nbsp;&nbsp;<a href=\"modules.php?name=$module_name&d_op=viewdownload&amp;cid=$cid&amp;min=$prev&amp;orderby=$orderby&amp;show=$show#categorystart\"><img src=\"themes/$ns_theme/images/previous.gif\" border=\"0\" title=\""._PREVIOUS."\"></a>&nbsp;&nbsp;</td>";
     }          
       $counter = 1;
   $currentpage = ($max / $ns_dl_num_per_page);
          while ($counter<=$downloadpages ) {
             $cpage = $counter;
             $mintemp = ($ns_dl_num_per_page * $counter) - $ns_dl_num_per_page;
             if ($counter == $currentpage) {
      echo "<td valign=\"top\" align=\"center\"><span style=\"vertical-align=-23%\">&nbsp;&nbsp;<b>$counter</b>&nbsp;&nbsp;</span></td>";
       } else {
      echo "<td valign=\"top\" align=\"center\">&nbsp;&nbsp;<span style=\"vertical-align=-23%\"><a href=\"modules.php?name=$module_name&d_op=viewdownload&amp;cid=$cid&amp;min=$mintemp&amp;orderby=$orderby&amp;show=$show#categorystart\" class=\"pagenumbers\">$counter</a></span>&nbsp;&nbsp;</td>";
       }
              $counter++;
          }         
        $next=$min+$ns_dl_num_per_page;
        if ($x>=$ns_dl_num_per_page) {
          echo "<td valign=\"middle\" align=\"center\">&nbsp;&nbsp;<a href=\"modules.php?name=$module_name&d_op=viewdownload&amp;cid=$cid&amp;min=$max&amp;orderby=$orderby&amp;show=$show#categorystart\"><img src=\"themes/$ns_theme/images/next.gif\" border=\"0\" title=\""._NEXT."\"></a>&nbsp;&nbsp;</td>";
        }
   echo "</tr></table>";
    }

        echo "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\"><tr>";
    echo "<td align=\"center\"><br><br><font class=\"content\">"
   .""._TRY2SEARCH." \"$the_query\" "._INOTHERSENGINES."<br>"
   ."<a target=\"_blank\" href=\"http://www.altavista.com/cgi-bin/query?pg=q&amp;sc=on&amp;hl=on&amp;act=2006&amp;par=0&amp;q=$the_query&amp;kl=XX&amp;stype=stext\">Alta Vista</a> - "
   ."<a target=\"_blank\" href=\"http://www.hotbot.com/?MT=$the_query&amp;DU=days&amp;SW=web\">HotBot</a> - "
   ."<a target=\"_blank\" href=\"http://www.infoseek.com/Titles?qt=$the_query\">Infoseek</a> - "
   ."<a target=\"_blank\" href=\"http://www.dejanews.com/dnquery.xp?QRY=$the_query\">Deja News</a> - "
   ."<a target=\"_blank\" href=\"http://www.lycos.com/cgi-bin/pursuit?query=$the_query&amp;maxhits=20\">Lycos</a> - "
   ."<a target=\"_blank\" href=\"http://search.yahoo.com/bin/search?p=$the_query\">Yahoo</a>"
   ."<br>"
   ."<a target=\"_blank\" href=\"http://es.linuxstart.com/cgi-bin/sqlsearch.cgi?pos=1&amp;query=$the_query&amp;language=&amp;advanced=&amp;urlonly=&amp;withid=\">LinuxStart</a> - "
   ."<a target=\"_blank\" href=\"http://search.1stlinuxsearch.com/compass?scope=$the_query&amp;ui=sr\">1stLinuxSearch</a> - "
   ."<a target=\"_blank\" href=\"http://www.google.com/search?q=$the_query\">Google</a> - "
   ."<a target=\"_blank\" href=\"http://www.linuxdownloads.com/cgi-bin/search.cgi?query=$the_query&amp;engine=Downloads\">LinuxDownloads</a> - "
   ."<a target=\"_blank\" href=\"http://www.freshmeat.net/modules.php?name=Search&amp;query=$the_query\">Freshmeat</a> - "
   ."<a target=\"_blank\" href=\"http://www.justlinux.com/bin/search.pl?key=$the_query\">JustLinux</a>"
   ."</font><br><br></td>";
    echo "</tr></table><br>";

    } else {
   echo "<center><font class=\"option\"><b>"._NOMATCHES."</b></font></center><br><br>";
    }
    CloseTable();
    include("footer.php");
}



Thanks in advance for any help with any one (or all) of the items I'd like to accomplish!


Back to top Reply with quote
#2   re: Improve Search function in Downloads
jhayann1
CZ Newbie
jhayann1 has been a member for over 19 year's 19 Year Member
usa.gif pennsylvania.gif
Gender: Female
Website:
Status: Offline
Joined: Jul 27, 2005
0.00 posts per day
Posts: 5
Points: 240
   
Ok, I've figured out how to do the above... but I stumbled across something when testing the search function: If no subcategory matches are found, it's supposed to say "No subcategory matches found" but for some reason, it's just blank. And if there ARE subcategory matches, the page layout get screwy and you'll notice the red rightside border disappears.

Anyone?



Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum