ruby 2.1.5
rails 3.2.3
In my gemfile, I have:
gem 'sunspot_rails'
gem 'sunspot_solr'
In my tickets_controller.rb, I have the following:
def index
params[:direction] ||= "desc"
params[:sort] ||= "requested_date_start"
@tickets = Ticket.solr_search( include: [:customer_info, :customer, :executor, :notes] ){
fulltext params[:query] if params[:query].present?
with :status, (params[:status] || params[:filter]) if (params[:status] || params[:filter]).present?
order_by( params[:sort], params[:direction] ) if params[:sort].present? && params[:direction].present?
paginate :page => params[:page], per_page: params[:per_page]
}.results
render partial: 'tickets' if request.xhr?
end
In my ticket.rb, I have:
searchable do
time(:deleted_at)
text :services do services.map(&:name) end
text :inventories do inventories.map(&:name) end
text :requested_date_start
text :number
text :customer_phone do customer_info.try(&:phone) end
text :sp_name do executor.try(&:full_name) end
text :specialties do specialties.map(&:top_code) end
double :number
string :customer_id
string :executor_id
string :id
string :technician_ids, multiple: true
string :customer_location_id, using: :location_id
string :customer_name do customer_info.try(&:full_name) end
string :customer_phone do customer_info.try(&:phone) end
string :executor_location_id do executor_location.try(&:id) end
string :originator_name do customer.try(&:full_name) end
string :sp_name do executor.try(&:full_name) end
REPORTCOLUMNS.except!(:customer_info_full_address).each do |k, v|
case v[:type]
when 'string'
text(k){instance_eval(v[:path]) rescue nil}
string(k){instance_eval(v[:path]).downcase rescue nil}
when 'datetime'
time(k){instance_eval(v[:path]) rescue nil}
when 'double'
double(k){instance_eval(v[:path]) rescue nil}
end
end
end
Search is working fine. I wanted to include customer_reference, which is a column in the tickets tables in the search, so I added it to searchable in ticket.rb, as follows:
searchable do
time(:deleted_at)
text :services do services.map(&:name) end
text :inventories do inventories.map(&:name) end
string :customer_reference
text :requested_date_start
text :number
text :customer_phone do customer_info.try(&:phone) end
text :sp_name do executor.try(&:full_name) end
text :specialties do specialties.map(&:top_code) end
double :number
string :customer_id
string :executor_id
string :id
string :technician_ids, multiple: true
string :customer_location_id, using: :location_id
string :customer_name do customer_info.try(&:full_name) end
string :customer_phone do customer_info.try(&:phone) end
string :executor_location_id do executor_location.try(&:id) end
string :originator_name do customer.try(&:full_name) end
string :sp_name do executor.try(&:full_name) end
REPORTCOLUMNS.except!(:customer_info_full_address).each do |k, v|
case v[:type]
when 'string'
text(k){instance_eval(v[:path]) rescue nil}
string(k){instance_eval(v[:path]).downcase rescue nil}
when 'datetime'
time(k){instance_eval(v[:path]) rescue nil}
when 'double'
double(k){instance_eval(v[:path]) rescue nil}
end
end
end
I uploaded the new ticket.rb to the staging server and did the following:
bundle install
bundle exec rake RAILS_ENV=staging db:migrate
chmod -R -- g+w /home/app
RAILS_ENV=staging RAILS_GROUPS=assets bundle exec rake assets:precompile
sudo reboot
echo \"DEPLOY SIDEKIQ RELOAD $(date)\" >> log/sidekiq.log
bundle exec sidekiq -d -L log/sidekiq.log -e staging
RAILS_ENV=staging bundle exec rake sunspot:solr:start
screen -d -m sh -c 'cd /home/app && RAILS_ENV=staging bundle exec rake sunspot:solr:reindex'
When I did a search with a customer_reference, it did not find it. When I looked at the solr log file, I found the following:
INFO: [development] webapp=/solr path=/select params={fl=*+score&sort=requested_date_start_d+desc&start=0&q=139170&qf=services_text+inventories_text+requested_date_start_text+number_text+customer_phone_text+sp_name_text+specialties_text+status_text+ticket_type_text+executor_full_name_text+customer_full_name_text+customer_info_full_name_text+ticket_profile_name_text&wt=ruby&fq=type:Ticket&rows=20&defType=edismax} hits=1 status=0 QTime=27
customer_reference is not there. This is the first time I use solr, and I am trying to maintain this code. Any ideas what I'm doing wrong?
Aucun commentaire:
Enregistrer un commentaire