<?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>Eric&#039;s Tech Blog</title>
	<atom:link href="http://eric.lubow.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://eric.lubow.org</link>
	<description>Thoughts, musings, and other useless idealistic systems hoopla.</description>
	<lastBuildDate>Tue, 09 Mar 2010 11:45:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Changing Shoes For A Redesign</title>
		<link>http://eric.lubow.org/2010/musings/changing-shoes-for-a-redesign/</link>
		<comments>http://eric.lubow.org/2010/musings/changing-shoes-for-a-redesign/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 11:45:49 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Musings]]></category>
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=555</guid>
		<description><![CDATA[

]]></description>
			<content:encoded><![CDATA[<!-- Easy AdSense V2.87 -->
<!-- Post[count: 2] -->
<div class="ezAdsense adsense adsense-leadin" style="float:right;margin:12px;border:#027AC6 solid 1px;"  onmouseover="this.style.border='#027AC6 solid 1px'" onmouseout="this.style.border='#027AC6 solid 1px'""><script type="text/javascript"><!--
google_ad_client = "pub-4181193436431978";
/* 234x60, created 3/5/10, single unit */
google_ad_slot = "7232571800";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<!-- Easy AdSense V2.87 -->

<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fmusings%2Fchanging-shoes-for-a-redesign%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fmusings%2Fchanging-shoes-for-a-redesign%2F&amp;source=elubow&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>The best way to rethink things is to be in the shoes of your users.   Use your app how they use your app.  Try to take a fresh look at your application like you&#8217;ve never seen it before.  Would you change the location of the menu/navigation?  Would you change the actual menus/navigation?  Would you add a shortcut search box where there wasn&#8217;t one before?  Maybe you remove the advertising or move the place that the ads are located so that they are less intrusive&#8230;</p>
<p>The idea is that every so often you need to take a step back.  Looking at your application from your users perspective may well change how your entire application works.  I&#8217;m not saying this from a statistical analysis of the way people click and heatmaps and all that good stuff (though they do have their applications), I&#8217;m saying just a pure usability test from another perspective.  Where do the new users look? Where do they click? What&#8217;s the first thing they want to go to? Are you putting them through information overload?</p>
<p>So take a step back, change shoes and take a fresh look at your app. No statistics, no heatmaps, no preconceived notions about the problem you are trying to solve (I know this is easier said than done).  Just remember why you wrote your app in the first place.  Try the passion on for size again and see if that doesn&#8217;t stir things up a bit.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/musings/changing-shoes-for-a-redesign/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Speeding Up Your Selects and Sorts</title>
		<link>http://eric.lubow.org/2010/databases/mysql/speeding-up-your-selects-and-sorts/</link>
		<comments>http://eric.lubow.org/2010/databases/mysql/speeding-up-your-selects-and-sorts/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 13:30:07 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql tricks]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=585</guid>
		<description><![CDATA[

]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fdatabases%2Fmysql%2Fspeeding-up-your-selects-and-sorts%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fdatabases%2Fmysql%2Fspeeding-up-your-selects-and-sorts%2F&amp;source=elubow&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>When you are using a framework, they typically set your VARCHAR size automatically to <strong>255</strong>.  This is normally fine since you are letting the framework abstract you away from most of the SQL.  But if you interact with your SQL, there is a way to get a decent speed increase on your SELECTs and ORDER BYs when you are working with VARCHARs.</p>
<p>The VARCHAR data type is only variable character size for storage, not for sorting and buffering.  In fact, since the MySQL optimizer doesn&#8217;t know how big the data in that column can be, it has to allocate the maximum size possible for that column.  So for sorting and buffering of the <em>name</em> and <em>email</em> columns below would take up <strong>310</strong> bytes per row.<br />
<span id="more-585"></span></p>
<p>To fix that you should alter the size of your columns.  Imagine having the optimizer have to go through an additional 310 bytes for every row.  If there are 500k rows in the table time 310 bytes for each row, that can add up in the amount of memory that the optimizer has to use to perform the sorting/buffering.</p>
<p>Consider the following table of businesses:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:450px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">DESC</span> businesses;<br />
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----------------+--------------+------+-----+---------+----------------+</span><br />
<span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">FIELD</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">|</span> Type &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #66cc66;">|</span> Extra &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----------------+--------------+------+-----+---------+----------------+</span><br />
<span style="color: #66cc66;">|</span> id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">|</span> int<span style="color: #66cc66;">&#40;</span>11<span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">|</span> NO &nbsp; <span style="color: #66cc66;">|</span> PRI <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> &nbsp; &nbsp;<span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #66cc66;">|</span> <br />
<span style="color: #66cc66;">|</span> name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span>255<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> YES &nbsp;<span style="color: #66cc66;">|</span> &nbsp; &nbsp; <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> &nbsp; &nbsp;<span style="color: #66cc66;">|</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">|</span> <br />
<span style="color: #66cc66;">|</span> url &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span>255<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> YES &nbsp;<span style="color: #66cc66;">|</span> &nbsp; &nbsp; <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> &nbsp; &nbsp;<span style="color: #66cc66;">|</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">|</span> <br />
<span style="color: #66cc66;">|</span> email &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span>255<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> YES &nbsp;<span style="color: #66cc66;">|</span> &nbsp; &nbsp; <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> &nbsp; &nbsp;<span style="color: #66cc66;">|</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">|</span> <br />
<span style="color: #66cc66;">|</span> description &nbsp; &nbsp;<span style="color: #66cc66;">|</span> text &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">|</span> YES &nbsp;<span style="color: #66cc66;">|</span> &nbsp; &nbsp; <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> &nbsp; &nbsp;<span style="color: #66cc66;">|</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">|</span> <br />
<span style="color: #66cc66;">|</span> created_at &nbsp; &nbsp; <span style="color: #66cc66;">|</span> datetime &nbsp; &nbsp; <span style="color: #66cc66;">|</span> YES &nbsp;<span style="color: #66cc66;">|</span> &nbsp; &nbsp; <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> &nbsp; &nbsp;<span style="color: #66cc66;">|</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">|</span> <br />
<span style="color: #66cc66;">|</span> updated_at &nbsp; &nbsp; <span style="color: #66cc66;">|</span> datetime &nbsp; &nbsp; <span style="color: #66cc66;">|</span> YES &nbsp;<span style="color: #66cc66;">|</span> &nbsp; &nbsp; <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> &nbsp; &nbsp;<span style="color: #66cc66;">|</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">|</span> <br />
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----------------+--------------+------+-----+---------+----------------+</span><br />
7 rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span>0<span style="color: #66cc66;">.</span>00 sec<span style="color: #66cc66;">&#41;</span><br />
<br />
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> MAX<span style="color: #66cc66;">&#40;</span>LENGTH<span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> MAX<span style="color: #66cc66;">&#40;</span>LENGTH<span style="color: #66cc66;">&#40;</span>email<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> MAX<span style="color: #66cc66;">&#40;</span>LENGTH<span style="color: #66cc66;">&#40;</span>url<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> businesses;<br />
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------------------+--------------------+------------------+</span><br />
<span style="color: #66cc66;">|</span> MAX<span style="color: #66cc66;">&#40;</span>LENGTH<span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> MAX<span style="color: #66cc66;">&#40;</span>LENGTH<span style="color: #66cc66;">&#40;</span>email<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> MAX<span style="color: #66cc66;">&#40;</span>LENGTH<span style="color: #66cc66;">&#40;</span>url<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------------------+--------------------+------------------+</span><br />
<span style="color: #66cc66;">|</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;53 <span style="color: #66cc66;">|</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 36 <span style="color: #66cc66;">|</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 40 <span style="color: #66cc66;">|</span> <br />
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------------------+--------------------+------------------+</span><br />
1 row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.40</span> sec<span style="color: #66cc66;">&#41;</span></div></div>
<p>You can change the name to column sizes to 75 (name), 50 (email), and 100 (url).  But realistically you don&#8217;t want to chance things getting cut off, so it may be better off to settle on each column here being a VARCHAR(100).  Even that would save drastically on the space required to perform a sort and buffer the results.</p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2008/databases/mysql/mysql-encoded-uri-search-and-replace/' rel='bookmark' title='Permanent Link: MySQL Encoded URI Search and Replace'>MySQL Encoded URI Search and Replace</a></li>
<li><a href='http://eric.lubow.org/2009/system-administration/howto-recreate-devnull/' rel='bookmark' title='Permanent Link: HOWTO Recreate /dev/null'>HOWTO Recreate /dev/null</a></li>
<li><a href='http://eric.lubow.org/2009/databases/mysql/counting-email-addresses-by-domain-in-mysql/' rel='bookmark' title='Permanent Link: Counting Email Addresses By Domain in MySQL'>Counting Email Addresses By Domain in MySQL</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/databases/mysql/speeding-up-your-selects-and-sorts/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Database Read/Write Splitting in Frameworks/ORMs</title>
		<link>http://eric.lubow.org/2010/databases/mysql/database-readwrite-splitting-in-frameworksorms/</link>
		<comments>http://eric.lubow.org/2010/databases/mysql/database-readwrite-splitting-in-frameworksorms/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 13:00:27 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[scaling]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=563</guid>
		<description><![CDATA[
			
				
			
		
Although one of the primary ideas behind frameworks is to keep things as simple as possible, sometimes they create issues in the long run.  What I am about to discuss is something of a luxury problem (as scaling usually is), but it is a problem nonetheless.
When initially starting a project, whether you are using [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fdatabases%2Fmysql%2Fdatabase-readwrite-splitting-in-frameworksorms%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fdatabases%2Fmysql%2Fdatabase-readwrite-splitting-in-frameworksorms%2F&amp;source=elubow&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Although one of the primary ideas behind frameworks is to keep things as simple as possible, sometimes they create issues in the long run.  What I am about to discuss is something of a luxury problem (as scaling usually is), but it is a problem nonetheless.</p>
<p>When initially starting a project, whether you are using <a href="http://rubyonrails.org/">Ruby on Rails</a> (Ruby), <a href="http://www.djangoproject.com/">Django</a> (Python), <a href="http://cakephp.org/">CakePHP</a> (PHP), <a href="http://www.catalystframework.org/">Catalyst</a> (Perl), or any of the other 100s of frameworks in any of the languages out there, the first and most important thing to do is to get it out the door.  Once you have done that, it&#8217;s time to get users, fix bugs, and add features.  After you have done all that and you have a great web app, its time to think scaling. (Yes I realize that I have trivialized this process immensely, but its for a point, I promise).<br />
<span id="more-563"></span><br />
When starting to scale (whether its out or up) and you decide its time to add another database, its necessary to analyze your app and decide whether its read heavy or write heavy.  A lot of scaling comes in knowing your application and where its bottlenecks are.  Let&#8217;s assume that you are at the point that you need to add a database server.  What would be great is if you had a framework that allowed you to set some database servers as read-only in order to take load off the master.</p>
<p>In an abstract format, it would be a good idea to break out your SQL requirements into 2 functions: <strong>sql_write_query</strong> and <strong>sql_read_query</strong>.  Then have the functions go to your primary database server and slave database servers respectively.  The reason that you should do this instead of using a single function that sends the query to the &#8220;correct&#8221; location based on the SQL it finds is that your slave servers may be behind the master (which is the nature of replication) which could give you an incorrect result in your query.  This way, depending on the importance and type of the query, in your code you can choose the location that you want to send the query to.  The read queries where accuracy is extremely important can be sent to the database using <strong>sql_write_query</strong> and all others can be executed normally using your <strong>sql_read_query</strong> function.</p>
<p>How does this relate to frameworks and ORMs?  It would be very handy if frameworks provided a method to expand an application into splitting read and write queries that is native to the frameworks.  If it is native and isn&#8217;t hacked on afterward (like below), then you don&#8217;t have to muck around in the core code or write a plugin and you can stick to what you know best (which is your application).  That is not to say that one should prematurely optimize an application (which is a whole other issue that you need to be careful of) and build it out in a split read/write fashion from the beginning, but that there should be a native way for the application to be faster should you reach that point.</p>
<p>Building this out as a afterthought can be done like what&#8217;s below (the example is in Python but can be extrapolated to the language specific to the framework).</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:450px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">import</span> MySQLdb<br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> write_mysql_query<span style="color: black;">&#40;</span>query<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; conn = MySQLdb.<span style="color: black;">connect</span><span style="color: black;">&#40;</span>host = <span style="color: #483d8b;">&quot;dbvip1.example.com&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #dc143c;">user</span> = <span style="color: #483d8b;">&quot;root&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; passwd = <span style="color: #483d8b;">&quot;pass&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; db = <span style="color: #483d8b;">&quot;myapp&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; cursor = conn.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; cursor.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;SET AUTOCOMMIT=1&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; cursor.<span style="color: black;">execute</span><span style="color: black;">&#40;</span>query<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; cursor.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; conn.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> read_mysql_query<span style="color: black;">&#40;</span>query<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; conn = MySQLdb.<span style="color: black;">connect</span><span style="color: black;">&#40;</span>host = <span style="color: #483d8b;">&quot;slavedb1.example.com&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #dc143c;">user</span> = <span style="color: #483d8b;">&quot;root&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; passwd = <span style="color: #483d8b;">&quot;pass&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; db = <span style="color: #483d8b;">&quot;myapp&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; cursor = conn.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; cursor.<span style="color: black;">execute</span><span style="color: black;">&#40;</span>query<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; result = cursor.<span style="color: black;">fetchall</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; cursor.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; conn.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></div>
<p>You can even do things for the writer in a more transactional fashion using <em>START TRANSACTION</em> and <em>COMMIT</em> if you don&#8217;t like using <em>AUTOCOMMIT</em>.  You&#8217;ll also notice that there is a connect every time a query is executed.  A lot of people will have an initial gut reaction of a problem here.  In fact, since most of your queries will be taking place over a LAN with a pretty fast backplane (or some other variation of a high speed network), it&#8217;s probably negligible.  Taking the load off of your master and dispersing it onto slaves will make the most difference here.</p>
<p>All this is a very oversimplified way of taking this step, but it is something that frameworks should consider.  Even if its just in a plugin fashion which can be taken advantage of if the database server is getting overloaded.</p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2010/python/when-to-use-mysql-cursor-classes-in-python/' rel='bookmark' title='Permanent Link: When To Use MySQL Cursor Classes In Python'>When To Use MySQL Cursor Classes In Python</a></li>
<li><a href='http://eric.lubow.org/2009/python/python-multiprocessing-pools-and-mysql/' rel='bookmark' title='Permanent Link: Python Multiprocessing Pools and MySQL'>Python Multiprocessing Pools and MySQL</a></li>
<li><a href='http://eric.lubow.org/2009/python/pythons-mysqldb-2014-error-commands-out-of-sync/' rel='bookmark' title='Permanent Link: Python&#8217;s MySQLdb 2014 Error &#8211; Commands out of sync'>Python&#8217;s MySQLdb 2014 Error &#8211; Commands out of sync</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/databases/mysql/database-readwrite-splitting-in-frameworksorms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Textmate Minimap Plugin</title>
		<link>http://eric.lubow.org/2010/mac/textmate-minimap-plugin/</link>
		<comments>http://eric.lubow.org/2010/mac/textmate-minimap-plugin/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 12:00:35 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[editors]]></category>
		<category><![CDATA[textmate]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=556</guid>
		<description><![CDATA[
			
				
			
		
My editor of choice for most of what I do on the Mac (when I&#8217;m not in the shell using Vim) is Textmate.  I recently came across a neat plugin called the Textmate Minimap.  Essentially this plugin opens a map across the side of your Textmate window (like another drawer on the other [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fmac%2Ftextmate-minimap-plugin%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fmac%2Ftextmate-minimap-plugin%2F&amp;source=elubow&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>My editor of choice for most of what I do on the Mac (when I&#8217;m not in the shell using Vim) is <a href="http://macromates.com/">Textmate</a>.  I recently came across a neat plugin called the <a href="http://julianeberius.github.com/Textmate-Minimap/">Textmate Minimap</a>.  Essentially this plugin opens a map across the side of your Textmate window (like another drawer on the other side) and allows you to scroll full screens.  You can move the editing window screen by screen in the minimap.  This is equivalent to a visual page down.<br />
<span id="more-556"></span><br />
<div id="attachment_557" class="wp-caption aligncenter" style="width: 710px"><a href="http://eric.lubow.org/wp-content/uploads/2010/02/textmate-minimap2.jpg"><img src="http://eric.lubow.org/wp-content/uploads/2010/02/textmate-minimap2.jpg" alt="Textmate Minimap" title="Textmate Minimap" width="700" height="438" class="size-full wp-image-557" /></a><p class="wp-caption-text">Example of the minimap</p></div></p>
<p>This isn&#8217;t really handy if you have a lot of small files, but you can imagine the utility with larger files.  Now its still in beta stages, so be weary when you try it out.  Install it into Textmate as a bundle and use it as necessary.</p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2009/misc/more-wolframalpha-easter-eggs/' rel='bookmark' title='Permanent Link: More Wolframalpha Easter Eggs'>More Wolframalpha Easter Eggs</a></li>
<li><a href='http://eric.lubow.org/2009/mac/git-gui-on-mac-os-x/' rel='bookmark' title='Permanent Link: Git GUI on Mac OS X'>Git GUI on Mac OS X</a></li>
<li><a href='http://eric.lubow.org/2009/spam/more-efficient-spam-fighting-with-amavisd-logwatch/' rel='bookmark' title='Permanent Link: More Efficient SPAM Fighting with Amavisd-logwatch'>More Efficient SPAM Fighting with Amavisd-logwatch</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/mac/textmate-minimap-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Philosophical Python</title>
		<link>http://eric.lubow.org/2010/python/philosophical-python/</link>
		<comments>http://eric.lubow.org/2010/python/philosophical-python/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 13:30:43 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[Poetry]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=552</guid>
		<description><![CDATA[
			
				
			
		
Having spent a lot of time in the Perl world and even trying to write a Perl poem here and there, I decided to give some Python poetry a try.  It turned out to be a bit more philosophical than poetic. But it compiles and that&#8217;s what counts; even though it doesn&#8217;t do anything [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fpython%2Fphilosophical-python%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fpython%2Fphilosophical-python%2F&amp;source=elubow&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Having spent a lot of time in the Perl world and even trying to write a <a href="http://eric.lubow.org/category/perl/poetry/">Perl poem</a> here and there, I decided to give some Python poetry a try.  It turned out to be a bit more philosophical than poetic. But it compiles and that&#8217;s what counts; even though it doesn&#8217;t do anything useful (or anything at all).<br />
<span id="more-552"></span><br />
Since as people, we get the most out of something by filling in small spaces with our imagination (think of how comic books are so successful), fill in the words that might be missing.  Either way, enjoy.  Hope you get as much from reading it as I did from writing it.</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:450px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> people<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">try</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">class</span> Me<span style="color: black;">&#40;</span>being<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">mind</span> = MyThoughts<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">body</span> = MyBeing<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">soul</span> = MyEssence<br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> inner<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; answers = <span style="color: #008000;">None</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; answers.<span style="color: black;">seek</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mind_answers = <span style="color: #008000;">self</span>.<span style="color: black;">mind</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; body_answers = <span style="color: #008000;">self</span>.<span style="color: black;">body</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; soul_answers = <span style="color: #008000;">self</span>.<span style="color: black;">soul</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; answers = <span style="color: #008000;">reduce</span><span style="color: black;">&#40;</span>mind_answers, body_answers, soul_answers<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> MeaningOfLife <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #ff7700;font-weight:bold;">in</span> answers:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">raise</span> Awareness, <span style="color: #483d8b;">&quot;Searching for meaning&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; answers = <span style="color: #008000;">filter</span><span style="color: black;">&#40;</span>Intelligence, mind_answers, body_answers, soul_answers<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; answers.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> answers<br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">except</span> Awareness, MeaningOfLife:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> MeaningOfLife</div></div>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2009/python/python-multiprocessing-pools-and-mysql/' rel='bookmark' title='Permanent Link: Python Multiprocessing Pools and MySQL'>Python Multiprocessing Pools and MySQL</a></li>
<li><a href='http://eric.lubow.org/2010/python/when-to-use-mysql-cursor-classes-in-python/' rel='bookmark' title='Permanent Link: When To Use MySQL Cursor Classes In Python'>When To Use MySQL Cursor Classes In Python</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/python/philosophical-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sortfix Or A Next Generation Search Tool</title>
		<link>http://eric.lubow.org/2010/seo/sortfix-or-a-next-generation-search-tool/</link>
		<comments>http://eric.lubow.org/2010/seo/sortfix-or-a-next-generation-search-tool/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 14:45:25 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=548</guid>
		<description><![CDATA[
			
				
			
		
Although SortFix has been around for a while, I hadn&#8217;t heard of it until recently.  I also didn&#8217;t really have a reason to give it a try because the vast majority of my Google searches were providing me with the results I was looking for.
The idea here is that you can do a normal [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fseo%2Fsortfix-or-a-next-generation-search-tool%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fseo%2Fsortfix-or-a-next-generation-search-tool%2F&amp;source=elubow&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Although <a href="http://www.sortfix.com/">SortFix</a> has been around for a while, I hadn&#8217;t heard of it until recently.  I also didn&#8217;t really have a reason to give it a try because the vast majority of my Google searches were providing me with the results I was looking for.</p>
<p>The idea here is that you can do a normal search for something and then you will be presented with a screen that will allow you to narrow down your search using a graphical user interface (GUI).  This will produce a search similar to something that a power searcher would do in Google.  After doing this a few times, it becomes fairly evident how its done and one could start &#8220;power searching&#8221; on their own.<br />
<span id="more-548"></span><br />
Now what&#8217;s exciting to me here is the potential.  SortFix currently only uses Google as a backend search engine.  There is nothing wrong with that considering that most of us only stick to one search engine anyway.  However it would be great if SortFix could act as a meta search engine (a search engine that searches multiple other search engines) to do power searches and search the major players using your search terms, pair down the dupes and give you the results.  Technically speaking, I am aware that this is no trivial task.  But a unified search engine like that would certainly help quite a bit with finding what you&#8217;re looking for in a difficult search.</p>
<p>If you haven&#8217;t seen SortFix, then I&#8217;d head on over there.  It&#8217;s a concept with some great potential and a cool user friendly searching style.</p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2010/seo/social-searchs-effect-on-seo/' rel='bookmark' title='Permanent Link: Social Search&#8217;s Effect on SEO'>Social Search&#8217;s Effect on SEO</a></li>
<li><a href='http://eric.lubow.org/2007/perl/perl-modules-introduction/' rel='bookmark' title='Permanent Link: Perl Modules Introduction'>Perl Modules Introduction</a></li>
<li><a href='http://eric.lubow.org/2009/seo/remembering-that-content-is-king/' rel='bookmark' title='Permanent Link: Remembering that Content Is King'>Remembering that Content Is King</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/seo/sortfix-or-a-next-generation-search-tool/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Social Search&#8217;s Effect on SEO</title>
		<link>http://eric.lubow.org/2010/seo/social-searchs-effect-on-seo/</link>
		<comments>http://eric.lubow.org/2010/seo/social-searchs-effect-on-seo/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 16:36:50 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=545</guid>
		<description><![CDATA[
			
				
			
		
There always seems to be something affecting your SEO rankings.  Most recently, people have had issues with personalized search.  Another kink in the chain may be social search.
The first thing is that Social Search can&#8217;t replace Hyptertext search (such as Google/Yahoo!/Bing/etc).  Social search has 3 inherent drawbacks, time to receive information, credibility [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fseo%2Fsocial-searchs-effect-on-seo%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fseo%2Fsocial-searchs-effect-on-seo%2F&amp;source=elubow&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>There always seems to be something affecting your SEO rankings.  Most recently, people have had issues with personalized search.  Another kink in the chain may be social search.</p>
<p>The first thing is that Social Search can&#8217;t replace Hyptertext search (such as Google/Yahoo!/Bing/etc).  Social search has 3 inherent drawbacks, time to receive information, credibility of the source, and subject/objectivity.  Technically subjectivity is an issue with hypertext searches as well, but since the information is considered more permanent, people tend to be a little less opinionated and a little more objective (if the information is factual).<br />
<span id="more-545"></span><br />
According to a recent <a href="http://bits.blogs.nytimes.com/2010/02/05/a-search-engine-that-relies-on-humans/">NY Times article</a>, the majority of social searches are answered within 10 minutes.  In our culture, 10 minutes is a long time to wait.  We are all about instant gratification.  With regard to credibility, most of the time social searches are requests for opinions, so credibility isn&#8217;t an issue.  What one thinks of a restaurant or some other establishment is generally an opinion based question.</p>
<p>Ultimately I don&#8217;t believe there will be a direct impact on SEO.  Social search just aim to fill a different niche.  People have a different goal in mind when performing a social search than when they are performing a non-social (hypertext) search.</p>
<p>The one thing that this article in the times neglected to mention is that a lot of the hypertext search results are becoming social.  With the hypertext search engines indexing sites like <a href="http://www.yelp.com/">Yelp</a> and <a href="http://www.tripadvisor.com/">TripAdvisor</a> for example, they are already allow social search results in a hypertext search engine.  Therefore social search engines will need a wholly different approach to searching to be effective.</p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2010/seo/sortfix-or-a-next-generation-search-tool/' rel='bookmark' title='Permanent Link: Sortfix Or A Next Generation Search Tool'>Sortfix Or A Next Generation Search Tool</a></li>
<li><a href='http://eric.lubow.org/2010/seo/seo-and-cross-domain-content-syndication/' rel='bookmark' title='Permanent Link: SEO and Cross-Domain Content Syndication'>SEO and Cross-Domain Content Syndication</a></li>
<li><a href='http://eric.lubow.org/2009/misc/social-media-information-propagation/' rel='bookmark' title='Permanent Link: Social Media Information Propagation'>Social Media Information Propagation</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/seo/social-searchs-effect-on-seo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Model Specific Formatted Search Results Using Thinking Sphinx</title>
		<link>http://eric.lubow.org/2010/ruby/rails/model-specific-formatted-search-results-using-thinking-sphinx/</link>
		<comments>http://eric.lubow.org/2010/ruby/rails/model-specific-formatted-search-results-using-thinking-sphinx/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 14:15:23 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[sphinx]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=538</guid>
		<description><![CDATA[
			
				
			
		
Having recently implemented Thinking Sphinx on one of my web sites, I thought it would be cool to be able to search every indexed model.  With Thinking Sphinx, it&#8217;s easy to have a bunch of different classes returned in the results.  The tougher part is displaying them in a way that is organized [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fruby%2Frails%2Fmodel-specific-formatted-search-results-using-thinking-sphinx%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fruby%2Frails%2Fmodel-specific-formatted-search-results-using-thinking-sphinx%2F&amp;source=elubow&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Having recently implemented <a href="http://freelancing-god.github.com/ts/en">Thinking Sphinx</a> on one of my web sites, I thought it would be cool to be able to search every indexed model.  With Thinking Sphinx, it&#8217;s easy to have a bunch of different classes returned in the results.  The tougher part is displaying them in a way that is organized (although admittedly not very DRY).<br />
<span id="more-538"></span><br />
Let&#8217;s start out with the controller method for search results (<strong>app/controllers/search_controller.rb</strong>):</p>
<div class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> result<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> !params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:model</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?<br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@model</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:model</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@model</span> = <span style="color:#996600;">&quot;ThinkingSphinx&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@query</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:search</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:query</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@results</span> = Search.<span style="color:#9900CC;">model_search</span><span style="color:#006600; font-weight:bold;">&#40;</span>@model, <span style="color:#0066ff; font-weight:bold;">@query</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>Also, let&#8217;s make sure we define the actual search model.  I define it in a separate search library (<strong>lib/search.rb</strong>).  This is the relevant snippet of code:</p>
<div class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">model_search</span><span style="color:#006600; font-weight:bold;">&#40;</span>model, keywords, var = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@search_options</span> = <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> var<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:page</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> 1,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:per_page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 15 <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@search_options</span>.<span style="color:#9900CC;">merge</span>!<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;@relevance DESC&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:sort_mode</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:expr</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:sort_by</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;@weight * @weight&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; model.<span style="color:#9900CC;">constantize</span>.<span style="color:#9900CC;">search</span><span style="color:#006600; font-weight:bold;">&#40;</span>keywords, <span style="color:#0066ff; font-weight:bold;">@search_options</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>Assuming that we are working with the all models search, where the above model is <em>ThinkingSphinx</em>, let&#8217;s iterate over the search results with this code in the view (<strong>app/views/search/results.html.erb</strong>):</p>
<div class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@results</span>.<span style="color:#9900CC;">total_entries</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
<span style="color:#006600; font-weight:bold;">&lt;</span>div id=<span style="color:#996600;">&quot;localLocationList&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;</span>ul <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;list&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#0066ff; font-weight:bold;">@results</span>.<span style="color:#5A0A0A; font-weight:bold;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>result<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;</span>li<span style="color:#006600; font-weight:bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span>= display_search_result<span style="color:#006600; font-weight:bold;">&#40;</span>result<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;/</span>li<span style="color:#006600; font-weight:bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;/</span>ul<span style="color:#006600; font-weight:bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;</span>div <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;clear&quot;</span><span style="color:#006600; font-weight:bold;">&gt;&lt;/</span>div<span style="color:#006600; font-weight:bold;">&gt;</span><br />
<span style="color:#006600; font-weight:bold;">&lt;/</span>div<span style="color:#006600; font-weight:bold;">&gt;</span><br />
<span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></div></div>
<p>And the view helper (<strong>app/helpers/search_helper.rb</strong>):</p>
<div class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">def</span> display_search_result<span style="color:#006600; font-weight:bold;">&#40;</span>result<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#CC0066; font-weight:bold;">eval</span> <span style="color:#996600;">&quot;render :partial =&gt; '#{result.class.to_s.downcase.pluralize}/result',<br />
&nbsp; &nbsp; :locals =&gt; { :result =&gt; result }&quot;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>The interesting thing about this bit of code is the <strong>eval</strong>.  The <strong>eval</strong> on each iteration decides which search result partial to display based on the class and then passes the result to the partial for display.  So if the result has a class of <em>Business</em>, the partial <strong>app/views/businesses/_result.html.erb</strong> will be rendered.  This is a quick example of a search result partial:</p>
<div class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&lt;</span>span id=<span style="color:#996600;">&quot;localBizName&quot;</span><span style="color:#006600; font-weight:bold;">&gt;&lt;</span> <span style="color:#006600; font-weight:bold;">%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> result.<span style="color:#9900CC;">name</span>, business_path<span style="color:#006600; font-weight:bold;">&#40;</span> result <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;&lt;/</span>span<span style="color:#006600; font-weight:bold;">&gt;&lt;</span>br <span style="color:#006600; font-weight:bold;">/&gt;</span><br />
<span style="color:#006600; font-weight:bold;">&lt;</span>p <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;smallOffset&quot;</span><span style="color:#006600; font-weight:bold;">&gt;&lt;</span> <span style="color:#006600; font-weight:bold;">%</span>= truncate<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;#{result.description}&quot;</span>, :<span style="color:#5A0A0A; font-weight:bold;">length</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">128</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;&lt;/</span>p<span style="color:#006600; font-weight:bold;">&gt;</span></div></div>
<p>This is useful because all models don&#8217;t have the same characteristics.  By creating a search result partial for each model type, this can be reused for consistent looking search results around your webapp.  If the search is model specific, the same result partial will be used in every iteration over the results.  If the search is model agnostic, then you can display your search results in a consistent manner.</p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2010/seo/sortfix-or-a-next-generation-search-tool/' rel='bookmark' title='Permanent Link: Sortfix Or A Next Generation Search Tool'>Sortfix Or A Next Generation Search Tool</a></li>
<li><a href='http://eric.lubow.org/2009/ruby/rails/adding-an-average-column-to-a-model/' rel='bookmark' title='Permanent Link: Adding An Average Column To A Model'>Adding An Average Column To A Model</a></li>
<li><a href='http://eric.lubow.org/2008/databases/mysql/mysql-encoded-uri-search-and-replace/' rel='bookmark' title='Permanent Link: MySQL Encoded URI Search and Replace'>MySQL Encoded URI Search and Replace</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/ruby/rails/model-specific-formatted-search-results-using-thinking-sphinx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SEO and Cross-Domain Content Syndication</title>
		<link>http://eric.lubow.org/2010/seo/seo-and-cross-domain-content-syndication/</link>
		<comments>http://eric.lubow.org/2010/seo/seo-and-cross-domain-content-syndication/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 11:45:02 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[syndication]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=535</guid>
		<description><![CDATA[
			
				
			
		
When dealing with content syndication, one is occasionally in the situation where you are not the higher ranking site in search engines.  You might rank #4 for an article and in that same search, your syndicated content may be ranked #1.  What&#8217;s the best way to deal with this?
After much reading and discussion, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fseo%2Fseo-and-cross-domain-content-syndication%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fseo%2Fseo-and-cross-domain-content-syndication%2F&amp;source=elubow&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>When dealing with content syndication, one is occasionally in the situation where you are not the higher ranking site in search engines.  You might rank #4 for an article and in that same search, your syndicated content may be ranked #1.  What&#8217;s the best way to deal with this?</p>
<p>After much reading and discussion, I believe that you have a few options.<br />
<span id="more-535"></span><br />
The first is taking advantage of the most recent addition to the cross-domain <strong>rel=canonical</strong> link element.  You can read up on it more <a href="http://googlewebmastercentral.blogspot.com/2009/12/handling-legitimate-cross-domain.html">here</a>.  If you can talk to the publishing group and get them to allow the addition of the canonical link relationship, then you will get credit where credit is due (and deserved).</p>
<p>The reason that this can sometimes be an issue is that a lot of SEO types are not comfortable with when and how to use this link relationship and over use it or point it to their homepage for more link juice. That&#8217;s not the idea here.  The idea is to prevent duplicate content from being index and to allot credit to the deserving party.</p>
<p>The second is to try to take advantage of the syndicate publishing networks credibility and publish a blurb at the bottom of every article.  Look at the bottom of every <a href="http://cnet.com/">CNET</a> article as an example.  There is a blurb about every author with a link. That link could be to the author&#8217;s site or to an author&#8217;s bio page.</p>
<p>Lastly, you need to make sure that the article links back to your site.  This is again taking advantage of the link juice and credibility that the higher ranking site can bring to your natural search ranking.</p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2009/seo/remembering-that-content-is-king/' rel='bookmark' title='Permanent Link: Remembering that Content Is King'>Remembering that Content Is King</a></li>
<li><a href='http://eric.lubow.org/2010/seo/social-searchs-effect-on-seo/' rel='bookmark' title='Permanent Link: Social Search&#8217;s Effect on SEO'>Social Search&#8217;s Effect on SEO</a></li>
<li><a href='http://eric.lubow.org/2007/perl/perl-modules-introduction/' rel='bookmark' title='Permanent Link: Perl Modules Introduction'>Perl Modules Introduction</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/seo/seo-and-cross-domain-content-syndication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Being Smart is all about Being Resourceful</title>
		<link>http://eric.lubow.org/2010/musings/being-smart-is-all-about-being-resourceful/</link>
		<comments>http://eric.lubow.org/2010/musings/being-smart-is-all-about-being-resourceful/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 12:45:48 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Musings]]></category>
		<category><![CDATA[rants]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=532</guid>
		<description><![CDATA[
			
				
			
		
The internet us the ability to not while keeping up the appearance that we do.  Now that&#8217;s not to say that you should be a know it all, but you should definitely know how and where to get information if you need it.  If you use a specific open source technology at work, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fmusings%2Fbeing-smart-is-all-about-being-resourceful%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Feric.lubow.org%2F2010%2Fmusings%2Fbeing-smart-is-all-about-being-resourceful%2F&amp;source=elubow&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>The internet us the ability to not while keeping up the appearance that we do.  Now that&#8217;s not to say that you should be a know it all, but you should definitely know how and where to get information if you need it.  If you use a specific open source technology at work, then you need to know how to support (because odds are, it was written by a few interested people and doesn&#8217;t have a company behind it).  So you should know where the forums are, where the documentation is, where the mailing lists and the mailing list archives are, etc.  Do they have an IRC channel where you can talk to live users who might be able to help on a more immediate basis?  Maybe there was an even a book written that you can get your hands on, a PDF, or even a screencast.  If you lucky, you might write a Tweet about your frustration and one of the products creators will answer (which happened to me recently).<br />
<span id="more-532"></span><br />
The best part about all this is the internet is the enabler.  It&#8217;s searchable, indexed and provides you many methods of finding the answer to your (or other peoples) questions.  Why am I telling you all this obvious information?  Because its why I write my blog.  People who need help need to be able to search for it.  Most of the things I write about here are specific problems with answers that I figured out or aggregated from reading various things around the web.  So be resourceful, use what&#8217;s out there and then document it.  You may save yourself (and maybe me) a lot of time.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/musings/being-smart-is-all-about-being-resourceful/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
