views:

150

answers:

1

I have gotten sorting working from my rails application using acts_as_solr for text fields, as seen below with Title.

I am having problems getting it to work for date.

My model has the following

class Article < ActiveRecord::Base

acts_as_solr :fields[:title, {:title_s=> :string}, {:created_at_d => :date}]

def title_s
  self.title
end

def created_at_d
  self.created_at
end

The following is being sent to the solr server:

path=/select params={wt=ruby&rows=10start=0&sort=created_at_d_d+asc&fl=pk_i,score&q=(+searchtext)..........

The solr code

Article.paginate_all_by_solr(searchString, :order=> "created_at_d asc", :page = page, :per_page => results_per_page, :total_entrieds => count)

Is there something obvious I am doing wrong? I am not sure that the {:created_at_d => :date} in the model is the correct way to set up the index for dates.

When I just coin it off of :created_at, I get the error around tokenized fields similar to that when I tried to sort against :title.

+1  A: 

Something was wrong with the index.

When I went into script/console and ran

Article.rebuild_solr_index

It did not index the date correctly.

I created a rake task from with the following site. http://henrik.nyh.se/2007/06/rake-task-to-reindex-models-for-acts_as_solr

When I ran

>rake solr:reindex

The index was created correctly and the date sorting started working.

Mark Redding