Commit 550f0a75 authored by Daniel Mack's avatar Daniel Mack Committed by Mario Manno

conferences, events, people: switch to ransack for full-text search

Ransack is already included in the gems, so all we have to do is cut out the
acts_as_indexed pieces and use ransack directly in the models.

For this, the controllers for conferences, events and people have been
changed so that the ransack filters are called directly, using the 'cond'
predicate in most cases.

The search code in controllers was factored out into a new method called
'search'. Depending on whether 'q' or 'term' has been passed in through
the query, it uses the model's search method or invokes ransack directly.
This way, both query methods are still offered.
parent dad7308c
......@@ -10,12 +10,8 @@ class ConferencesController < ApplicationController
# GET /conferences
# GET /conferences.xml
def index
if params.has_key?(:term) and not params[:term].empty?
@search = Conference.with_query(params[:term]).search(params[:q])
else
@search = Conference.search(params[:q])
end
@conferences = @search.result.paginate page: page_param
result = search Conference, params
@conferences = result.paginate page: page_param
respond_to do |format|
format.html # index.html.erb
......@@ -100,6 +96,21 @@ class ConferencesController < ApplicationController
return "edit"
end
def search(conferences, params)
if params.has_key?(:term) and not params[:term].empty?
term = params[:term]
sort = params[:q][:s] rescue nil
@search = events.ransack(title_cont: term,
acronym_cont: term,
m: 'or',
s: sort)
else
@search = conferences.ransack(params[:q])
end
@search.result(distinct: true)
end
def conference_params
params.require(:conference).permit(
:acronym, :title, :timezone, :timeslot_duration, :default_timeslots, :max_timeslots, :feedback_enabled, :email, :program_export_base_url, :schedule_version, :schedule_public, :color, :ticket_type, :event_state_visible, :schedule_custom_css, :schedule_html_intro, :default_recording_license,
......
......@@ -8,12 +8,9 @@ class EventsController < ApplicationController
# GET /events.xml
def index
authorize! :read, Event
if params.has_key?(:term) and not params[:term].empty?
@search = @conference.events.with_query(params[:term]).includes(:track).search(params[:q])
else
@search = @conference.events.includes(:track).search(params[:q])
end
@events = @search.result.paginate page: page_param
result = search @conference.events.includes(:track), params
@events = result.paginate page: page_param
clean_events_attributes
respond_to do |format|
......@@ -25,13 +22,10 @@ class EventsController < ApplicationController
# current_users events
def my
authorize! :read, Event
if params.has_key?(:term) and not params[:term].empty?
@search = @conference.events.associated_with(current_user.person).with_query(params[:term]).search(params[:q])
else
@search = @conference.events.associated_with(current_user.person).search(params[:q])
end
result = search @conference.events.associated_with(current_user.person), params
clean_events_attributes
@events = @search.result.paginate page: page_param
@events = result.paginate page: page_param
end
# events as pdf
......@@ -51,8 +45,9 @@ class EventsController < ApplicationController
# show event ratings
def ratings
authorize! :create, EventRating
@search = @conference.events.search(params[:q])
@events = @search.result.paginate page: page_param
result = search @conference.events, params
@events = result.paginate page: page_param
clean_events_attributes
# total ratings:
......@@ -68,8 +63,8 @@ class EventsController < ApplicationController
# show event feedbacks
def feedbacks
authorize! :access, :event_feedback
@search = @conference.events.accepted.search(params[:q])
@events = @search.result.paginate page: page_param
result = search @conference.events.accepted, params
@events = result.paginate page: page_param
end
# start batch event review
......@@ -223,6 +218,24 @@ class EventsController < ApplicationController
end
end
def search(events, params)
if params.has_key?(:term) and not params[:term].empty?
term = params[:term]
sort = params[:q][:s] rescue nil
@search = events.ransack(title_cont: term,
description_cont: term,
abstract_cont: term,
track_name_cont: term,
event_type_is: term,
m: 'or',
s: sort)
else
@search = events.ransack(params[:q])
end
@search.result(distinct: true)
end
def event_params
params.require(:event).permit(
:id, :title, :subtitle, :event_type, :time_slots, :state, :start_time, :public, :language, :abstract, :description, :logo, :track_id, :room_id, :note, :submission_note, :do_not_record, :recording_license,
......
......@@ -8,12 +8,8 @@ class PeopleController < ApplicationController
# GET /people.xml
def index
authorize! :administrate, Person
if params.has_key?(:term) and not params[:term].empty?
@search = Person.involved_in(@conference).with_query(params[:term]).search(params[:q])
else
@search = Person.involved_in(@conference).search(params[:q])
end
@people = @search.result.paginate page: page_param
result = search Person.involved_in(@conference), params
@people = result.paginate page: page_param
end
def speakers
......@@ -22,12 +18,8 @@ class PeopleController < ApplicationController
respond_to do |format|
format.html do
if params.has_key?(:term) and not params[:term].empty?
@search = @people.involved_in(@conference).with_query(params[:term]).search(params[:q])
else
@search = @people.involved_in(@conference).search(params[:q])
end
@people = @search.result.paginate page: page_param
result = search Person.involved_in(@conference), params
@people = result.paginate page: page_param
end
format.text do
render text: @people.map(&:email).join("\n")
......@@ -37,12 +29,8 @@ class PeopleController < ApplicationController
def all
authorize! :administrate, Person
if params.has_key?(:term) and not params[:term].empty?
@search = Person.with_query(params[:term]).search(params[:q])
else
@search = Person.search(params[:q])
end
@people = @search.result.paginate page: page_param
result = search Person, params
@people = result.paginate page: page_param
end
# GET /people/1
......@@ -154,6 +142,26 @@ class PeopleController < ApplicationController
end
end
def search(people, params)
if params.has_key?(:term) and not params[:term].empty?
term = params[:term]
sort = params[:q][:s] rescue nil
@search = people.ransack(first_name_cont: term,
last_name_cont: term,
public_name_cont: term,
email_cont: term,
abstract_cont: term,
description_cont: term,
user_email_cont: term,
m: 'or',
s: sort)
else
@search = people.ransack(params[:q])
end
@search.result(distinct: true)
end
def person_params
params.require(:person).permit(
:first_name, :last_name, :public_name, :email, :email_public, :gender, :avatar_file_name, :abstract, :description, :include_in_mailings, :note,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment