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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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! |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 > > |
|
|||
|
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. | `------------------------------------------------------------' |
|
|||
|
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. | > `------------------------------------------------------------' > > |
|
|||
|
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 |
|
|||
|
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 > > |
![]() |
| Thread Tools | |
| Display Modes | |
|
|