fix query filter to avoid repeating results

This commit is contained in:
rulingcom 2024-06-11 22:45:53 +08:00
parent 2889581306
commit 061447c5d1
2 changed files with 14 additions and 17 deletions

View File

@ -270,6 +270,7 @@ class Admin::UniversalTablesController < OrbitAdminController
column.each do |c| column.each do |c|
columns = (columns | c.column_entries.any_of(:"text.en" => regex).or(:"text.zh_tw" => regex).or(:"content.en" => regex).or(:"content.zh_tw" => regex)) columns = (columns | c.column_entries.any_of(:"text.en" => regex).or(:"text.zh_tw" => regex).or(:"content.en" => regex).or(:"content.zh_tw" => regex))
end end
columns = columns.uniq{|col| col.table_entry_id}
columns_count = columns.count columns_count = columns.count
columns_count = 1 if columns_count==0 columns_count = 1 if columns_count==0
columns = Kaminari.paginate_array(columns,limit: columns_count) columns = Kaminari.paginate_array(columns,limit: columns_count)
@ -284,9 +285,3 @@ class Admin::UniversalTablesController < OrbitAdminController
params.require(:table_entry).permit! params.require(:table_entry).permit!
end end
end end

View File

@ -201,7 +201,12 @@ class UniversalTablesController < ApplicationController
regexes = keywords.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/) regexes = keywords.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/)
regex = Regexp.union(regexes.map{|word| Regexp.new(".*"+word+".*", "i")}) regex = Regexp.union(regexes.map{|word| Regexp.new(".*"+word+".*", "i")})
end end
columns = column.column_entries.any_of(:"text.en" => regex).or(:"text.zh_tw" => regex).or(:"content.en" => regex).or(:"content.zh_tw" => regex) if column.type == "text"
columns = column.column_entries.any_of(:"text.en" => regex, :"text.zh_tw" => regex)
elsif column.type == "editor"
columns = column.column_entries.any_of(:"content.en" => regex, :"content.zh_tw" => regex)
end
# .or(:"content.en" => regex).or(:"content.zh_tw" => regex)
if paginated if paginated
entries = TableEntry.where(:u_table_id=>table.id).sorting(params: params,table: table,column_entries: columns,page_num: params["page_no"],per: OrbitHelper.page_data_count) entries = TableEntry.where(:u_table_id=>table.id).sorting(params: params,table: table,column_entries: columns,page_num: params["page_no"],per: OrbitHelper.page_data_count)
else else
@ -253,6 +258,3 @@ class UniversalTablesController < ApplicationController
} }
end end
end end