ruby script/plugin install svn://svn.railsfreaks.com/projects/acts_as_solr/trunk
rake aborted!
Bad file descriptor - connect(2)
(See full trace by running task with --trace)
depot\vendor\plugins\acts_as_solr\solr directory\
java -jar start.jar
desc 'Starts Solr. on windows . Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.'
task :start_win do
begin
n = Net::HTTP.new('localhost', SOLR_PORT)
n.request_head('/').value
rescue Net::HTTPServerException #responding
puts "Port #{SOLR_PORT} in use" and return
rescue Errno::EBADF #not responding
Dir.chdir(SOLR_PATH) do
exec "java -Dsolr.data.dir=solr/data/#{ENV['RAILS_ENV']} -Djetty.port=#{SOLR_PORT} -jar start.jar"
sleep(5)
puts "#{ENV['RAILS_ENV']} Solr started sucessfuly on #{SOLR_PORT}, pid: #{pid}."
end
end
end
rake solr:start_win
class Job < ActiveRecord::Base
acts_as_solr :include => [:category], :fields=>[:name,:description,:resolution]
belongs_to :category
belongs_to :user
end
class Category < ActiveRecord::Base
has_many :jobs
acts_as_solr :include => [:jobs]
end
ruby script/console
Job.rebuild_solr_index
Category.rebuild_solr_index
@results = Job.find_by_solr("code monkey")
module ActsAsSolr
module PaginationExtension
def paginate_search(query, options = {})
options, page, per_page = wp_parse_options!(options)
pager = WillPaginate::Collection.new(page, per_page, nil)
options.merge!(:offset => pager.offset, :limit => per_page)
result = result = find_by_solr(query, options)
returning WillPaginate::Collection.new(page, per_page, result.total_hits) do |pager|
pager.replace result.docs
end
end
end
end
module ActsAsSolr::ClassMethods
include ActsAsSolr::PaginationExtension
end
def search
begin
@jobs =Job.paginate_search params[:query_string], :page => params[:page], :per_page => 10
@query_string=params[:query_string]
rescue
#handle any errors here
#flash[:notice] = 'There was a problem with your query'
@jobs = Job.paginate :page => params[:page]
end
end
<% form_tag :action => 'search' do %>
<%= text_field_tag :query_string , @query_string %>
<%= submit_tag "Search" %>
<% end %>
<p><b><%= pluralize @jobs.total_entries, 'job' %></b> found.</p>
<table>
<%= render :partial => 'job', :collection => @jobs %>
</table>
<%= will_paginate @jobs, :params =>{:query_string=> @query_string} -%>
will_paginate @jobs, :params =>{:query_string=> @query_string}
def search
begin
@jobs =Job.paginate_search params[:query_string], :page => params[:page], :per_page => 3
@query_string=params[:query_string]
rescue
#handle any errors here
#flash[:notice] = 'There was a problem with your query'
@jobs = Job.paginate :page => params[:page]
end
respond_to do |format|
format.html do
#If the request is a live search just return the rendered search results
#rather than the whole page
render :action => 'live_search.html.erb', :layout =>false if request.xml_http_request?
end
end
end
<%= observe_field(:query_string, :url =>{ :controller => :jobs, :action => :search }, :frequency => 0.5, :update => :search_results, :with => "'query_string=' + escape(value)") %>
July 2007 August 2007 September 2007 December 2007 January 2008 February 2008 March 2008 April 2008 June 2008 July 2008 August 2008 October 2008 November 2008 January 2009
Subscribe to Comments [Atom]