<?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>spiral_code &#187; solr</title>
	<atom:link href="http://blog.trydionel.com/tag/solr/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.trydionel.com</link>
	<description></description>
	<lastBuildDate>Fri, 27 Aug 2010 00:35:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>A Few SunSpot Tips</title>
		<link>http://blog.trydionel.com/2009/11/19/a-few-sunspot-tips/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=a-few-sunspot-tips</link>
		<comments>http://blog.trydionel.com/2009/11/19/a-few-sunspot-tips/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 15:09:37 +0000</pubDate>
		<dc:creator>Jeff Tucker</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[solr]]></category>
		<category><![CDATA[sunspot]]></category>

		<guid isPermaLink="false">http://trydionel.wordpress.com/?p=36</guid>
		<description><![CDATA[I started playing with <a href="http://github.com/outoftime/sunspot">SunSpot</a> yesterday with the intent of using it as my full-text search provider in a Rails application.  The few how-tos I found show the beautiful DSL it provides, but unfortunately not much more.  Below are a few gotchas I ran into while getting it to work on my setup. <a href="http://blog.trydionel.com/2009/11/19/a-few-sunspot-tips/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I started playing with <a href="http://github.com/outoftime/sunspot">SunSpot</a> yesterday with the intent of using it as my full-text search provider in a Rails application.  The few how-tos I found show the beautiful DSL it provides, but unfortunately not much more.  Below are a few gotchas I ran into while getting it to work on my setup.</p>
<h3>1. Sunspot includes a development version of Solr</h3>
<p>There&#8217;s no need to download an official Solr release from Apache for development work.  Just install <code>sunspot</code> and you get Solr for free, complete with some nice Rake tasks.<br />
<code><br />
gem install sunspot<br />
rake sunspot:solr:start --starts the solr server<br />
rake sunspot:solr:stop --stops the solr server<br />
</code></p>
<h3>2. Using Sunspot in Rails requires the sunspot_rails gem</h3>
<p>This one was easy to solve, but still surprised me a bit.  The <code>sunspot</code> gem only provides the base interaction with the <code>Solr</code> server.  In order to get <code>ActiveRecord</code> integration, you need to add the <a href="http://github.com/outoftime/sunspot_rails"><code>sunspot_rails</code> gem</a>:</p>
<pre class="brush: ruby;">
# config/environment.rb
config.gem 'sunspot', :lib =&amp;gt; 'sunspot'
config.gem 'sunspot_rails', :lib =&amp;gt; 'sunspot/rails'

$ rake gems:install
</pre>
<h3>3. Text Analysis is setup in Solr, not in Sunspot</h3>
<p>It seems there&#8217;s not much written in the Sunspot documentation/groups about text analysis (such as word stemming, stop word filters, synonyms analysis, etc), and for good reason.  These settings are defined in Solr&#8217;s setup via the <code>schema.xml</code> file.  More details on Solr&#8217;s text analysis abilities can be found on <a href="http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters">Apache&#8217;s website.</a>  If you&#8217;re using the install you get with Sunspot, you can find this in <code>RAILS_ROOT/solr/conf/schema.xml</code>.</p>
<h3>4. Sunspot executes its <code>search</code> DSL in a new scope</h3>
<p>This one took me forever to figure out.  By default, any details passed into Sunspot.search are not evaluated in the current context.  This means that trying to search directly from the controller just doesn&#8217;t work as I expected.  There&#8217;s no mention of this in sunspot_rails&#8217; documentation, but <a href="http://outoftime.github.com/sunspot/docs/classes/Sunspot.html#M000006">there&#8217;s a brief snippet in sunspot&#8217;s</a>:</p>
<blockquote><p>If the block passed to search takes an argument, that argument will present the DSL, and the block will be evaluated in the calling context. This will come in handy for building searches using instance data or methods</p></blockquote>
<p>So, in order to search from the controller (or rather in the model, like you should), you&#8217;ll need to pass an argument to the <code>Sunspot.search</code> block:</p>
<pre class="brush: ruby;">
@search = Sunspot.search(Post) do |query|
query.keywords params[:query]
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.trydionel.com/2009/11/19/a-few-sunspot-tips/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
