Module: FulltextSearchable::Mysql2Adapter

Defined in:
lib/fulltext_searchable/mysql2_adapter.rb

Instance Method Summary collapse

Instance Method Details

#create_fulltext_index_tableObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fulltext_searchable/mysql2_adapter.rb', line 5

def create_fulltext_index_table
  execute( <<SQL
CREATE TABLE IF NOT EXISTS `#{::FulltextSearchable::TABLE_NAME}` (
  `_id` INT(11),
  `key` VARCHAR(32),
  `item_type` VARCHAR(255),
  `item_id` INT(11),
  `text` TEXT,
  #{"`_score` FLOAT," unless mroonga_match_against?}
  PRIMARY KEY(`key`),
  #{"UNIQUE " if mroonga_unique_hash_index_safe?}INDEX(`_id`) USING HASH,
  FULLTEXT INDEX (`text`) COMMENT 'parser "TokenBigramSplitSymbolAlpha"'
) ENGINE = #{mroonga_storage_engine_name} COLLATE utf8_unicode_ci;
SQL
  )
end

#mroonga_match_against?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/fulltext_searchable/mysql2_adapter.rb', line 22

def mroonga_match_against?
  mroonga_version >= '1.2'
end

#mroonga_storage_engine_nameObject



31
32
33
34
35
# File 'lib/fulltext_searchable/mysql2_adapter.rb', line 31

def mroonga_storage_engine_name
  @mroonga_storage_engine_name ||=
    execute('SHOW ENGINES;').map(&:first).find{|name| name =~ /.+roonga/} or
    raise "mroonga or groonga storage engine is not installed"
end

#mroonga_versionObject



26
27
28
29
# File 'lib/fulltext_searchable/mysql2_adapter.rb', line 26

def mroonga_version
  execute("SHOW VARIABLES LIKE '#{mroonga_storage_engine_name}_version';").map(&:last).first ||
    '0.0' # older than 1.0
end