* Refactor iqdb response collection

This commit is contained in:
r888888888
2014-05-08 16:42:16 -07:00
parent d46042f038
commit 6de67da280
7 changed files with 7 additions and 18 deletions

View File

@@ -53,6 +53,6 @@ end
group :development do group :development do
gem 'ruby-prof' gem 'ruby-prof'
gem 'sql-logging' # gem 'sql-logging'
end end

View File

@@ -190,8 +190,6 @@ GEM
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
sprockets (~> 2.8) sprockets (~> 2.8)
sql-logging (3.0.8)
rails (> 3.0.0)
statistics2 (0.54) statistics2 (0.54)
term-ansicolor (1.3.0) term-ansicolor (1.3.0)
tins (~> 1.0) tins (~> 1.0)
@@ -264,7 +262,6 @@ DEPENDENCIES
simple_form simple_form
simplecov simplecov
sprockets-rails sprockets-rails
sql-logging
statistics2 statistics2
term-ansicolor term-ansicolor
therubyracer therubyracer

View File

@@ -24,7 +24,7 @@ protected
def create_by_post def create_by_post
@post = Post.find(params[:post_id]) @post = Post.find(params[:post_id])
@results = Iqdb::Server.default.similar(@post.id, 3) @results = Iqdb::Server.default.query(3, @post.preview_file_path)
render :layout => false, :action => "create_by_post" render :layout => false, :action => "create_by_post"
end end
end end

View File

@@ -14,7 +14,7 @@ module Iqdb
def find_similar def find_similar
if Danbooru.config.iqdb_hostname_and_port if Danbooru.config.iqdb_hostname_and_port
@matches = Iqdb::Server.new(*Danbooru.config.iqdb_hostname_and_port).query(3, @download.file_path).matches @matches = Iqdb::Server.default.query(3, @download.file_path).matches
end end
end end
end end

View File

@@ -2,7 +2,8 @@ module Iqdb
module Responses module Responses
class Collection class Collection
attr_reader :responses attr_reader :responses
delegate :each, :empty?, :any?, :to => :matches include Enumerable
delegate :<=>, :each, :to => :matches
def initialize(response_string) def initialize(response_string)
@responses = response_string.split(/\n/).map do |string| @responses = response_string.split(/\n/).map do |string|

View File

@@ -49,15 +49,6 @@ module Iqdb
end end
end end
def similar(post_id, results, flags = FLAG_DISCARD_COMMON_COEFFS)
request do
hex_id = post_id.to_s(16)
socket.puts "sim 0 #{flags} #{results} #{hex_id}"
socket.puts "done"
responses = Responses::Collection.new(socket.read)
end
end
def query(results, filename, flags = FLAG_DISCARD_COMMON_COEFFS) def query(results, filename, flags = FLAG_DISCARD_COMMON_COEFFS)
request do request do
socket.puts "query 0 #{flags} #{results} #{filename}" socket.puts "query 0 #{flags} #{results} #{filename}"

View File

@@ -1,6 +1,6 @@
<% if @download.matches.any? %> <% if @download.any? %>
<h3>Similar</h3> <h3>Similar</h3>
<% @download.matches.each do |match| %> <% @download.each do |match| %>
<%= PostPresenter.preview(Post.find(match.post_id)) %> <%= PostPresenter.preview(Post.find(match.post_id)) %>
<% end %> <% end %>
<% else %> <% else %>