Module: IsMsfteSearchable::ActiveRecordMixin::ClassMethods

Defined in:
lib/is_msfte_searchable/active_record_mixin.rb

Instance Method Summary collapse

Instance Method Details

#msfte_catalog_rebuildObject



25
26
27
# File 'lib/is_msfte_searchable/active_record_mixin.rb', line 25

def msfte_catalog_rebuild
  connection.execute %|sp_fulltext_catalog '#{msfte_catalog}', 'rebuild'|
end

#msfte_quote(string) ⇒ Object



29
30
31
# File 'lib/is_msfte_searchable/active_record_mixin.rb', line 29

def msfte_quote(string)
  connection.quote_string(string)
end

#msfte_reset!Object



19
20
21
22
23
# File 'lib/is_msfte_searchable/active_record_mixin.rb', line 19

def msfte_reset!
  msfte_teardown
  yield if block_given?
  msfte_setup
end

#msfte_search_string(query, boolean = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/is_msfte_searchable/active_record_mixin.rb', line 33

def msfte_search_string(query, boolean=nil)
  if boolean
    # sql2k won't treat punctuation as valid search terms, so strip them out until we upgrade to 2k5+
    termed_query = query.gsub(/[^\w\d\s]+/, '').split(/\s+/).map{ |term| %|"#{term} *"| }.join(" #{boolean} ").strip
  else
    termed_query = %|"#{query} *"|
  end
  %|'#{msfte_quote(termed_query)}'|
end

#msfte_setupObject



6
7
8
9
10
11
12
# File 'lib/is_msfte_searchable/active_record_mixin.rb', line 6

def msfte_setup
  connection.execute %|sp_fulltext_catalog '#{msfte_catalog}', 'create'|
  connection.execute %|sp_fulltext_table 'dbo.#{msfte_table_name}', 'create', '#{msfte_catalog}', '#{msfte_unique_key_index}'|
  msfte_columns.each { |col| connection.execute(%|sp_fulltext_column '#{msfte_table_name}', '#{col}', 'add'|) }
  connection.execute %|sp_fulltext_table 'dbo.#{msfte_table_name}', 'start_change_tracking'| if msfte_change_tracking
  connection.execute %|sp_fulltext_table 'dbo.#{msfte_table_name}', 'start_background_updateindex'| if msfte_update_index
end

#msfte_teardownObject



14
15
16
17
# File 'lib/is_msfte_searchable/active_record_mixin.rb', line 14

def msfte_teardown
  connection.execute %|sp_fulltext_table 'dbo.#{msfte_table_name}', 'drop'| rescue nil
  connection.execute %|sp_fulltext_catalog '#{msfte_catalog}', 'drop'| rescue nil
end