<?xml version="1.0" encoding="UTF-8"?>
<posts type="array">
  <post>
    <author>Phil</author>
    <body>I had this issue recently when trying to sort items in an EmbeddedDocument.  Say you have a "Post" Document and a "Comment" EmbeddedDocument.  If you want to sort the comments by the created_at field (which is pretty likely), it isn't as easy as you would think, using MongoMapper (at the moment anyway).

However, there is a nice clean alternative that can be used to achieve the same results.  Simply use the "sort_by" method like so, passing in a symbol of the field to sort as a proc:-

&lt;script src="http://gist.github.com/281790.js?file=sort_mongomapper_embeddoc.rb"&gt;&lt;/script&gt;

...and for descending order:-

&lt;script src="http://gist.github.com/281791.js?file=mongomapper_sort_desc.rb"&gt;&lt;/script&gt;

Here is the original [google group thread](http://groups.google.com/group/mongomapper/browse_thread/thread/ec3c9cad236c6be5).</body>
    <created-at type="datetime">2010-01-20T11:55:23Z</created-at>
    <id type="integer">25</id>
    <prev-body nil="true"></prev-body>
    <prev-graphic nil="true"></prev-graphic>
    <preview-body nil="true"></preview-body>
    <title>Sorting an EmbeddedDocument with MongoMapper</title>
    <updated-at type="datetime">2010-01-20T11:57:59Z</updated-at>
  </post>
  <post>
    <author>Phil</author>
    <body>As you may of heard, I'm working on a new project ([meetee](http://meetee.me)), which will allow a more collaborative approach to meetings.

Over the last few days I've concentrating my efforts on getting the website design implemented using the following technologies:-

- Ruby on Rails
- MongoDB
- Compass CSS Framework

I've written about [Compass](i.github.com/chriseppstein/compass) before, and in this article (and the next) I want to concentrate on how I dealt with setting up **themes**.

Compass wouldn't be possible without [Sass](http://sass-lang.com/), the underlying language.  Sass allows you to define variables (among other things), and this becomes particularly useful when defining base colours for your website theme(s).  For instance, I defined the following base colours for my "Roast" theme.  _In the below example, see how you can perform operations on hex colours to make a lighter or darker shade.  This is important!  When you change the base colours, the correct shades will be applied to the derived colours._

The Roast Theme
---------------

&lt;script src="http://gist.github.com/243643.js?file=roast.sass"&gt;&lt;/script&gt;

![Roast Theme](/images/roast.png "Roast Theme")

Once I had this theme set-up, I used the defined variables throughout my Sass code in Compass.  This allowed me to create more "theme" sass files with different colours defined:-

The Raindrop Theme
------------------

&lt;script src="http://gist.github.com/243644.js?file=raindrop.sass"&gt;&lt;/script&gt;

![Raindrop Theme](/images/raindrop.png "Raindrop Theme")

And since I'm using Ruby on Rails I thought this would be fitting...

The Ruby Theme
--------------

&lt;script src="http://gist.github.com/243645.js?file=ruby.sass"&gt;&lt;/script&gt;

![Ruby Theme](/images/ruby.png "Ruby Theme")

Pretty damn cool!  As you can see, it will be very easy to integrate different themes at any time.  I'm really loving Compass and Sass!

In the next post I'll show how I structured the files and how I plan to load the appropriate CSS file dynamically.

If you haven't checked out [Compass](i.github.com/chriseppstein/compass), do it now - It's the future!</body>
    <created-at type="datetime">2009-11-26T21:02:57Z</created-at>
    <id type="integer">24</id>
    <prev-body nil="true"></prev-body>
    <prev-graphic nil="true"></prev-graphic>
    <preview-body nil="true"></preview-body>
    <title>A look at themes with Compass (Part 1)</title>
    <updated-at type="datetime">2009-11-26T21:24:04Z</updated-at>
  </post>
  <post>
    <author>Phil McClure</author>
    <body>Sunspot
-------

I had the recent pleasure of using [Sunspot](http://outoftime.github.com/sunspot/), which is powered by [Apache Solr](http://lucene.apache.org/solr/), to provide full-text search functionality for a Ruby on Rails recent project.

Installation/Configuration
--------------------------

Installing Sunspot is reasonably simple.  I installed the Sunspot gems along with the related [Sunspot Rails Plugin](http://github.com/outoftime/sunspot_rails), with the following commands:-

**Sunspot gems**

`sudo gem install outoftime-sunspot outoftime-sunspot_rails --source=http://gems.github.com`

**Sunspot Rails Plugin**

`script/plugin install git://github.com/outoftime/sunspot_rails.git`

Note that you will need to `require` the relevant library in the `Rakefile` which is in the base directory in your Rails app:-

`require 'sunspot/rails/tasks'`

Now you can generate the sunspot yaml configuration file with the built in generator:-

`script/generate sunspot`

This creates a `sunspot.yml` file in the rails `config` directory (more on this later). 

Indexing Fields in your Models
------------------------------

Sunspot, in comparison to the alternatives, has really clean and clear syntax for defining indexed fields in **the model**.  Here's an example:-

&lt;script src="http://gist.github.com/217569.js"&gt;&lt;/script&gt;

Here we can index string and text fields, or integer foreign keys or even foreign keys of a joining table.  Full-text searching is performed against the `text` fields and filtering can be performed against the other fields, in **the controller**, like this:-

&lt;script src="http://gist.github.com/217607.js"&gt;&lt;/script&gt;

Then rendered in **the view**, like this:-

&lt;script src="http://gist.github.com/217609.js"&gt;&lt;/script&gt;

Development Server
------------------

You can start the sunspot/solr server in a development environment by using a built-in rake task, just key the following command:-

`rake sunspot:solr:start`

Production Server
-----------------

While the rake task is great for development, it is not recommended for a production environment.  To start the sunspot/solr server in production use this command:-

`sunspot-solr start -- -p 8983 -d data/solr/myapp`

This starts a daemon process on the server.  You can check that the process is running by going to `http://hostname:8983/data/solr/myapp`.

You may be wondering how your Rails app knows to look in this location.  Remember the `sunspot.yml` file in the `config` directory?... That's where!

&lt;script src="http://gist.github.com/217617.js"&gt;&lt;/script&gt;

Pitfalls
--------

- Make sure you have java (jre) 1.5 &gt; installed

Links
-----

- [Sunspot](http://outoftime.github.com/sunspot/)
- [Sunspot Rails Plugin](http://github.com/outoftime/sunspot_rails)
- [Sunspot Docs](http://outoftime.github.com/sunspot/docs/index.html)</body>
    <created-at type="datetime">2009-10-24T16:46:03Z</created-at>
    <id type="integer">23</id>
    <prev-body nil="true"></prev-body>
    <prev-graphic nil="true"></prev-graphic>
    <preview-body nil="true"></preview-body>
    <title>Sunspot Full-text Search for Rails/Ruby</title>
    <updated-at type="datetime">2009-10-24T17:09:53Z</updated-at>
  </post>
</posts>
