Class: ActiveRecord::Searchable::Adapters::SQLite
Constant Summary
collapse
- SNIPPET_WORD_COUNT =
Number of words to include in snippet output (context around match)
20
- HIGHLIGHT_START_TAG =
HTML tags used to mark highlighted matches in search results
"<mark>"
- HIGHLIGHT_END_TAG =
"</mark>"
Instance Attribute Summary collapse
Instance Method Summary
collapse
for, #select_clause_for_highlights
Constructor Details
#initialize(connection) ⇒ SQLite
Returns a new instance of SQLite.
16
17
18
|
# File 'lib/activerecord/searchable/adapters/sqlite.rb', line 16
def initialize(connection)
@connection = connection
end
|
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
14
15
16
|
# File 'lib/activerecord/searchable/adapters/sqlite.rb', line 14
def connection
@connection
end
|
Instance Method Details
#delete_sql(config, record_id) ⇒ Object
70
71
72
73
74
75
|
# File 'lib/activerecord/searchable/adapters/sqlite.rb', line 70
def delete_sql(config, record_id)
[
"DELETE FROM #{config.search_table_name} WHERE rowid = ?",
record_id
]
end
|
#execute_with_result(connection, sql_array, model_class) ⇒ Object
77
78
79
80
|
# File 'lib/activerecord/searchable/adapters/sqlite.rb', line 77
def execute_with_result(connection, sql_array, model_class)
connection.execute(model_class.sanitize_sql(sql_array))
connection.raw_connection.changes.positive?
end
|
#insert_sql(config, record_id, values) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/activerecord/searchable/adapters/sqlite.rb', line 51
def insert_sql(config, record_id, values)
columns = ["rowid", *config.field_names].join(", ")
placeholders = (["?"] * (values.length + 1)).join(", ")
[
"INSERT INTO #{config.search_table_name}(#{columns}) VALUES (#{placeholders})",
record_id,
*values
]
end
|
#join_clause(config) ⇒ Object
20
21
22
23
24
|
# File 'lib/activerecord/searchable/adapters/sqlite.rb', line 20
def join_clause(config)
table = config.model_class.table_name
search_table = config.search_table_name
"JOIN #{search_table} ON #{table}.id = #{search_table}.rowid"
end
|
#ranking_order_clause(config) ⇒ Object
46
47
48
49
|
# File 'lib/activerecord/searchable/adapters/sqlite.rb', line 46
def ranking_order_clause(config)
weights = config.weights.join(", ")
Arel.sql("bm25(#{config.search_table_name}, #{weights})")
end
|
#select_clause_for_matches(config, matches) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/activerecord/searchable/adapters/sqlite.rb', line 30
def select_clause_for_matches(config, matches)
clauses = []
matches[:highlight].each do |field_name|
clause = build_match_clause(config, field_name, :highlight)
clauses << clause if clause
end
matches[:snippet].each do |field_name|
clause = build_match_clause(config, field_name, :snippet)
clauses << clause if clause
end
clauses
end
|
#update_sql(config, record_id, values) ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'lib/activerecord/searchable/adapters/sqlite.rb', line 61
def update_sql(config, record_id, values)
set_clause = config.field_names.map { |name| "#{name} = ?" }.join(", ")
[
"UPDATE #{config.search_table_name} SET #{set_clause} WHERE rowid = ?",
*values,
record_id
]
end
|
#where_clause(config) ⇒ Object
26
27
28
|
# File 'lib/activerecord/searchable/adapters/sqlite.rb', line 26
def where_clause(config)
"#{config.search_table_name} MATCH ?"
end
|