Page 1 of 1

search website

Posted: Tue Apr 26, 2005 9:02 am
by wood1e
Hi,

I am looking for a search option on my website...Looking through the internet I have found, Full-Text searching using PHP, on various websites.

I was just wondering if this is a good way to allow people to search, or is it now old hat, and there is a better way to have a search facility on my website?

Posted: Tue Apr 26, 2005 10:00 am
by pickle
Strictly speaking, FULL TEXT searching is a MySQL construct, not PHP. It is, nonetheless, the easiest way I've found, to search a website, and give those cool 'relevance percentage' figures.

???

Posted: Sun Jun 05, 2005 11:49 am
by kickmaster
i wrote a search engine that works like this:

Code: Select all

<form action=&quote;&quote; method=&quote;get&quote;>
						    <div align=&quote;right&quote;>
						      <p>
						      <input type=&quote;text&quote; name=&quote;find&quote;>
						      <br>
                              <input type=&quote;submit&quote;  value=&quote;&#1513;&#1500;&#1495; &quote;name=&quote;ok&quote;>
						      </p>
						      <p>
						        <?
						  global $text;
						  $str=$_GET&#1111;&quote;find&quote;];
						  $l=strlen($str);
						  if((substr($str,1,1)==&quote;&quote;) and (substr($str,$l-1,1)==&quote;&quote;))
						  {
						  $str=substr($str,2,$l);
						  $l=strlen($str);
						  $text=$str;
						  find();
						  }
						  else
						  {
						  $mess=explode(&quote; &quote;,$str);
						  $n=sizeof($mess);
							//echo $n.&quote;--&quote;;
						  for($i=0;$i<$n;$i++)
						  {
						  $text=$mess&#1111;$i];
						  $l=strlen($text);
						  if($l!=0)
						  find();
						  }
						  }
						  function find()
						  {
						  global $text;
						  //$text=strtolower($text);
						  //echo $text.&quote;<br>&quote;;
						  $i=0;
						  $j=2;
						  $dirname=&quote;.&quote;;
						  $dh=opendir($dirname);
						  $file=readdir($dh);
						  while ($file !=false)
						  {
						  $path = $dirname.&quote;/&quote;.$file;
						  if(is_dir($path))
						  {
						  $names&#1111;$i]=$path;
						  $i=$i+1;
						  }
						  if(is_file($path))
						  {
						  $fp=fopen($path,&quote;r&quote;);
						  while(!feof($fp))
						  {
						  $line=fgets($fp,1024);
						  if(strstr($line,$text))
						  echo &quote;<a href=&quote;.$file.&quote;>  *  $file </a><br>&quote;;
						  }
						  }
						  $file=readdir($dh);
						  }
						  closedir($dh);
						  }s
						  ?>                        
						                  </p>
						    </div>
						  </form>
how do i get the results to show the target's page <title>???

Posted: Mon Jun 06, 2005 1:15 pm
by pickle
Well, once you've found the file, just parse it for <title> and </title>, and output it's contents

I would suggest that you either a) put the contents in a database or b) cache search data. Searching whole directories of files each time a search is done might start to be taxing on the server.