<?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>Nico.Berlee.nl &#187; search</title>
	<atom:link href="http://nico.berlee.nl/tag/search/feed/" rel="self" type="application/rss+xml" />
	<link>http://nico.berlee.nl</link>
	<description>a digital portfolio</description>
	<lastBuildDate>Sat, 21 Jan 2012 21:31:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Instant Search in WordPress</title>
		<link>http://nico.berlee.nl/instant-search-in-wordpress/</link>
		<comments>http://nico.berlee.nl/instant-search-in-wordpress/#comments</comments>
		<pubDate>Tue, 25 Jul 2006 18:33:16 +0000</pubDate>
		<dc:creator>Nico</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[instant]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://nico.berlee.nl/instant-search-inwordpress/</guid>
		<description><![CDATA[When I updated to version 2.0.3 of wordpress, I came across a some ajax plugins. Live search 1.2 seemed great, but the version just did not work as described&#8230;. bummer&#8230; so I came across Ajaxsearch 0.1 and surprise, surprise, it actually worked. The idea behind Ajaxsearch, intentionally or not, is very smart. When you start [...]]]></description>
			<content:encoded><![CDATA[<p>When I updated to version 2.0.3 of wordpress, I came across a some ajax plugins. Live search 1.2 seemed great, but the version just did not work as described&#8230;. bummer&#8230; so I came across <a href="http://www.start.com.my/blog/ajaxsearch/">Ajaxsearch 0.1</a> and surprise, surprise, it actually worked. The idea behind Ajaxsearch, intentionally or not, is very smart.<span id="more-53"></span></p>
<p>When you start typing stuff into the searchbox, in the background the server is going to execute the php script that search every tie you type a letter. So in order to get results fast, you need a very sleek script that is doing just only that as optimal as possible.</p>
<p>Ajaxsearch works independently from wordpress includes and functions (which are great if you just load the page once <img src='http://nico.berlee.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ). So I started to integrate the instant search into my brajeshwar theme. As I wanted to see the text in the message aswell, and dropdown box below the search field was simply not an option. I didn&#8217;t want an autocomplete function, I wanted an instant search function! So now it pushes articles away if it needs space for the search results. Which is actually not so difficult at all if you know a bit of CSS markup&#8230;. because the ajaxsearch javascript uses innerhtml to drop the results in an div. which is practical because now I could drop</p>
<pre>&lt;div id="instantsearch"&gt;&lt;/div&gt;</pre>
<p>where-ever I want.</p>
<p>Then i dropped this in the CSS:</p>
<pre>#instantsearch div {
border-top: 1px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
background: #FFFFEE;
}
#instantsearch ul li {
background: none;
line-height: 15px;
padding: 0 15px;
font-size: 0.85em;
}
#instantsearch ul{
margin: 0;
}
#instantsearch h3 {
padding: 0px 15px;
margin-top: 0px;
text-transform: uppercase;
letter-spacing: 0.2em;
}
#instantsearch h3 {
padding: 20px 15px 10px;
text-transform: uppercase;
letter-spacing: 0.2em;
}
#col-right input {
width: 185px;
}</pre>
<p>Then I dropped the following html code inside a text widget, but if you don&#8217;t have the widget you can also put it inside the left or right sidebar</p>
<pre>&lt;script type="text/javascript" src="/ajaxsearch.js" mce_src="/ajaxsearch.js"&gt;&lt;/script&gt;&lt;form action="javascript:return false;" onsubmit="return false;"&gt;&lt;div&gt;&lt;input type="text" name="searchnicoberleenl1" value="Type to search instantly..."
onfocus="this.value = '';" onblur="this.value = 'Type to search instantly...';"
onkeyup="SendQuery(this.value)"/&gt;&lt;/div&gt;&lt;/form&gt;&lt;br /&gt;</pre>
<p>Please make sure you change the <em>searchnicoberleenl1</em> to something else. I had to use a name that is unique, I can&#8217;t set autocomplete=&#8221;off&#8221; because it&#8217;s not valid xhtml 1.0.</p>
<p>You can download the modified ajaxsearch.php and ajaxsearch.js from <a href="http://nico.berlee.nl/wp-content/uploads/modifiedajaxsearch.zip">here</a>. Put them in the root of your site.</p>
<p>So I start with ajaxsearch.js. I didn&#8217;t change much. The code does a good job, I only cleaned it up (tabs instead of spaces, for file download purpose) and removed the unnecessarily UnHideDiv() and HideDiv()</p>
<p>As you can see I changed a lot of things in ajaxsearch.php. First of all, the original version contains serious flaws:</p>
<ul>
<li>It does not take the post status in account, this means, that drafts and private posts are just as searchable as published posts</li>
<li>html code in the post will be also on the search result, which could rune your complete blog layout</li>
<li>The like query was not very sql server friendly when you have a big blog.</li>
</ul>
<p>The MySQL (like some other SQL servers) has a Full-Text-Search feature, which is a really great database search feature which almost gives you a functionality google inside your database. In a big blog you need such a feature because every keystroke must turn up a search result very fast.</p>
<p>The modified ajaxsearch.php uses the Full-Text-search feature and if this feature turns up with 0 results, it&#8217;s going to fallback on the old LIKE query. That&#8217;s because Full-Text-Search has a downside. In the MySQL implimentation it does not work on some known english stopwords and it&#8217;s start searching when 4 characters are given is set as default setting. In Boolean mode the sql server can give some results below 4 characters, but it&#8217;s not perfect.</p>
<p>Furthermore, you need to execute on sql query to enable the Full-Text-Search on that fields:</p>
<pre>CREATE FULLTEXT INDEX full_index ON `wp_posts`(
`post_title`,
`post_content`);</pre>
<p>In a 404 template you could use something like this:</p>
<pre>&lt;script type="text/javascript"&gt;
&lt;!--
SendQuery('&lt;?php echo trim(str_replace('/', ' ', str_replace('-', ' ', $_SERVER['REQUEST_URI']))); ?&gt;');
//--&gt;
&lt;/script&gt;</pre>
<p>Be sure to put this after the sidebar where the javascript file ajaxsearch.js is loaded <img src='http://nico.berlee.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I have no intension in releasing a real plugin. If you want to pack this in a real plugin, be my guest&#8230; (if you have permission of blewtooth)&#8230; anyway&#8230; If you in want to use something in this article, please do so&#8230; but it would be nice if you thank me in a comment in the code&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://nico.berlee.nl/instant-search-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

