Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improve book search using Texticle

  • Loading branch information...
commit c5493a6b3367014cb18da6e41f62cb38009e60ff 1 parent 16c41b1
Adrian Short authored
View
2  Gemfile
@@ -10,6 +10,8 @@ gem 'isbn'
gem 'themes_for_rails'
gem 'httpclient'
gem 'json_pure'
+gem 'pg'
+gem 'texticle', '< 2.0'#, :require => 'texticle/rails'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
View
4 Gemfile.lock
@@ -52,6 +52,7 @@ GEM
treetop (~> 1.4.8)
mime-types (1.16)
nokogiri (1.5.0)
+ pg (0.14.1)
polyglot (0.3.2)
rack (1.2.3)
rack-mount (0.6.14)
@@ -77,6 +78,7 @@ GEM
rake (0.9.2)
rdoc (3.9.4)
sqlite3 (1.3.4)
+ texticle (1.0.4.20101004123327)
themes_for_rails (0.4.2)
rails (~> 3.0.0)
themes_for_rails
@@ -99,7 +101,9 @@ DEPENDENCIES
isbn
json_pure
nokogiri
+ pg
rails
rails3-generators
sqlite3
+ texticle (< 2.0)
themes_for_rails
View
18 app/controllers/search_controller.rb
@@ -4,17 +4,13 @@ def index
case ActiveRecord::Base.connection.adapter_name
- when 'SQLite'
- @titles = Title.find_by_sql(["
- SELECT *
- FROM titles
- WHERE title LIKE ? OR subtitle LIKE ?", "%#{@q}%", "%#{@q}%"])
- else
- @titles = Title.find_by_sql(["
- SELECT *
- FROM titles
- WHERE LOWER(TEXTCAT(TEXTCAT(title, ' '), subtitle)) LIKE(?)", "%#{@q}%"
- ])
+ when 'SQLite'
+ @titles = Title.find_by_sql(["
+ SELECT *
+ FROM titles
+ WHERE title LIKE ? OR subtitle LIKE ?", "%#{@q}%", "%#{@q}%"])
+ else
+ @titles = Title.search(@q)
end
# @type = params[:type]
# if @type == 'titles'
View
6 app/models/title.rb
@@ -9,6 +9,12 @@ class Title < ActiveRecord::Base
validates_associated :authors
validates_isbn :isbn13, :with => :isbn13
+ index do
+ title
+ subtitle
+ description
+ end
+
def to_param
isbn13
end
View
8 config/database.yml
@@ -1,8 +1,12 @@
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
- adapter: sqlite3
- database: db/development.sqlite3
+ host: localhost
+ adapter: postgresql
+ database:
+ username:
+ password:
+ port: 5432
pool: 5
timeout: 5000
Please sign in to comment.
Something went wrong with that request. Please try again.