0
0
Fork 0

Add exclude_unreviewed param to GET /api/v2/search REST API (#11977)

Make it so normal search returns even unreviewed matches, but
autosuggestions do not.

Fix #11960
This commit is contained in:
Eugen Rochko 2019-09-28 01:02:21 +02:00 committed by GitHub
parent 234c729c52
commit ab33c4df94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 17 deletions

View file

@ -124,16 +124,15 @@ class Tag < ApplicationRecord
end
end
def search_for(term, limit = 5, offset = 0)
def search_for(term, limit = 5, offset = 0, options = {})
normalized_term = normalize(term.strip).mb_chars.downcase.to_s
pattern = sanitize_sql_like(normalized_term) + '%'
query = Tag.listable.where(arel_table[:name].lower.matches(pattern))
query = query.where(arel_table[:name].lower.eq(normalized_term).or(arel_table[:reviewed_at].not_eq(nil))) if options[:exclude_unreviewed]
Tag.listable
.where(arel_table[:name].lower.matches(pattern))
.where(arel_table[:name].lower.eq(normalized_term).or(arel_table[:reviewed_at].not_eq(nil)))
.order(Arel.sql('length(name) ASC, name ASC'))
.limit(limit)
.offset(offset)
query.order(Arel.sql('length(name) ASC, name ASC'))
.limit(limit)
.offset(offset)
end
def find_normalized(name)