<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Happy Web Diva &#187; PHP/MySQL</title>
	<atom:link href="http://www.happywebdiva.com/category/phpmysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.happywebdiva.com</link>
	<description>Musings of Anna Belle Leiserson</description>
	<lastBuildDate>Fri, 20 Nov 2009 02:56:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Boolean Search Made Easy By MySQL</title>
		<link>http://www.happywebdiva.com/2008/03/01/boolean-search-made-easy-by-mysql/</link>
		<comments>http://www.happywebdiva.com/2008/03/01/boolean-search-made-easy-by-mysql/#comments</comments>
		<pubDate>Sun, 02 Mar 2008 01:27:11 +0000</pubDate>
		<dc:creator>Anna Belle</dc:creator>
				<category><![CDATA[PHP/MySQL]]></category>

		<guid isPermaLink="false">http://www.happywebdiva.com/2008/03/01/boolean-search-made-easy-by-mysql/</guid>
		<description><![CDATA[Call me naive, but I never dreamed that one day I would be able to set up my own Boolean search &#8212; let alone call it easy. However, once you have the basics of PHP and MySQL down, it turns out it&#8217;s just that. My inner librarian basks in wonder. There are two essential parts. [...]]]></description>
			<content:encoded><![CDATA[<p> Call me naive, but I never dreamed that one day I would be able to set up my own Boolean search &#8212; let alone call it easy. However, once you have the basics of PHP and MySQL down, it turns out it&#8217;s just that.   My inner librarian basks in wonder.</p>
<p>There are two essential parts.</p>
<p>Part one is adding fulltext indexing to the columns you will be searching.  In MySQL use a query such as:</p>
<p><code>ALTER TABLE table ADD FULLTEXT INDEX (column1);</code></p>
<p>Part two is the query in PHP, which looks something like this:</p>
<p><code>$result = mysql_query(<br />
&nbsp;&nbsp;"SELECT *, " .<br />
&nbsp;&nbsp;"MATCH (" .<br />
&nbsp;&nbsp;&nbsp;&nbsp;"fulltextcolumn1, " .<br />
&nbsp;&nbsp;&nbsp;&nbsp;"fulltextcolumn2, " .<br />
&nbsp;&nbsp;&nbsp;&nbsp;"fulltextcolumn3)" .<br />
&nbsp;&nbsp;&nbsp;&nbsp;"AGAINST ('$keyword' IN BOOLEAN MODE) " .<br />
&nbsp;&nbsp;&nbsp;&nbsp;"AS Rank " .<br />
&nbsp;&nbsp;"FROM tablename " .<br />
&nbsp;&nbsp;"WHERE MATCH (" .<br />
&nbsp;&nbsp;&nbsp;&nbsp;"fulltextcolumn1, " .<br />
&nbsp;&nbsp;&nbsp;&nbsp;"fulltextcolumn2, " .<br />
&nbsp;&nbsp;&nbsp;&nbsp;"fulltextcolumn3)" .<br />
&nbsp;&nbsp;&nbsp;&nbsp;"AGAINST ('$keyword' IN BOOLEAN MODE)" .<br />
&nbsp;&nbsp;"ORDER BY Rank DESC");<br />
</code></p>
<p>The first MATCH is actually just to rank the results in the ORDER BY.  You don&#8217;t really need any of those lines, but they are just too cool to skip in my opinion.  Also, to get $keyword, chances are you will use a very simple form and POST the results.</p>
<p>For the particular Boolean commands to use, see the <a href="http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html">MySQL Reference Manual</a>.</p>
<p>And for those wanting to learn more, this fabulous technique from Chapter 5 my all-time favorite PHP/MySQL book: Larry Ullman&#8217;s <a href="http://www.dmcinsights.com/phpmysql2/">PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide</a> (2nd Edition).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.happywebdiva.com/2008/03/01/boolean-search-made-easy-by-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
