Class: Elrec::Searcher
- Inherits:
-
Object
- Object
- Elrec::Searcher
- Defined in:
- lib/elrec/searcher.rb
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
-
#initialize(host = "localhost", port = 1055) ⇒ Searcher
constructor
A new instance of Searcher.
- #recommend_from_item_id(item_id, how_many, include_known_items) ⇒ Object
- #recommend_from_item_list(item_list, how_many, include_known_items) ⇒ Object
- #recommend_from_user_id(user_id, how_many, include_known_items) ⇒ Object
Constructor Details
#initialize(host = "localhost", port = 1055) ⇒ Searcher
Returns a new instance of Searcher.
6 7 8 9 10 |
# File 'lib/elrec/searcher.rb', line 6 def initialize(host = "localhost", port = 1055) @host = host @port = port self.connect end |
Instance Method Details
#close ⇒ Object
43 44 45 46 |
# File 'lib/elrec/searcher.rb', line 43 def close @socket.write("\n") @socket.close end |
#connect ⇒ Object
12 13 14 |
# File 'lib/elrec/searcher.rb', line 12 def connect @socket = TCPSocket.open(@host, @port) end |
#recommend_from_item_id(item_id, how_many, include_known_items) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/elrec/searcher.rb', line 25 def recommend_from_item_id(item_id, how_many, include_known_items) json = "{'inputType' : 'item_id', " + "'itemId' : #{item_id}, " + "'howMany' : #{how_many}, " + "'includeKnownItems' : #{include_known_items}}\n" @socket.write(json) return @socket.gets end |
#recommend_from_item_list(item_list, how_many, include_known_items) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/elrec/searcher.rb', line 34 def recommend_from_item_list(item_list, how_many, include_known_items) json = "{'inputType' : 'item_id_list', " + "'itemIdList' : #{item_list}, " + "'howMany' : #{how_many}, " + "'includeKnownItems' : #{include_known_items}}\n" @socket.write(json) return @socket.gets end |
#recommend_from_user_id(user_id, how_many, include_known_items) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/elrec/searcher.rb', line 16 def recommend_from_user_id(user_id, how_many, include_known_items) json = "{'inputType' : 'user_id', " + "'userId' : #{user_id}, " + "'howMany' : #{how_many}, " + "'includeKnownItems' : #{include_known_items}}\n" @socket.write(json) return @socket.gets end |