Permalink
Browse files

Reimplement search using ThinkingSphinx

  • Loading branch information...
jamesu committed Oct 4, 2011
1 parent 5a3a899 commit e83d2252a19555dc674d2e4b338430b71093e75d
View
13 Gemfile
@@ -1,21 +1,21 @@
source 'http://rubygems.org'
-gem 'rails', '3.1.0rc4'
+gem 'rails', '3.1.0'
gem 'sqlite3'
gem 'cancan'
-gem 'sass-rails', "~> 3.1.0.rc"
gem 'haml'
+gem 'sass-rails', '~> 3.1.0'
gem 'uglifier'
gem 'paperclip'
gem 'dynamic_form'
gem 'will_paginate', '~> 3.0'
gem 'RedCloth'
gem 'icalendar'
-gem 'faker'
-gem 'factory_girl'
gem 'friendly_id', '~> 4.0.0.beta8'
gem 'acts_as_versioned', :git => "git://github.com/firien/acts_as_versioned.git"
gem 'jquery-rails', '>= 1.0.12'
+gem 'thinking-sphinx', '2.0.5'
+gem 'mysql', :require => nil, :group => :mysql
#group :test, :development do
# gem 'rspec-rails', '~> 2.3.1'
@@ -24,6 +24,11 @@ gem 'jquery-rails', '>= 1.0.12'
#gem 'immortal', :git => "git://github.com/teambox/immortal.git"
gem 'choices', :git => "git://github.com/teambox/choices.git"
+group :test do
+ gem 'faker'
+ gem 'factory_girl'
+end
+
# Rails 3.1 - Heroku
group :production do
gem 'therubyracer-heroku', '0.8.1.pre3'
View
@@ -16,56 +16,56 @@ GEM
remote: http://rubygems.org/
specs:
RedCloth (4.2.8)
- actionmailer (3.1.0.rc4)
- actionpack (= 3.1.0.rc4)
+ actionmailer (3.1.0)
+ actionpack (= 3.1.0)
mail (~> 2.3.0)
- actionpack (3.1.0.rc4)
- activemodel (= 3.1.0.rc4)
- activesupport (= 3.1.0.rc4)
+ actionpack (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
- rack (~> 1.3.0)
- rack-cache (~> 1.0.1)
- rack-mount (~> 0.8.1)
- rack-test (~> 0.6.0)
- sprockets (~> 2.0.0.beta.10)
- tzinfo (~> 0.3.27)
- activemodel (3.1.0.rc4)
- activesupport (= 3.1.0.rc4)
- bcrypt-ruby (~> 2.1.4)
+ rack (~> 1.3.2)
+ rack-cache (~> 1.0.3)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.0)
+ activemodel (3.1.0)
+ activesupport (= 3.1.0)
+ bcrypt-ruby (~> 3.0.0)
builder (~> 3.0.0)
i18n (~> 0.6)
- activerecord (3.1.0.rc4)
- activemodel (= 3.1.0.rc4)
- activesupport (= 3.1.0.rc4)
- arel (~> 2.1.1)
- tzinfo (~> 0.3.27)
- activeresource (3.1.0.rc4)
- activemodel (= 3.1.0.rc4)
- activesupport (= 3.1.0.rc4)
- activesupport (3.1.0.rc4)
+ activerecord (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ activesupport (3.1.0)
multi_json (~> 1.0)
- arel (2.1.1)
- bcrypt-ruby (2.1.4)
- bcrypt-ruby (2.1.4-java)
+ arel (2.2.1)
+ bcrypt-ruby (3.0.1)
+ bcrypt-ruby (3.0.1-java)
builder (3.0.0)
- cancan (1.6.5)
+ cancan (1.6.6)
cocaine (0.2.0)
dynamic_form (1.1.4)
erubis (2.7.0)
- execjs (1.2.0)
+ execjs (1.2.9)
multi_json (~> 1.0)
- factory_girl (1.3.3)
- faker (0.9.5)
+ factory_girl (2.1.2)
+ activesupport
+ faker (1.0.1)
i18n (~> 0.4)
friendly_id (4.0.0.beta12)
- haml (3.1.2)
- hashie (1.0.0)
- hike (1.1.0)
+ haml (3.1.3)
+ hashie (1.1.0)
+ hike (1.2.1)
i18n (0.6.0)
icalendar (1.1.6)
- jquery-rails (1.0.13)
+ jquery-rails (1.0.14)
railties (~> 3.0)
thor (~> 0.14)
mail (2.3.0)
@@ -74,60 +74,65 @@ GEM
treetop (~> 1.4.8)
mime-types (1.16)
multi_json (1.0.3)
- paperclip (2.3.16)
+ mysql (2.8.1)
+ paperclip (2.4.2)
activerecord (>= 2.3.0)
activesupport (>= 2.3.2)
cocaine (>= 0.0.2)
mime-types
pg (0.11.0)
- polyglot (0.3.1)
- rack (1.3.0)
- rack-cache (1.0.2)
+ polyglot (0.3.2)
+ rack (1.3.4)
+ rack-cache (1.0.3)
rack (>= 0.4)
- rack-mount (0.8.1)
+ rack-mount (0.8.3)
rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
- rack-test (0.6.0)
+ rack-test (0.6.1)
rack (>= 1.0)
- rails (3.1.0.rc4)
- actionmailer (= 3.1.0.rc4)
- actionpack (= 3.1.0.rc4)
- activerecord (= 3.1.0.rc4)
- activeresource (= 3.1.0.rc4)
- activesupport (= 3.1.0.rc4)
+ rails (3.1.0)
+ actionmailer (= 3.1.0)
+ actionpack (= 3.1.0)
+ activerecord (= 3.1.0)
+ activeresource (= 3.1.0)
+ activesupport (= 3.1.0)
bundler (~> 1.0)
- railties (= 3.1.0.rc4)
- railties (3.1.0.rc4)
- actionpack (= 3.1.0.rc4)
- activesupport (= 3.1.0.rc4)
+ railties (= 3.1.0)
+ railties (3.1.0)
+ actionpack (= 3.1.0)
+ activesupport (= 3.1.0)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2)
- rdoc (3.6.1)
- sass (3.1.2)
- sass-rails (3.1.0.rc.2)
- actionpack (~> 3.1.0.rc1)
- railties (~> 3.1.0.rc1)
- sass (>= 3.1.2)
- sprockets (>= 2.0.0.beta.9)
- sprockets (2.0.0.beta.10)
- hike (~> 1.0)
+ rdoc (3.9.4)
+ riddle (1.4.0)
+ sass (3.1.7)
+ sass-rails (3.1.0)
+ actionpack (~> 3.1.0)
+ railties (~> 3.1.0)
+ sass (>= 3.1.4)
+ sprockets (2.0.2)
+ hike (~> 1.2)
rack (~> 1.0)
- tilt (!= 1.3.0, ~> 1.1)
- sqlite3 (1.3.3)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.4)
therubyracer-heroku (0.8.1.pre3)
+ thinking-sphinx (2.0.5)
+ activerecord (>= 3.0.3)
+ riddle (>= 1.3.3)
thor (0.14.6)
- tilt (1.3.2)
- treetop (1.4.9)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
polyglot (>= 0.3.1)
- tzinfo (0.3.28)
- uglifier (0.5.4)
+ tzinfo (0.3.30)
+ uglifier (1.0.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
- will_paginate (3.0.0)
+ will_paginate (3.0.2)
PLATFORMS
java
@@ -145,11 +150,13 @@ DEPENDENCIES
haml
icalendar
jquery-rails (>= 1.0.12)
+ mysql
paperclip
pg
- rails (= 3.1.0rc4)
- sass-rails (~> 3.1.0.rc)
+ rails (= 3.1.0)
+ sass-rails (~> 3.1.0)
sqlite3
therubyracer-heroku (= 0.8.1.pre3)
+ thinking-sphinx (= 2.0.5)
uglifier
will_paginate (~> 3.0)
View
@@ -34,6 +34,7 @@ class Comment < ActiveRecord::Base
scope :is_public, where(:is_private => false)
def process_params
+ self.project_id ||= self.rel_object.try(:project_id)
self.is_anonymous = self.created_by.is_anonymous?
true
@@ -70,14 +71,6 @@ def object_url(host = nil)
end
end
- def project
- self.rel_object.project
- end
-
- def project_id
- self.rel_object.project_id
- end
-
def attached_files(with_private)
if with_private
project_file
@@ -99,4 +92,14 @@ def attached_files(with_private)
validates_each :is_private, :if => Proc.new { |obj| !obj.last_edited_by_owner? } do |record, attr, value|
record.errors.add attr, I18n.t('not_allowed') if value == true
end
+
+ # Indexing
+ define_index do
+ indexes :text
+
+ has :project_id
+ has :is_private
+ has :created_on
+ has :updated_on
+ end
end
View
@@ -70,6 +70,10 @@ def tags_with_spaces
Tag.list_by_object(self).join(' ')
end
+ def tag_list
+ Tag.where(['rel_object_type = ? AND rel_object_id = ?', object.class.to_s, object.id])
+ end
+
def tags=(val)
Tag.clear_by_object(self)
Tag.set_to_object(self, val.split(',')) unless val.nil?
@@ -139,4 +143,17 @@ def send_notification(user)
validates_each :comments_enabled, :if => Proc.new { |obj| !obj.last_edited_by_owner? } do |record, attr, value|
record.errors.add(attr, I18n.t('not_allowed')) if value == false
end
+
+ # Indexing
+ define_index do
+ indexes :title
+ indexes :text
+ indexes tag_list(:tag), :as => :tags
+
+ has :project_id
+ has :category_id
+ has :is_private
+ has :created_on
+ has :updated_on
+ end
end
View
@@ -102,6 +102,10 @@ def tags_with_spaces
Tag.list_by_object(self).join(' ')
end
+ def tag_list
+ Tag.where(['rel_object_type = ? AND rel_object_id = ?', object.class.to_s, object.id])
+ end
+
def tags=(val)
Tag.clear_by_object(self)
Tag.set_to_object(self, val.split(',')) unless val.nil?
@@ -276,4 +280,18 @@ def self.late_by_user(user)
validates_each :assigned_to, :allow_nil => true do |record, attr, value|
record.errors.add(attr, I18n.t('not_part_of_project')) if !value.nil? and !value.is_part_of(record.project)
end
+
+ # Indexing
+ define_index do
+ indexes :name
+ indexes :description
+ indexes tag_list(:tag), :as => :tags
+
+ has :assigned_to_company_id
+ has :assigned_to_user_id
+ has :project_id
+ has :is_private
+ has :created_on
+ has :updated_on
+ end
end
View
@@ -115,22 +115,18 @@ def self.search_for_user(query, user, options={}, tag_search=false)
def self.search(query, is_private, projects, options={}, tag_search=false)
results = []
- return results, 0 unless Rails.configuration.search_enabled
-
- project_ids = projects.collect { |project| project.id }.join('|')
- real_query = if is_private
- "is_private:false project_id:\"#{project_ids}\" #{query}"
- else
- "project_id:\"#{project_ids}\" #{query}"
- end
+ return results, 0 if !Rails.configuration.search_enabled or query.blank?
+ options[:with] ||= {}
+ options[:with][:is_private] = false unless is_private
+ options[:with][:project_id] = projects.map(&:id)
results = if tag_search
- Tag.find_with_ferret(real_query, options)
+ Tag.search(query, options)
else
- ActsAsFerret::find(real_query, :shared, options)
+ ThinkingSphinx.search query, options.merge(:classes => [Comment, Message, TimeRecord, Task, TaskList, Milestone, ProjectFile, ProjectFileRevision, WikiPage])
end
- return results, results.total_hits
+ return results, results.total_entries
end
# Helpers
View
@@ -64,6 +64,10 @@ def tags_with_spaces
Tag.list_by_object(self).join(' ')
end
+ def tag_list
+ Tag.where(['rel_object_type = ? AND rel_object_id = ?', object.class.to_s, object.id])
+ end
+
def tags=(val)
Tag.clear_by_object(self)
real_owner = project_file_revisions.empty? ? nil : self.project_file_revisions[0].created_by
@@ -212,4 +216,18 @@ def self.find_grouped(group_field, params)
validates_each :comments_enabled, :if => Proc.new { |obj| !obj.last_edited_by_owner? } do |record, attr, value|
record.errors.add(attr, I18n.t('not_allowed')) if value == false
end
+
+ # Indexing
+ define_index do
+ indexes :name
+ indexes :description
+ indexes tag_list(:tag), :as => :tags
+
+ has :folder_id
+ has :project_id
+ has :is_private
+ has :is_visible
+ has :created_on
+ has :updated_on
+ end
end
Oops, something went wrong.

0 comments on commit e83d225

Please sign in to comment.