<?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>Binary Logic &#187; modifiers</title>
	<atom:link href="http://www.binarylogic.com/tag/modifiers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.binarylogic.com</link>
	<description>Ben Johnson's thoughts and programming techniques</description>
	<lastBuildDate>Sat, 23 Jan 2010 21:19:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Searchlogic 1.3.0 &#8211; Adding modifiers into the mix</title>
		<link>http://www.binarylogic.com/2008/10/02/searchlogic-1-3-0-adding-modifiers-into-the-mix/</link>
		<comments>http://www.binarylogic.com/2008/10/02/searchlogic-1-3-0-adding-modifiers-into-the-mix/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 12:40:00 +0000</pubDate>
		<dc:creator>benjohnson</dc:creator>
				<category><![CDATA[Searchlogic]]></category>
		<category><![CDATA[modifiers]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[searchgasm]]></category>

		<guid isPermaLink="false">0/2009/03/23/searchlogic-1-3-0-adding-modifiers-into-the-mix</guid>
		<description><![CDATA[Searchlogic 1.3.0 was released today and has some pretty cool features, mainly modifiers. I&#8217;m going to assume you know what Searchlogic is. If you don&#8217;t, you&#8217;re missing out. Take a quick glance at the readme on github, otherwise this article probably won&#8217;t make a whole lot of sense.
        [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/binarylogic/searchlogic">Searchlogic 1.3.0</a> was released today and has some pretty cool features, mainly modifiers. I&#8217;m going to assume you know what <a href="http://github.com/binarylogic/searchlogic">Searchlogic</a> is. If you don&#8217;t, you&#8217;re missing out. Take <a href="http://github.com/binarylogic/searchlogic">a quick glance at the readme</a> on github, otherwise this article probably won&#8217;t make a whole lot of sense.</p>
<p>            <span id="more-44"></span></p>
<h2>Why modifiers are necessary?</h2>
<p>ActiveRecord does a great job when it comes to keeping your code database agnostic. But I feel like it neglected searching when it came to that goal. What if you want to find all records that were created after 7am? Depending on your database you would have to do something like the following:</p>
<pre><code>MySQL:        HOUR(created_at)
PostgreSQL:   date_part('hour', created_at)
SQLite:       strftime('%H', created_at)
</code></pre>
<p>All of a sudden your app is not database agnostic. Oh no!</p>
<p>All of that bragging to your girlfriend about how you can switch databases in a matter of minutes was all a lie. How&#8217;s she going to feel when she finds out HOUR(created_at) is a MySQL specific function? Searchlogic to the rescue!</p>
<h2>Searchlogic modifiers</h2>
<p>Remember how you can do this in searchlogic?</p>
<pre class="cobalt">
<span class="Support">User</span><span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">all</span></span><span class="Punctuation">(</span><span class="Constant"><span class="Punctuation">:</span>condition</span> <span class="Punctuation">=&gt;</span> <span class="Punctuation">{</span><span class="Constant"><span class="Punctuation">:</span>created_at_gt</span> <span class="Punctuation">=&gt;</span> <span class="Support">Time</span><span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">parse</span></span><span class="Punctuation">(</span><span class="String"><span class="Punctuation">&quot;</span>Jan 1, 2008<span class="Punctuation">&quot;</span></span><span class="Punctuation">)</span><span class="Punctuation">}</span><span class="Punctuation">)</span>
<span class="Comment"><span class="Punctuation">#</span> =&gt; &quot;created_at &gt; 2008-01-01 00:00:00</span>
</pre>
<p>Now you can do this too:</p>
<pre class="cobalt">
<span class="Support">User</span><span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">all</span></span><span class="Punctuation">(</span><span class="Constant"><span class="Punctuation">:</span>conditions</span> <span class="Punctuation">=&gt;</span> <span class="Punctuation">{</span><span class="Constant"><span class="Punctuation">:</span>hour_of_created_at_gt</span> <span class="Punctuation">=&gt;</span> <span class="Constant">10</span><span class="Punctuation">}</span><span class="Punctuation">)</span>
<span class="Comment"><span class="Punctuation">#</span> =&gt; HOUR(created_at) &gt; 10</span>
</pre>
<p>or this:</p>
<pre class="cobalt">
<span class="Support">User</span><span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">all</span></span><span class="Punctuation">(</span><span class="Constant"><span class="Punctuation">:</span>conditions</span> <span class="Punctuation">=&gt;</span> <span class="Punctuation">{</span><span class="Constant"><span class="Punctuation">:</span>tan_of_sin_of_cos_of_minute_of_created_at_gt</span> <span class="Punctuation">=&gt;</span> <span class="Constant">20</span><span class="Punctuation">}</span><span class="Punctuation">)</span>
<span class="Comment"><span class="Punctuation">#</span> =&gt; TAN(SIN(COS(MINUTE(created_at)))) &gt; 20</span>
</pre>
<p>What the hell was that? That was me making the point that you can chain modifiers. Obviously a very unrealistic example, but cool none-the-less.</p>
<p><a href="http://github.com/binarylogic/searchlogic">Check out the readme for a list of modifiers</a> and <a href="http://github.com/binarylogic/searchlogic/tree/master/CHANGELOG.rdoc">check out the changelog for a complete list of changes</a></p>
<p>What do you think?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarylogic.com/2008/10/02/searchlogic-1-3-0-adding-modifiers-into-the-mix/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
