mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-02 13:12:13 +08:00
Add improved search for smart annotations
This commit is contained in:
parent
20ecc6dc0b
commit
777afd0e9b
2 changed files with 19 additions and 6 deletions
|
@ -12,10 +12,23 @@ module SearchableByNameModel
|
|||
.limit(Constants::SEARCH_LIMIT)
|
||||
end
|
||||
|
||||
def self.search_by_name_all(user, teams = [], query = nil)
|
||||
return if user.blank? || teams.blank?
|
||||
|
||||
sql_q = viewable_by_user(user, teams)
|
||||
# Remove non-breaking space,  
|
||||
query_array = query.gsub(/[[:space:]]+/, ' ').split(' ')
|
||||
if query_array.any?
|
||||
sql_q = sql_q.where("LOWER(#{table_name}.name) like all (array[?])", query_array.map { |c| "%#{c.downcase}%" })
|
||||
end
|
||||
sql_q.limit(Constants::SEARCH_LIMIT)
|
||||
end
|
||||
|
||||
def self.filter_by_teams(teams = [])
|
||||
return self if teams.empty?
|
||||
|
||||
if column_names.include? 'team_id'
|
||||
return where(team_id: teams)
|
||||
where(team_id: teams)
|
||||
else
|
||||
valid_subjects = Extends::ACTIVITY_SUBJECT_CHILDREN
|
||||
parent_array = [to_s.underscore]
|
||||
|
@ -38,7 +51,7 @@ module SearchableByNameModel
|
|||
query = child.to_s.camelize.constantize.where("#{last_parent}_id" => query)
|
||||
last_parent = child
|
||||
end
|
||||
return where("#{last_parent}_id" => query)
|
||||
where("#{last_parent}_id" => query)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ class SmartAnnotation
|
|||
|
||||
def my_modules
|
||||
# Search tasks
|
||||
MyModule.search_by_name(@current_user, @current_team, @query).active
|
||||
MyModule.search_by_name_all(@current_user, @current_team, @query).active
|
||||
.joins(experiment: :project)
|
||||
.where(projects: { archived: false }, experiments: { archived: false })
|
||||
.limit(Constants::ATWHO_SEARCH_LIMIT + 1)
|
||||
|
@ -22,14 +22,14 @@ class SmartAnnotation
|
|||
|
||||
def projects
|
||||
# Search projects
|
||||
Project.search_by_name(@current_user, @current_team, @query)
|
||||
Project.search_by_name_all(@current_user, @current_team, @query)
|
||||
.where(archived: false)
|
||||
.limit(Constants::ATWHO_SEARCH_LIMIT + 1)
|
||||
end
|
||||
|
||||
def experiments
|
||||
# Search experiments
|
||||
Experiment.search_by_name(@current_user, @current_team, @query)
|
||||
Experiment.search_by_name_all(@current_user, @current_team, @query)
|
||||
.joins(:project)
|
||||
.where(projects: { archived: false }, experiments: { archived: false })
|
||||
.limit(Constants::ATWHO_SEARCH_LIMIT + 1)
|
||||
|
@ -62,7 +62,7 @@ class SmartAnnotation
|
|||
res = RepositoryRow
|
||||
.active
|
||||
.where(repository: repository)
|
||||
.where_attributes_like('name', @query, at_search: true)
|
||||
.search_by_name_all(@current_user, @current_team, @query)
|
||||
.limit(Constants::ATWHO_SEARCH_LIMIT + 1)
|
||||
rep_items_list = []
|
||||
splitted_name = repository.name.gsub(/[^0-9a-z ]/i, '').split
|
||||
|
|
Loading…
Reference in a new issue