Permalink
Browse files

Use TS to index users

  • Loading branch information...
1 parent 34f0a87 commit c1392dd18e1b7f91500da4fb13a4ad78efd25015 unknown committed Jul 20, 2010
Showing with 81 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 Rakefile
  3. +9 −2 app/controllers/users_controller.rb
  4. +11 −2 app/models/user.rb
  5. +49 −0 config/development.sphinx.conf
  6. +5 −0 config/environment.rb
  7. +5 −0 config/sphinx.yml
View
@@ -21,3 +21,4 @@ doc/app
public/themes/scribe/cache/
.tmp*
development.yml
+db/sphinx/development
View
@@ -8,3 +8,4 @@ require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
+require 'thinking_sphinx/tasks'
@@ -30,10 +30,17 @@ def search
session[:users_start_filter] = "All"
session[:users_end_filter] = "All"
session[:users_search] = params[:search]
- params[:search] = StringUtils.sanitize_search_terms params[:search]
+# params[:search] = StringUtils.sanitize_search_terms params[:search]
+ if params[:search].empty?
+ list
+ render :list
+ return
+ end
+
set_start_stop_tags
begin
- search_results = User.find_by_solr(params[:search], :lazy => true).docs.collect(&:id)
+ search_results = User.search_for_ids params[:search], :order => :email
+# search_results = User.find_by_solr(params[:search], :lazy => true).docs.collect(&:id)
rescue RuntimeError => e
flash[:error] = "An error occurred while executing your search. Perhaps there is a problem with the syntax of your search string."
logger.error(e)
View
@@ -34,8 +34,17 @@ class User < ActiveRecord::Base
extend ActiveSupport::Memoizable
ajaxful_rater
- acts_as_solr :fields => [:email, :first_name, :last_name],
- :include => [:enterprise]
+# acts_as_solr :fields => [:email, :first_name, :last_name],
+# :include => [:enterprise]
+
+ define_index do
+ indexes email, :sortable => true
+ indexes first_name, :sortable => true
+ indexes last_name, :sortable => true
+ indexes enterprise(:name), :as => :enterprise, :sortable => true
+
+ has created_at, updated_at
+ end
# Virtual attribute for the unencrypted password
@@ -0,0 +1,49 @@
+indexer
+{
+}
+
+searchd
+{
+ listen = 127.0.0.1:9312
+ log = c:/dev/openmind.git/log/searchd.log
+ query_log = c:/dev/openmind.git/log/searchd.query.log
+ pid_file = c:/dev/openmind.git/log/searchd.development.pid
+}
+
+source user_core_0
+{
+ type = mysql
+ sql_host = localhost
+ sql_user = dev
+ sql_pass = openmind
+ sql_db = OpenMind_dev2
+ sql_query_pre = SET NAMES utf8
+ sql_query = SELECT SQL_NO_CACHE `users`.`id` * 1 + 0 AS `id` , CAST(`users`.`email` AS CHAR) AS `email`, CAST(`users`.`first_name` AS CHAR) AS `first_name`, CAST(`users`.`last_name` AS CHAR) AS `last_name`, CAST(`enterprises`.`name` AS CHAR) AS `enterprise`, `users`.`id` AS `sphinx_internal_id`, 765557111 AS `class_crc`, '765557111' AS `subclass_crcs`, 0 AS `sphinx_deleted`, IFNULL(`users`.`email`, '') AS `email_sort`, IFNULL(`users`.`first_name`, '') AS `first_name_sort`, IFNULL(`users`.`last_name`, '') AS `last_name_sort`, IFNULL(`enterprises`.`name`, '') AS `enterprise_sort`, UNIX_TIMESTAMP(`users`.`created_at`) AS `created_at`, UNIX_TIMESTAMP(`users`.`updated_at`) AS `updated_at` FROM `users` LEFT OUTER JOIN `enterprises` ON `enterprises`.id = `users`.enterprise_id WHERE `users`.`id` >= $start AND `users`.`id` <= $end GROUP BY `users`.`id` ORDER BY NULL
+ sql_query_range = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1) FROM `users`
+ sql_attr_uint = sphinx_internal_id
+ sql_attr_uint = class_crc
+ sql_attr_uint = sphinx_deleted
+ sql_attr_timestamp = created_at
+ sql_attr_timestamp = updated_at
+ sql_attr_str2ordinal = email_sort
+ sql_attr_str2ordinal = first_name_sort
+ sql_attr_str2ordinal = last_name_sort
+ sql_attr_str2ordinal = enterprise_sort
+ sql_attr_multi = uint subclass_crcs from field
+ sql_query_info = SELECT * FROM `users` WHERE `id` = (($id - 0) / 1)
+}
+
+index user_core
+{
+ source = user_core_0
+ path = c:/dev/openmind.git/db/sphinx/development/user_core
+ charset_type = utf-8
+ min_infix_len = 1
+ enable_star = 1
+}
+
+index user
+{
+ type = distributed
+ local = user_core
+}
View
@@ -35,6 +35,11 @@
config.gem "ruby-yadis", :lib => 'yadis', :version => '0.3.4'
config.gem "ruby-openid", :lib => 'openid', :version => '1.1.4'
+
+ config.gem(
+ 'thinking-sphinx',
+ :lib => 'thinking_sphinx',
+ :version => '1.3.11')
# Default timezone...Set this to the timezone where the server resides
config.time_zone = 'Eastern Time (US & Canada)'
View
@@ -0,0 +1,5 @@
+# Auto-generated template
+development:
+ enable_star: 1
+ min_infix_len: 1
+ bin_path: 'c:/sphinx/bin'

0 comments on commit c1392dd

Please sign in to comment.