iqdb: lower similarity cutoff, return more results (fix #4190).

* Change cutoffs on upload page to max 5 results, min. 20% similarity.
* Change cutoffs on standalone /iqdb_queries page to max 20 results, min. 0% similarity.
* /iqdb_queries.json: add `limit` and `similarity` params to change default cutoffs.
This commit is contained in:
evazion
2019-10-14 21:16:04 -05:00
parent ca54e2d67b
commit fa37b1edcd
4 changed files with 25 additions and 21 deletions

View File

@@ -1,12 +1,15 @@
class IqdbProxy
def self.query(image_url)
def self.query(url, limit, similarity)
raise NotImplementedError unless Danbooru.config.iqdbs_server.present?
url = URI.parse(Danbooru.config.iqdbs_server)
url.path = "/similar"
url.query = {url: image_url}.to_query
json = HTTParty.get(url.to_s, Danbooru.config.httparty_options).parsed_response
decorate_posts(json)
limit ||= 20
similarity ||= 0.0
query = { url: url, limit: limit }
response = HTTParty.get("#{Danbooru.config.iqdbs_server}/similar", query: query, **Danbooru.config.httparty_options)
json = decorate_posts(response.parsed_response)
json = json.select { |result| result["score"] >= similarity.to_f }.take(limit.to_i)
json
end
def self.decorate_posts(json)