Skip to content

Commit

Permalink
added Postgres full text search
Browse files Browse the repository at this point in the history
  • Loading branch information
dladowitz committed Sep 28, 2013
1 parent 3ea6ea6 commit 164147f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gem 'paperclip'
gem 'pg'
gem 'thin'
gem "remotipart", "~> 1.0"
gem 'texticle', require: 'texticle/rails'
gem 'will_paginate', '~> 3.0.0'


Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
texticle (2.2.0)
activerecord (>= 3.0, < 4.1)
thin (1.5.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
Expand Down Expand Up @@ -205,6 +207,7 @@ DEPENDENCIES
rails (= 3.2.12)
remotipart (~> 1.0)
sass-rails (~> 3.2.3)
texticle
thin
uglifier (>= 1.0.3)
will_paginate (~> 3.0.0)
3 changes: 2 additions & 1 deletion app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def add_photos

def index
# @courses = Course.paginate(:per_page => 15, :page => params[:page])
@courses = get_courses_nearby(location = 'Saratoga, CA, USA', distance_in_mi = 60)
# @courses = get_courses_nearby(location = 'Saratoga, CA, USA', distance_in_mi = 60)
@courses = Course.text_search(params[:query]).page(params[:page]).per_page(9)
end

def new
Expand Down
8 changes: 8 additions & 0 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class Course < ActiveRecord::Base
validates_presence_of :organization_id, :name
validates_numericality_of :price

def self.text_search(query)
if query.present?
search(query)
else
# This returns all courses orded by rank
scoped(:order => 'rank DESC')
end
end

def next_dates(number_of_dates = nil)
# Gets a specified number of next sections being offered
Expand Down
26 changes: 18 additions & 8 deletions app/views/courses/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@
<img class="hero_image" src="assets/courses/el_cap_hero_bar.jpg">
<div class="search">
<h1>Find Your Adventure</h1>
<form name="search" action="#" method="get">

<!-- TODO delete old form -->
<!-- <form name="search" action="#" method="get">
<input class="search_submit_button" type="submit" value="Search">
<input class="search_box" type="text" name="search" placeholder="rock climbing, sailing, scuba diving....">
</form>
</form> -->

<%= form_tag courses_path, method: :get do %>
<p>
<%= submit_tag "Search", :name => nil, :class => "search_submit_button" %>
<%= text_field_tag :query, params[:query], :class => "search_box", :placeholder => "rock climbing, sailing, scuba diving...." %>
</p>
<% end %>
</div>
</div>

<div class="container">
<div class="main_content">
<h1>Courses</h1>
<% ordered_courses = order_by_rank(@courses) %>
<%# ordered_courses = order_by_rank(@courses) %>
<% courses = WillPaginate::Collection.create(2, 2, 2) do |pager| %>
<% pager.replace ordered_courses %>
<% end %>
<%# courses = WillPaginate::Collection.create(2, 2, 2) do |pager| %>
<%# pager.replace ordered_courses %>
<%# end %>
<% courses.each do |course| %>
<% @courses.each do |course| %>

<!-- Makes sure courses without photos never end up on the home page -->
<% next if course.photos.empty? %>
Expand Down Expand Up @@ -46,6 +55,7 @@
<div class="course_info">
<div class="course_name">
<%= course.name %>
<%= course.rank %>
</div>
<div class="location_group">
<% if course.sections.any? %>
Expand All @@ -69,6 +79,6 @@
</a>
<% end %>
<%= will_paginate courses %>
<%= will_paginate @courses %>
</div>
</div>

0 comments on commit 164147f

Please sign in to comment.