Skip to content

Commit b901b20

Browse files
greverittarnaudbesnier
authored andcommitted
[*] Search - Enable PostgreSQL's CITEXT fields in search. (#311)
1 parent 8b7be20 commit b901b20

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Change Log
22

33
## [Unreleased]
4+
### Fixed
5+
- Search - Enable PostgreSQL's CITEXT fields in search.
46

57
## RELEASE 3.0.0-beta.17 - 2019-04-04
68
### Changed

app/services/forest_liana/search_query_builder.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def search_param
5656
conditions = []
5757

5858
@resource.columns.each_with_index do |column, index|
59-
@fields_searched << column.name if [:string, :text].include? column.type
59+
@fields_searched << column.name if text_type? column.type
6060
column_name = format_column_name(@resource.table_name, column.name)
6161
if (@collection.search_fields && !@collection.search_fields.include?(column.name))
6262
conditions
@@ -73,8 +73,7 @@ def search_param
7373
!@resource.defined_enums[column.name][@search.downcase].nil?
7474
conditions << "#{column_name} =
7575
#{@resource.defined_enums[column.name][@search.downcase]}"
76-
elsif !(column.respond_to?(:array) && column.array) &&
77-
(column.type == :string || column.type == :text)
76+
elsif !(column.respond_to?(:array) && column.array) && text_type?(column.type)
7877
conditions << "LOWER(#{column_name}) LIKE :search_value_for_string"
7978
end
8079
end
@@ -101,8 +100,7 @@ def search_param
101100
if @includes.include? association.to_sym
102101
resource = @resource.reflect_on_association(association.to_sym)
103102
resource.klass.columns.each do |column|
104-
if !(column.respond_to?(:array) && column.array) &&
105-
(column.type == :string || column.type == :text)
103+
if !(column.respond_to?(:array) && column.array) && text_type?(column.type)
106104
if @collection.search_fields.nil? || (association_search &&
107105
association_search.include?(column.name))
108106
conditions << association_search_condition(resource.table_name,
@@ -125,8 +123,7 @@ def search_param
125123
unless association_search.empty?
126124
resource = @resource.reflect_on_association(association.to_sym)
127125
resource.klass.columns.each do |column|
128-
if !(column.respond_to?(:array) && column.array) &&
129-
(column.type == :string || column.type == :text)
126+
if !(column.respond_to?(:array) && column.array) && text_type?(column.type)
130127
if association_search.include?(column.name)
131128
conditions << association_search_condition(resource.table_name,
132129
column.name)
@@ -278,5 +275,11 @@ def belongs_to_filter
278275

279276
@records
280277
end
278+
279+
private
280+
281+
def text_type?(type_sym)
282+
[:string, :text, :citext].include? type_sym
283+
end
281284
end
282285
end

0 commit comments

Comments
 (0)