decisiv-is_msfte_searchable 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +3 -0
- data/init.rb +1 -0
- data/lib/is_msfte_searchable.rb +76 -0
- data/tasks/is_msfte_searchable_tasks.rake +23 -0
- metadata +57 -0
data/README.rdoc
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'is_msfte_searchable'
|
@@ -0,0 +1,76 @@
|
|
1
|
+
|
2
|
+
module IsMsfteSearchable
|
3
|
+
module ActiveRecordExtension
|
4
|
+
def is_msfte_searchable(options)
|
5
|
+
class_inheritable_accessor :fields
|
6
|
+
class_inheritable_accessor :key_table
|
7
|
+
self.fields = options[:fields].blank? ? [] : options[:fields].map(&:to_s)
|
8
|
+
self.key_table = options[:key_table].blank? ? table_name : options[:key_table]
|
9
|
+
include IsMsfteSearchable::NamedScopes
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module NamedScopes
|
14
|
+
def self.included(klass)
|
15
|
+
klass.class_eval do
|
16
|
+
|
17
|
+
def self.make_search_string(search_string, boolean="OR")
|
18
|
+
search_string.split(/ +/).map {|term| '"' + term + '*"'}.join(" #{boolean} ")
|
19
|
+
end
|
20
|
+
|
21
|
+
named_scope :msfte_with_any, lambda { |search_string|
|
22
|
+
if search_string.blank?
|
23
|
+
{}
|
24
|
+
else
|
25
|
+
{ :conditions => "#{table_name}.#{primary_key} IN (SELECT [KEY_TBL].[KEY] FROM CONTAINSTABLE(#{self.key_table},*,'#{make_search_string(search_string,'OR')}') AS KEY_TBL)" }
|
26
|
+
end
|
27
|
+
}
|
28
|
+
|
29
|
+
named_scope :msfte_with_all, lambda { |search_string|
|
30
|
+
if search_string.blank?
|
31
|
+
{}
|
32
|
+
else
|
33
|
+
{ :conditions => "#{table_name}.#{primary_key} IN (SELECT [KEY_TBL].[KEY] FROM CONTAINSTABLE(#{self.key_table},*,'#{make_search_string(search_string,'AND')}') AS KEY_TBL)" }
|
34
|
+
end
|
35
|
+
}
|
36
|
+
|
37
|
+
named_scope :msfte_with_booleans, lambda { |search_string|
|
38
|
+
if search_string.blank?
|
39
|
+
{}
|
40
|
+
else
|
41
|
+
{ :conditions => "#{table_name}.#{primary_key} IN (SELECT [KEY_TBL].[KEY] FROM CONTAINSTABLE(#{self.key_table},*,'#{search_string}') AS KEY_TBL)" }
|
42
|
+
end
|
43
|
+
}
|
44
|
+
|
45
|
+
self.fields.each do |field|
|
46
|
+
named_scope "msfte_#{field}_with_any".to_sym, lambda { |search_string|
|
47
|
+
if search_string.blank?
|
48
|
+
{}
|
49
|
+
else
|
50
|
+
{ :conditions => "#{table_name}.#{primary_key} IN (SELECT [KEY_TBL].[KEY] FROM CONTAINSTABLE(#{self.key_table},#{field},'#{make_search_string(search_string,'OR')}') AS KEY_TBL)" }
|
51
|
+
end
|
52
|
+
}
|
53
|
+
|
54
|
+
named_scope "msfte_#{field}_with_all".to_sym, lambda { |search_string|
|
55
|
+
if search_string.blank?
|
56
|
+
{}
|
57
|
+
else
|
58
|
+
{ :conditions => "#{table_name}.#{primary_key} IN (SELECT [KEY_TBL].[KEY] FROM CONTAINSTABLE(#{self.key_table},#{field},'#{make_search_string(search_string,'AND')}') AS KEY_TBL)" }
|
59
|
+
end
|
60
|
+
}
|
61
|
+
|
62
|
+
named_scope "msfte_#{field}_with_booleans".to_sym, lambda { |search_string|
|
63
|
+
if search_string.blank?
|
64
|
+
{}
|
65
|
+
else
|
66
|
+
{ :conditions => "#{table_name}.#{primary_key} IN (SELECT [KEY_TBL].[KEY] FROM CONTAINSTABLE(#{self.key_table},*,'#{search_string}') AS KEY_TBL)" }
|
67
|
+
end
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
ActiveRecord::Base.send(:extend, IsMsfteSearchable::ActiveRecordExtension)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
namespace :msfte do
|
2
|
+
task :no_ddl_environment => :environment do
|
3
|
+
conn = ActiveRecord::Base.connection
|
4
|
+
conn.instance_eval do
|
5
|
+
def supports_ddl_transactions? ; false ; end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
task :enable_fulltext => :no_ddl_environment do
|
10
|
+
ActiveRecord::Base.connection.execute("sp_fulltext_database 'enable'")
|
11
|
+
end
|
12
|
+
|
13
|
+
task :add_table => :no_ddl_environment do
|
14
|
+
# parameters = table, columns
|
15
|
+
table = ENV['table']
|
16
|
+
cols = ENV['cols'].split(/, +/)
|
17
|
+
ActiveRecord::Base.connection.execute("sp_fulltext_catalog '#{table_msfte}','create'")
|
18
|
+
ActiveRecord::Base.connection.execute("sp_fulltext_table '#{table}', 'create', 'dealers_fti', 'dealer_id_idx'")
|
19
|
+
cols.each { |col| ActiveRecord::Base.connection.execute("sp_fulltext_column '#{table}', '#{col}', 'add'") }
|
20
|
+
ActiveRecord::Base.connection.execute("sp_fulltext_table '#{table}', 'start_change_tracking'")
|
21
|
+
ActiveRecord::Base.connection.execute("sp_fulltext_table '#{table}', 'start_background_updateindex'")
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: decisiv-is_msfte_searchable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Knox
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-10 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Adds named scopes for full text searching with Microsoft SQL Server
|
17
|
+
email: bknox@decisiv.net
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- init.rb
|
26
|
+
- README.rdoc
|
27
|
+
- lib/is_msfte_searchable.rb
|
28
|
+
- tasks/is_msfte_searchable_tasks.rake
|
29
|
+
has_rdoc: true
|
30
|
+
homepage: http://github.com/decisiv/is_ms_searchable/
|
31
|
+
licenses:
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
version:
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.3.5
|
53
|
+
signing_key:
|
54
|
+
specification_version: 2
|
55
|
+
summary: Easy full text searching for Microsoft SQL Server
|
56
|
+
test_files: []
|
57
|
+
|