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
6 changed files with 22 additions and 17 deletions

View File

@ -60,7 +60,8 @@ class SearchService < BaseService
TagSearchService.new.call(
@query,
limit: @limit,
offset: @offset
offset: @offset,
exclude_unreviewed: @options[:exclude_unreviewed]
)
end

View File

@ -2,11 +2,12 @@
class TagSearchService < BaseService
def call(query, options = {})
@query = query.strip.gsub(/\A#/, '')
@offset = options[:offset].to_i
@limit = options[:limit].to_i
@query = query.strip.gsub(/\A#/, '')
@offset = options.delete(:offset).to_i
@limit = options.delete(:limit).to_i
@options = options
results = from_elasticsearch if Chewy.enabled?
results = from_elasticsearch if Chewy.enabled?
results ||= from_database
results
@ -72,12 +73,15 @@ class TagSearchService < BaseService
},
}
TagsIndex.query(query).filter(filter).limit(@limit).offset(@offset).objects.compact
definition = TagsIndex.query(query)
definition = definition.filter(filter) if @options[:exclude_unreviewed]
definition.limit(@limit).offset(@offset).objects.compact
rescue Faraday::ConnectionFailed, Parslet::ParseFailed
nil
end
def from_database
Tag.search_for(@query, @limit, @offset)
Tag.search_for(@query, @limit, @offset, @options)
end
end