mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-01 13:13:22 +08:00
update search
This commit is contained in:
parent
dde9854bf1
commit
6155a458e7
1 changed files with 18 additions and 2 deletions
|
@ -35,6 +35,16 @@ class Table < ActiveRecord::Base
|
||||||
.select("result_tables.id")
|
.select("result_tables.id")
|
||||||
.distinct
|
.distinct
|
||||||
|
|
||||||
|
if query
|
||||||
|
a_query = query.strip
|
||||||
|
.gsub('_', '\\_')
|
||||||
|
.gsub('%', '\\%')
|
||||||
|
.split(/\s+/)
|
||||||
|
.map { |t| '%' + t + '%' }
|
||||||
|
else
|
||||||
|
a_query = query
|
||||||
|
end
|
||||||
|
|
||||||
# Trim whitespace and replace it with OR character. Make prefixed
|
# Trim whitespace and replace it with OR character. Make prefixed
|
||||||
# wildcard search term and escape special characters.
|
# wildcard search term and escape special characters.
|
||||||
# For example, search term 'demo project' is transformed to
|
# For example, search term 'demo project' is transformed to
|
||||||
|
@ -47,13 +57,19 @@ class Table < ActiveRecord::Base
|
||||||
.join("|")
|
.join("|")
|
||||||
.gsub('\'', '"')
|
.gsub('\'', '"')
|
||||||
|
|
||||||
table_query = Table
|
table_query =
|
||||||
|
Table
|
||||||
.distinct
|
.distinct
|
||||||
.joins("LEFT OUTER JOIN step_tables ON step_tables.table_id = tables.id")
|
.joins("LEFT OUTER JOIN step_tables ON step_tables.table_id = tables.id")
|
||||||
.joins("LEFT OUTER JOIN result_tables ON result_tables.table_id = tables.id")
|
.joins("LEFT OUTER JOIN result_tables ON result_tables.table_id = tables.id")
|
||||||
.joins("LEFT OUTER JOIN results ON result_tables.result_id = results.id")
|
.joins("LEFT OUTER JOIN results ON result_tables.result_id = results.id")
|
||||||
.where("step_tables.id IN (?) OR result_tables.id IN (?)", step_ids, result_ids)
|
.where("step_tables.id IN (?) OR result_tables.id IN (?)", step_ids, result_ids)
|
||||||
.where("tables.data_vector @@ to_tsquery(?) ", s_query)
|
.where(
|
||||||
|
'(tables.name ILIKE ANY (array[?])'\
|
||||||
|
'OR tables.data_vector @@ to_tsquery(?))',
|
||||||
|
a_query,
|
||||||
|
s_query
|
||||||
|
)
|
||||||
|
|
||||||
new_query = table_query
|
new_query = table_query
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue