Click here to get back home

implementing a website search feature using php

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
implementing a website search feature using php Sudhakar 07-16-2008
Posted by Sudhakar on July 16, 2008, 1:51 pm
Please log in for more thread options
i want to implement a feature where a user searches with a keyword and
search results are displayed according to the keyword

or phrase entered by the user.

following are the steps i want to follow. please advice if i am
missing out any steps or i can add any step.

1. read the keyword entered by user using $search =
$_POST["searchkeyword"];

2. read all the files from the root directory into a variable (as all
files will be saved in the root directory)

3. from step 2 filter and read only files with html and php extensions
into a variable

4. read the entire contents of all html and php files into a variable

5. compare $search with all the individual html and php file contents
from step 4

6. if a match is found with either html or php file then display a
brief title and brief description which will be a link to

the actual file which has the keyword.

7. display search results in a serial order as 1. Brief Title of the
page 2. Brief Title of the page ...

8. at the bottom of the page based on the total number of results
found from step 6 i would like to provide a link to page 1
page 2 page3 ... (i can decide to display only 10 results per page)

please advice.

any help will be greatly appreciated.

thanks.

Posted by burgermeister01@gmail.com on July 16, 2008, 2:02 pm
Please log in for more thread options
> i want to implement a feature where a user searches with a keyword and
> search results are displayed according to the keyword
>
> or phrase entered by the user.
>
> following are the steps i want to follow. please advice if i am
> missing out any steps or i can add any step.
>
> 1. read the keyword entered by user using $search =3D
> $_POST["searchkeyword"];
>
> 2. read all the files from the root directory into a variable (as all
> files will be saved in the root directory)
>
> 3. from step 2 filter and read only files with html and php extensions
> into a variable
>
> 4. read the entire contents of all html and php files into a variable
>
> 5. compare $search with all the individual html and php file contents
> from step 4
>
> 6. if a match is found with either html or php file then display a
> brief title and brief description which will be a link to
>
> the actual file which has the keyword.
>
> 7. display search results in a serial order as 1. Brief Title of the
> page 2. Brief Title of the page ...
>
> 8. at the bottom of the page based on the total number of results
> found from step 6 i would like to provide a link to page 1
> page 2 page3 ... (i can decide to display only 10 results per page)
>
> please advice.
>
> any help will be greatly appreciated.
>
> thanks.

Depending on the process that loads the files being searched into the
directory, it may be quicker to put the contents of the files as they
are added to the directory into a database. That is, make a database
entry for each word in each file. That way instead of parsing each
file every time someone does a search, you instead can just do a
simple database query and return the files that contain the keywords.
Of course, if these files being searched are regularly changed, this
will not work so well. It would at least require some extra processing
to account for files changed.

Hope that helps.

Posted by Jeff on July 16, 2008, 5:35 pm
Please log in for more thread options
burgermeister01@gmail.com wrote:
>> i want to implement a feature where a user searches with a keyword and
>> search results are displayed according to the keyword
>>
>> or phrase entered by the user.
>>
>> following are the steps i want to follow. please advice if i am
>> missing out any steps or i can add any step.
>>
>> 1. read the keyword entered by user using $search =
>> $_POST["searchkeyword"];
>>
>> 2. read all the files from the root directory into a variable (as all
>> files will be saved in the root directory)
>>
>> 3. from step 2 filter and read only files with html and php extensions
>> into a variable
>>
>> 4. read the entire contents of all html and php files into a variable
>>
>> 5. compare $search with all the individual html and php file contents
>> from step 4
>>
>> 6. if a match is found with either html or php file then display a
>> brief title and brief description which will be a link to
>>
>> the actual file which has the keyword.
>>
>> 7. display search results in a serial order as 1. Brief Title of the
>> page 2. Brief Title of the page ...
>>
>> 8. at the bottom of the page based on the total number of results
>> found from step 6 i would like to provide a link to page 1
>> page 2 page3 ... (i can decide to display only 10 results per page)
>>
>> please advice.
>>
>> any help will be greatly appreciated.
>>
>> thanks.
>
> Depending on the process that loads the files being searched into the
> directory, it may be quicker to put the contents of the files as they
> are added to the directory into a database. That is, make a database
> entry for each word in each file. That way instead of parsing each
> file every time someone does a search, you instead can just do a
> simple database query and return the files that contain the keywords.
> Of course, if these files being searched are regularly changed, this
> will not work so well.

If you are using MySQL, MySQL has a FULLTEXT table type. It's more work
than a regular table to set up but but you'll get rankings and MySQL
will discount words that are too common.

As burgermeister has pointed out, you'll need to prepare the data before
you insert it (you won't want the navigation and some other bits, and
you'll probably want to get rid of the tags)

Jeff

It would at least require some extra processing
> to account for files changed.
>
> Hope that helps.

Posted by Captain Paralytic on July 18, 2008, 8:18 am
Please log in for more thread options
> burgermeiste...@gmail.com wrote:
> >> i want to implement a feature where a user searches with a keyword and
> >> search results are displayed according to the keyword
>
> >> or phrase entered by the user.
>
> >> following are the steps i want to follow. please advice if i am
> >> missing out any steps or i can add any step.
>
> >> 1. read the keyword entered by user using $search =
> >> $_POST["searchkeyword"];
>
> >> 2. read all the files from the root directory into a variable (as all
> >> files will be saved in the root directory)
>
> >> 3. from step 2 filter and read only files with html and php extensions
> >> into a variable
>
> >> 4. read the entire contents of all html and php files into a variable
>
> >> 5. compare $search with all the individual html and php file contents
> >> from step 4
>
> >> 6. if a match is found with either html or php file then display a
> >> brief title and brief description which will be a link to
>
> >> the actual file which has the keyword.
>
> >> 7. display search results in a serial order as 1. Brief Title of the
> >> page 2. Brief Title of the page ...
>
> >> 8. at the bottom of the page based on the total number of results
> >> found from step 6 i would like to provide a link to page 1
> >> page 2 page3 ... (i can decide to display only 10 results per page)
>
> >> please advice.
>
> >> any help will be greatly appreciated.
>
> >> thanks.
>
> > Depending on the process that loads the files being searched into the
> > directory, it may be quicker to put the contents of the files as they
> > are added to the directory into a database. That is, make a database
> > entry for each word in each file. That way instead of parsing each
> > file every time someone does a search, you instead can just do a
> > simple database query and return the files that contain the keywords.
> > Of course, if these files being searched are regularly changed, this
> > will not work so well.
>
> If you are using MySQL, MySQL has a FULLTEXT table type.
Er, no it doesn't! You just build a FULLTEXT index on a regular table.

Posted by NC on July 16, 2008, 8:39 pm
Please log in for more thread options
>
> i want to implement a feature where a user searches with
> a keyword and search results are displayed according to
> the keyword or phrase entered by the user.

Use an off-the-shelf search engine... I've used Sphider on a couple
of occasions:

http://www.sphider.eu/

Cheers,
NC

Similar ThreadsPosted
idea behind implementing search facility November 26, 2006, 6:26 pm
search a offline website March 28, 2007, 2:40 pm
Whois IP search integrated into website. February 12, 2005, 2:11 pm
Market Your Business Website On Search Engines May 31, 2007, 11:14 pm
enable keyword search on website whith in mysql database , windowsplatform June 5, 2008, 1:31 am
Implementing a tree September 16, 2005, 5:55 pm
Implementing a Calendar May 15, 2006, 2:26 pm
Implementing CHAT July 11, 2008, 1:43 pm
implementing login/logout (new to php) November 5, 2004, 1:37 pm
Newbie ? about implementing keywords for articles March 24, 2008, 4:53 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap