<?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>Pervasive Code &#187; XML</title>
	<atom:link href="http://www.pervasivecode.com/blog/category/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pervasivecode.com/blog</link>
	<description>Jamie Flournoy's Software Development Blog</description>
	<lastBuildDate>Wed, 01 Feb 2012 06:11:00 +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>Full Text Search refuses to be a black box</title>
		<link>http://www.pervasivecode.com/blog/2007/07/15/full-text-search-refuses-to-be-a-black-box/</link>
		<comments>http://www.pervasivecode.com/blog/2007/07/15/full-text-search-refuses-to-be-a-black-box/#comments</comments>
		<pubDate>Mon, 16 Jul 2007 02:48:56 +0000</pubDate>
		<dc:creator>Jamie Flournoy</dc:creator>
				<category><![CDATA[XML]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.pervasivecode.com/blog/2007/07/15/full-text-search-refuses-to-be-a-black-box/</guid>
		<description><![CDATA[Once upon a time, before Google pwn3d internet search, there were several competing definitions for full text search. Altavista more or less gave you results matching the exact strings you gave it, but in a crazy order that made it painful to use. Excite (my favorite back then) used a dictionary to achieve stemming and [...]]]></description>
			<content:encoded><![CDATA[<p>Once upon a time, before Google pwn3d internet search, there were several competing definitions for full text search. Altavista more or less gave you results matching the exact strings you gave it, but in a crazy order that made it painful to use. Excite (my favorite back then) used a dictionary to achieve stemming and synonym matches: searching for &#8216;dogs&#8217; would also match documents that contained &#8216;canines&#8217; or &#8216;dog&#8217;. Then Google blew them all away, and established a dominant set of expectations for how text search behaves.</p>
<p>I forgot about this, which is why I&#8217;m frustrated by the almost ridiculous complexity of the major server-side text search engines available right now. But it makes sense, once you learn what the options are.<br />
<span id="more-35"></span><br />
The first thing you have to decide is if you want to stick with an in-database search feature, meaning the one that comes with your SQL RDBMS of choice. If so, you get <a href="http://en.wikipedia.org/wiki/ACID">ACID</a> and hopefully <a href="http://en.wikipedia.org/wiki/Multiversion_concurrency_control">MVCC</a> features, which is probably why you&#8217;re using a SQL RDBMS in the first place: you&#8217;d like to get back the data that you put into it, even with multiuser access.</p>
<p>This option is just becoming decent in the last few years; typically you pay a penalty for the ACID and MVCC assurance, as well as for the smaller audience that uses that particular database. The factory installed radio is never as good as the one you order from <a href="http://www.crutchfield.com/">Crutchfield</a>, and likewise, the bundled thingamajig is never as good as the best available special-purpose thingamajig. But you get a few things in return: examples specific to your chosen database (duh), a simplified storage architecture, and probably some lower resource requirements.</p>
<p>By &#8220;simplified storage architecture&#8221; I mean that you don&#8217;t have to add your data to the database, and then also to the search engine, nor do you have to query the search engine first, and then possibly use the results to query the database if the search engine doesn&#8217;t contain everything you need. By &#8220;probably lower resource requirements&#8221; I mean that you&#8217;re not running two redundant but slightly differently optimized database servers: one SQL RDBMS and one specialized full text search server. Two redundant servers means double the storage, double the ram, plus or minus some variation in overhead (row size in bytes vs. page size, etc.). The full text index built into the database product will need a substantial amount of extra space for the indexes in memory and on disk, but almost certainly this will be less than a separate search server would need for the index and data, plus its own code, in memory and on disk.</p>
<p>An argument could be made for dumping the SQL RDBMS in favor of just using the dedicated full text search engine, but given that SQL RDMBSs tend to be the only game in town that offers unlimited ad-hoc querying, ACID, MVCC, and easy integration with all sorts of application languages and frameworks, I suspect that the folks making that argument either have really unusual requirements in mind, or are bozos who fall in love with architectures that work well for a few of their requirements and suck utterly at the remaining requirements.</p>
<p>There are quite a lot of those people out there. The same sort of suggestion has been made for object databases and XML databases in the past, and it turns out that the ones that blow away SQL RDBMSs in performance also lack one or more of the qualities that make SQL RDBMSs so useful. Putting those features back in tends to bring performance back down to a level close to that of the SQL RDBMS, and the argument for total replacement becomes weak. But the arguments, and arguers, remain.</p>
<p>But, perhaps your requirements for search performance are extreme: you need super duper fast search, which typically means you need a reasonable turnaround time on searches of a huge number of documents, with lots of users searching. The leading dedicated search engines lately seem to be <a href="http://en.wikipedia.org/wiki/Lucene">Lucene</a> (or one of its derivatives, such as <a href="http://ferret.davebalmain.com/trac/">Ferret</a>) or <a href="http://www.xapian.org/">Xapian</a>. In either case, you get super high performance, at the cost of some additional resources due to overlap with the SQL RDBMS, application complexity (two reads, two writes), and sysadmin complexity (a whole &#8216;nuther product to manage in order to keep the overall application up and running).</p>
<p>So, I&#8217;ll just accept that there are reasons to do either one, and maybe some corner cases in which just using a dedicated search engine makes sense instead of a SQL RDBMS. But let&#8217;s move on to the not-a-black-box aspect of full text search.</p>
<p>Here are the key issues:</p>
<ul>
<li>Full text search indices get huge quickly.</li>
<li>Some words are almost meaningless to searchers but are extremely commonly used.</li>
<li>Some words mean the same thing, or are variations of the same word.</li>
<li>Various kinds of coded character data (scientific notation, URLs, mailing addresses, etc.) are commonly embedded in searchable text.</li>
</ul>
<p>As a result of all of these, simply accelerating <code>"select * from cute_pet_stories WHERE UPPER(story) LIKE '%DOGS%'"</code> isn&#8217;t a viable approach. Instead, the search indexer requires additional information, such as the character encoding and language of the text being indexed, and uses that to simplify the text being indexed into root words (dog instead of dogs) that don&#8217;t include low-value words such as &#8220;a&#8221;, &#8220;the&#8221;, &#8220;of&#8221;, etc. (these are called <em>stop words</em>). Also, it may differentiate encoded data from regular language text, and handle it specially.</p>
<p>PostgreSQL includes a search engine called <a href="http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/">Tsearch2</a>, which is apparently <a href="http://people.planetpostgresql.org/xzilla/index.php?/archives/280-PostgreSQL-full-text-search-testing-PART-II.html">quite fast</a> if you&#8217;re willing to sacrifice size (big indexes) and write performance.</p>
<p>The implementation of a Tsearch2-indexed table is interesting: first you add a column to your table that&#8217;s just there to be indexed, and you fill it using text-mangling functions that do  stemming (dogs->dog), stop-word removal, and word counting. That leaves you with a column of type <code>tsvector</code>. Then you create an index on that column, and do your text queries against that index. You have to clean up your search text first, though, and similarly mangle it into an appropriately stemmed, stop-word-free <code>tsquery</code> object which itself can contain boolean expressions that will be used in the search process.</p>
<p>(There&#8217;s an <a href="http://code.google.com/p/acts-as-tsearch/">acts_as_tsearch</a> Rails plugin that attempts to simplify this into an idiom that makes more sense from a declarative standpoint. It looks pretty immature but I&#8217;m gonna give it a whirl anyway.)</p>
<p>Lucene does something similar, using Java classes it calls Analyzers to encapsulate the same kind of text-mangling behavior that Tsearch2 performs using its to_tsvector SQL function. Xapian <a href="http://www.xapian.org/docs/stemming.html">also has this same feature</a>, apparently from the <a href="http://snowball.tartarus.org/">same original source</a>. So the model of first preparing your text for indexability, then indexing it, then searching with similarly prepared query text, appears to be common if not universal.</p>
<p>Hopefully now you understand, as I now do, that full text search is inherently complicated, but not necessarily slow. All you need to do is understand the generic way that full text indexing and searching works, and then make a decision about integrated vs. standalone based on your setup.</p>
<p>I&#8217;m going to try Tsearch2 + acts_as_tsearch. I&#8217;ll let you know how it goes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pervasivecode.com/blog/2007/07/15/full-text-search-refuses-to-be-a-black-box/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Mozilla Platform&#8217;s Catch-22 Problem</title>
		<link>http://www.pervasivecode.com/blog/2007/04/30/the-mozilla-platforms-catch-22-problem/</link>
		<comments>http://www.pervasivecode.com/blog/2007/04/30/the-mozilla-platforms-catch-22-problem/#comments</comments>
		<pubDate>Mon, 30 Apr 2007 23:00:58 +0000</pubDate>
		<dc:creator>Jamie Flournoy</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[Thunderbird]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[labor]]></category>

		<guid isPermaLink="false">http://www.pervasivecode.com/blog/2007/04/30/the-mozilla-platforms-catch-22-problem/</guid>
		<description><![CDATA[Starting with Netscape 4.5, I&#8217;ve used Netscape, then Mozilla, then Thunderbird for email. I have a similar relationship with Firefox. I&#8217;ve watched with great hope and been disappointed over the years as Thunderbird bugs that really annoy me just&#8230; stay. I think I know why. It&#8217;s because Firefox and Thunderbird are built in such a [...]]]></description>
			<content:encoded><![CDATA[<p>Starting with Netscape 4.5, I&#8217;ve used Netscape, then Mozilla, then Thunderbird for email. I have a similar relationship with Firefox. I&#8217;ve watched with great hope and been disappointed over the years as Thunderbird bugs that really annoy me just&#8230; stay. I think I know why. It&#8217;s because Firefox and Thunderbird are built in such a way as to create a catch-22 situation &#8212; one that actually discourages new contributors.<br />
<span id="more-23"></span><br />
Here&#8217;s a good example of a bug that would seem to be trivial to fix: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=271222">&#8220;Entire message&#8221; quick search criteria is only the body</a>. You can&#8217;t search the entire message in Thunderbird. Can&#8217;t do it. Never been possible, as far as I know. Lots of people noticed it; it&#8217;s been marked as an &#8220;enhancement&#8221; in &#8220;New&#8221; status for years, even though it&#8217;s quite obviously a bug in my opinion. So, go to the source code, find the part where it decides what parts of the body to search, and make it search the whole thing. Should be easy, right?</p>
<p>Hell no. Firefox and Thunderbird are built using an <a href="http://www.mozilla.org/docs/#core">incredibly complicated set of tools and technologies</a> created by the Netscape and Mozilla folks, specifically for the purpose of building Firefox and Thunderbird.</p>
<p>Low-level stuff is written in C++, but if you know C++ already you still have to learn their coding standards and class libraries. Yeah, it&#8217;s great that they have coding standards and libraries; I&#8217;m just sayin&#8217;, that&#8217;s more stuff you have to learn in order to write a single line of low-level code.</p>
<p>High level stuff is in a combo of JavaScript and XML. Of course you have to learn the XUL platform stuff, so just knowing JavaScript and XML isn&#8217;t sufficient. You&#8217;ll also probably need to learn to use the low-level classes from the XUL side, so that you can get anything done.</p>
<p>Now if you want to actually build it, you&#8217;ll also need to understand their build system, and maybe their installer. You might need to learn how their help system, documentation system, internationalization sytem, etc. etc. work.</p>
<p>Now, I&#8217;m in awe of the monumental amount of new and working code that the Mozilla community has created. But the problem is just that: they built this huge application stack, and in order to get working on Firefox or Thunderbird, you have to learn a big chunk of that stack.</p>
<p>In theory, this wouldn&#8217;t be any more of a barrier than if they had coded to a single platform&#8217;s GUI widget set, class library, etc. But if I were to learn .NET and Visual Studio, or Cocoa, or GTK+, I would then have skills that I could use to work on thousands of other applications, either open source or commercial. That&#8217;s because those technologies are designed for general purpose application development.</p>
<p>The Mozilla application platform, however, has no life of its own outside of Mozilla. There&#8217;s an effort to extract it and make XULRunner a viable standalone platform that you could build your own XUL applications on, but that&#8217;s currently just a &#8220;stable developer preview&#8221;. What that means is that it&#8217;s still not suitable for use if you wanted to, say, <a href="http://www.songbirdnest.com/development">build your own iTunes killer</a> with it. It&#8217;s almost there, and maybe if you throw a lot of effort at it you could hack it so it&#8217;s usable, but as-is, it isn&#8217;t readily useful.</p>
<p>So, when a developer (such as myself) looks at this technology set, they ask themselves the question, &#8220;can I justify spending this much time learning all this stuff just to fix a little annoying bug?&#8221; If you spend a week or two downloading and learning and hacking and that gets you a certain amount of skill with the technology set, was it worth it? Maybe you could go get a job working with this technology set, except almost no one else is using it, not even open source projects.</p>
<p>When a corporation looks at this technology set, they have to ask a similar question: &#8220;is this the platform that will give me the best bang for my developer buck?&#8221; If they invest the time and money in hiring developers to work on this mostly-complete platform, so that they can then build an application with it, will it pay off? What about alternatives? Will the pool of available developers be so small that the project will fail before it starts?</p>
<p>These are not insurmountable barriers; some folks know some of these technologies already or only want to work on a corner of the application, so the overhead is smaller. Or, they may really want to work on Firefox or Thunderbird very badly. For an employer or open source project, their goals may match the goals of the original platform designers very well, in which case the payoff of using the Mozilla platform would be much higher than if you were (for example) making a Windows-only IM client.</p>
<p>But the barriers do exist, and they discourage the platform and the applications built with it from being improved. Developers don&#8217;t want to spend all that time learning things they can&#8217;t use elsewhere, and employers don&#8217;t want to pay developers to fix the platform so that other projects could find it useful. <a href="http://developer.mozilla.org/en/docs/XULRunner_Hall_of_Fame">A few projects do exist</a> and obviously somebody somewhere is working on Thunderbird bugs, but for a platform this sophisticated with this much mindshare (via Firefox), it&#8217;s remarkably unsuccessful in terms of adoption by developers.</p>
<p>All it would take to fix this would be some cash. Somebody could donate (or spend, in pursuit of a business goal) money toward the completion of XULRunner for general use, and toward clear and useful beginning developer documentation for the rest of the Mozilla platform.</p>
<p>Any takers? I could thrown in a hundred bucks or so, but I have a feeling this is more like a $50,000 undertaking. Otherwise we&#8217;re stuck waiting for Joost and a handful of others to slowly move it along.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pervasivecode.com/blog/2007/04/30/the-mozilla-platforms-catch-22-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

