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:
@ -60,7 +60,8 @@ class SearchService < BaseService
|
||||
TagSearchService.new.call(
|
||||
@query,
|
||||
limit: @limit,
|
||||
offset: @offset
|
||||
offset: @offset,
|
||||
exclude_unreviewed: @options[:exclude_unreviewed]
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user