transform INNER JOIN to LEFT OUTER
This commit is contained in:
@@ -47,7 +47,7 @@ module PgSearchable
|
|||||||
def ts_add_scope
|
def ts_add_scope
|
||||||
class_eval do
|
class_eval do
|
||||||
scope ts_scope_method, ->(value) do
|
scope ts_scope_method, ->(value) do
|
||||||
resulting_ids = ts_search(value).map(&:id)
|
resulting_ids = ts_search(value).rows.map { |row| row[0] }
|
||||||
where(id: resulting_ids)
|
where(id: resulting_ids)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -62,7 +62,9 @@ module PgSearchable
|
|||||||
@ts_search_fields_mappings,
|
@ts_search_fields_mappings,
|
||||||
@ts_joins
|
@ts_joins
|
||||||
)
|
)
|
||||||
distinct.joins(sql_query_object.join_clause).group(:id).having(sql_query_object.where_clause)
|
sql_query = select(:id).distinct.joins(sql_query_object.join_clause).group(:id).having(sql_query_object.where_clause)
|
||||||
|
modified_sql_query = sql_query.to_sql.gsub('INNER', 'LEFT OUTER') # TODO: Search terms should not be replaced!
|
||||||
|
ActiveRecord::Base.connection.exec_query(modified_sql_query)
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_update_cache_field?
|
def should_update_cache_field?
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ class TextToSqlQuery
|
|||||||
|
|
||||||
def join_clause
|
def join_clause
|
||||||
return nil if @joins.empty?
|
return nil if @joins.empty?
|
||||||
|
|
||||||
return *@joins
|
return *@joins
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -109,6 +108,7 @@ private
|
|||||||
result.gsub!(/\_/, '\_')
|
result.gsub!(/\_/, '\_')
|
||||||
result.tr!('\\', '\\')
|
result.tr!('\\', '\\')
|
||||||
result.gsub!(/%/, '\%')
|
result.gsub!(/%/, '\%')
|
||||||
|
result.downcase!
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user