About Website Search Engine

This is a discussion on About Website Search Engine within the PHP General forums, part of the PHP Programming Forums category; I'm trying to build a search engine for my website (with php), it will have functions such as finding ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-05-2007
Kelvin Park
 
Posts: n/a
Default About Website Search Engine

I'm trying to build a search engine for my website (with php), it will have
functions such as finding product names and their codes from the mysql
database.
Does anyone know any good tutorial or reference on any website, or any good
books out there that you might recommend?
I couldnt' find any decent one but only the ones that keep on saying, "use
google search engine to search your website!" etc.
Thanks!

Reply With Quote
  #2 (permalink)  
Old 07-05-2007
Daniel Brown
 
Posts: n/a
Default Re: [PHP] About Website Search Engine

On 7/5/07, Kelvin Park <kelvinpark86@gmail.com> wrote:
> I'm trying to build a search engine for my website (with php), it will have
> functions such as finding product names and their codes from the mysql
> database.
> Does anyone know any good tutorial or reference on any website, or any good
> books out there that you might recommend?
> I couldnt' find any decent one but only the ones that keep on saying, "use
> google search engine to search your website!" etc.
> Thanks!
>


Kelvin,

That depends. Is the content of your website dynamically-driven
from content within the MySQL database you mentioned? If so,
something like this would work:

<?
// Do your includes and database connection schemes here.

if($_POST['search_data']) {
$terms = mysql_real_escape_string($_POST['search_data']);
$sql = "SELECT * FROM tablename WHERE $terms IN ";
$sql .= "product_id,product_name,product_description";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
extract($row);
// Do your processing of each row of information here.
}
}
?>
<FORM METHOD="POST" ACTION="<?=$_SERVER['PHP_SELF'];?>">
Terms: <INPUT TYPE="TEXT" NAME="search_data"
VALUE="<?=$_POST['search_data'];?>"><BR />
<INPUT TYPE="SUBMIT" VALUE="Search">
</FORM>

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
Reply With Quote
  #3 (permalink)  
Old 07-05-2007
Daniel Brown
 
Posts: n/a
Default Re: [PHP] About Website Search Engine

On 7/5/07, Kelvin Park <kelvinpark86@gmail.com> wrote:
> Yes my website is dynamically driven from content within mysql. The products
> and the product information is within the datase. I was looking for a way to
> allow people to "efficiently" search for an item, for example if a customer
> types in, "bunny", it would find everything (and display them) that has word
> "bunny", or if the customer "misspells" it, "bunn", it will still display
> every item with the letters accordingly.
>
>
>
> On 7/5/07, Daniel Brown <parasane@gmail.com> wrote:
> > On 7/5/07, Kelvin Park <kelvinpark86@gmail.com> wrote:
> > > I'm trying to build a search engine for my website (with php), it will

> have
> > > functions such as finding product names and their codes from the mysql
> > > database.
> > > Does anyone know any good tutorial or reference on any website, or any

> good
> > > books out there that you might recommend?
> > > I couldnt' find any decent one but only the ones that keep on saying,

> "use
> > > google search engine to search your website!" etc.
> > > Thanks!
> > >

> >
> > Kelvin,
> >
> > That depends. Is the content of your website dynamically-driven
> > from content within the MySQL database you mentioned? If so,
> > something like this would work:
> >
> > <?
> > // Do your includes and database connection schemes here.
> >
> > if($_POST['search_data']) {
> > $terms =

> mysql_real_escape_string($_POST['search_data']);
> > $sql = "SELECT * FROM tablename WHERE $terms IN ";
> > $sql .= "product_id,product_name,product_description";
> > $result = mysql_query($sql);
> > while($row = mysql_fetch_array($result)) {
> > extract($row);
> > // Do your processing of each row of information here.
> > }
> > }
> > ?>
> > <FORM METHOD="POST" ACTION="<?=$_SERVER['PHP_SELF'];?>">
> > Terms: <INPUT TYPE="TEXT" NAME="search_data"
> > VALUE="<?=$_POST['search_data'];?>"><BR />
> > <INPUT TYPE="SUBMIT" VALUE="Search">
> > </FORM>
> >
> > --
> > Daniel P. Brown
> > [office] (570-) 587-7080 Ext. 272
> > [mobile] (570-) 766-8107
> >

>
>


The example I sent to you will act as a foundation to do the first
part of what you're asking, but not the second. To do something like
the second, you'll want to do something like:

$sql = "SELECT * FROM tablename WHERE $terms IN ";
$sql .= "product_id,product_name,product_description ";
$sql .= "OR product_description LIKE '%".$terms."%'";

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
Reply With Quote
  #4 (permalink)  
Old 07-06-2007
Nathan Nobbe
 
Posts: n/a
Default Re: [PHP] About Website Search Engine

Kevin,

just like Daniel said,
> $sql .= "OR product_description *LIKE '%".$terms."%'"*;


most of the *search engines* ive seen revolve around the use of the LIKE
construct<http://dev.mysql.com/doc/refman/5.1/en/string-comparison-functions.html#operator_like>
which is a simplified regex mechanism for an SQL query [for MySQL at least,
probly other RDBMS' as well]

-nathan


On 7/5/07, Daniel Brown <parasane@gmail.com> wrote:
>
> On 7/5/07, Kelvin Park <kelvinpark86@gmail.com> wrote:
> > Yes my website is dynamically driven from content within mysql. The

> products
> > and the product information is within the datase. I was looking for a

> way to
> > allow people to "efficiently" search for an item, for example if a

> customer
> > types in, "bunny", it would find everything (and display them) that has

> word
> > "bunny", or if the customer "misspells" it, "bunn", it will still

> display
> > every item with the letters accordingly.
> >
> >
> >
> > On 7/5/07, Daniel Brown <parasane@gmail.com> wrote:
> > > On 7/5/07, Kelvin Park <kelvinpark86@gmail.com> wrote:
> > > > I'm trying to build a search engine for my website (with php), it

> will
> > have
> > > > functions such as finding product names and their codes from the

> mysql
> > > > database.
> > > > Does anyone know any good tutorial or reference on any website, or

> any
> > good
> > > > books out there that you might recommend?
> > > > I couldnt' find any decent one but only the ones that keep on

> saying,
> > "use
> > > > google search engine to search your website!" etc.
> > > > Thanks!
> > > >
> > >
> > > Kelvin,
> > >
> > > That depends. Is the content of your website dynamically-driven
> > > from content within the MySQL database you mentioned? If so,
> > > something like this would work:
> > >
> > > <?
> > > // Do your includes and database connection schemes here.
> > >
> > > if($_POST['search_data']) {
> > > $terms =

> > mysql_real_escape_string($_POST['search_data']);
> > > $sql = "SELECT * FROM tablename WHERE $terms IN ";
> > > $sql .= "product_id,product_name,product_description";
> > > $result = mysql_query($sql);
> > > while($row = mysql_fetch_array($result)) {
> > > extract($row);
> > > // Do your processing of each row of information here.
> > > }
> > > }
> > > ?>
> > > <FORM METHOD="POST" ACTION="<?=$_SERVER['PHP_SELF'];?>">
> > > Terms: <INPUT TYPE="TEXT" NAME="search_data"
> > > VALUE="<?=$_POST['search_data'];?>"><BR />
> > > <INPUT TYPE="SUBMIT" VALUE="Search">
> > > </FORM>
> > >
> > > --
> > > Daniel P. Brown
> > > [office] (570-) 587-7080 Ext. 272
> > > [mobile] (570-) 766-8107
> > >

> >
> >

>
> The example I sent to you will act as a foundation to do the first
> part of what you're asking, but not the second. To do something like
> the second, you'll want to do something like:
>
> $sql = "SELECT * FROM tablename WHERE $terms IN ";
> $sql .= "product_id,product_name,product_description ";
> $sql .= "OR product_description LIKE '%".$terms."%'";
>
> --
> Daniel P. Brown
> [office] (570-) 587-7080 Ext. 272
> [mobile] (570-) 766-8107
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Reply With Quote
  #5 (permalink)  
Old 07-06-2007
Robert Cummings
 
Posts: n/a
Default Re: [PHP] About Website Search Engine

On Thu, 2007-07-05 at 22:26 -0400, Nathan Nobbe wrote:
> Kevin,
>
> just like Daniel said,
> > $sql .= "OR product_description *LIKE '%".$terms."%'"*;

>
> most of the *search engines* ive seen revolve around the use of the LIKE
> construct<http://dev.mysql.com/doc/refman/5.1/en/string-comparison-functions.html#operator_like>
> which is a simplified regex mechanism for an SQL query [for MySQL at least,
> probly other RDBMS' as well]


Don't do that. Unless you have a teency weency set of data don't use
LIKE syntax to match data. It's extremely inefficient and requires
scanning the entire table. If you need to use MySQL use the MATCH
AGAINST syntax since it will index the data and search much faster. I've
heard tell it sucks beyond a certain size, but it's great for quick
solutions and moderate sized data. If you need something more powerful
look into something like Lucene.

Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
Reply With Quote
  #6 (permalink)  
Old 07-06-2007
Nathan Nobbe
 
Posts: n/a
Default Re: [PHP] About Website Search Engine

note: i never said this was an optimal solution; i just said thats what ive
seen.
obviously i havent worked on any major search engine to date.
in fact i was fishing a bit for some info on how to do it right.

> On 7/5/07, Robert Cummings < robert@interjinn.com> wrote:
> If you need to use MySQL use the MATCH
> AGAINST syntax since it will index the data and search much faster. I've
> heard tell it sucks beyond a certain size, but it's great for quick
> solutions and moderate sized data. If you need something more powerful
> look into something like Lucene.


thanks Robert,

-nathan


On 7/5/07, Robert Cummings < robert@interjinn.com> wrote:
>
> On Thu, 2007-07-05 at 22:26 -0400, Nathan Nobbe wrote:
> > Kevin,
> >
> > just like Daniel said,
> > > $sql .= "OR product_description *LIKE '%".$terms."%'"*;

> >
> > most of the *search engines* ive seen revolve around the use of the LIKE

>
> > construct<

> http://dev.mysql.com/doc/refman/5.1/...#operator_like
> >
> > which is a simplified regex mechanism for an SQL query [for MySQL at

> least,
> > probly other RDBMS' as well]

>
> Don't do that. Unless you have a teency weency set of data don't use
> LIKE syntax to match data. It's extremely inefficient and requires
> scanning the entire table. If you need to use MySQL use the MATCH
> AGAINST syntax since it will index the data and search much faster. I've
> heard tell it sucks beyond a certain size, but it's great for quick
> solutions and moderate sized data. If you need something more powerful
> look into something like Lucene.
>
> Cheers,
> Rob.
> --
> .------------------------------------------------------------.
> | InterJinn Application Framework - http://www.interjinn.com |
> :------------------------------------------------------------:
> | An application and templating framework for PHP. Boasting |
> | a powerful, scalable system for accessing system services |
> | such as forms, properties, sessions, and caches. InterJinn |
> | also provides an extremely flexible architecture for |
> | creating re-usable components quickly and easily. |
> `------------------------------------------------------------'
>
>


Reply With Quote
  #7 (permalink)  
Old 07-06-2007
tedd
 
Posts: n/a
Default Re: [PHP] About Website Search Engine

At 1:34 PM -0700 7/5/07, Kelvin Park wrote:
>I'm trying to build a search engine for my website (with php), it will have
>functions such as finding product names and their codes from the mysql
>database.
>Does anyone know any good tutorial or reference on any website, or any good
>books out there that you might recommend?
>I couldnt' find any decent one but only the ones that keep on saying, "use
>google search engine to search your website!" etc.
>Thanks!


While it's not a "write your own" solution, it does work:

http://sperling.com/examples/search/

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
Reply With Quote
  #8 (permalink)  
Old 07-18-2007
Nathan Nobbe
 
Posts: n/a
Default Re: [PHP] About Website Search Engine

late follow up on this, but i was poking around php.net the other day and
stumbled upon this:
http://www.xapian.org/

-nathan

On 7/6/07, tedd <tedd@sperling.com> wrote:
>
> At 1:34 PM -0700 7/5/07, Kelvin Park wrote:
> >I'm trying to build a search engine for my website (with php), it will

> have
> >functions such as finding product names and their codes from the mysql
> >database.
> >Does anyone know any good tutorial or reference on any website, or any

> good
> >books out there that you might recommend?
> >I couldnt' find any decent one but only the ones that keep on saying,

> "use
> >google search engine to search your website!" etc.
> >Thanks!

>
> While it's not a "write your own" solution, it does work:
>
> http://sperling.com/examples/search/
>
> Cheers,
>
> tedd
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:19 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0