Class: Watson::RetrieveAndRank
- Inherits:
-
Object
- Object
- Watson::RetrieveAndRank
- Defined in:
- lib/watson/retrieve_and_rank.rb
Class Method Summary collapse
- .answers(data) ⇒ Object
- .configure(options = {}) ⇒ Object
- .send_message(message = '') ⇒ Object
- .url(query) ⇒ Object
Class Method Details
.answers(data) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/watson/retrieve_and_rank.rb', line 26 def self.answers(data) data.collect do |d| { source: 'retrieveandrank', intent: '', message: @message, tittle: d['title'], body: d['body'] } end end |
.configure(options = {}) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/watson/retrieve_and_rank.rb', line 3 def self.configure( = {}) @username = [:username] @password = [:password] @url = [:url] @cluster = [:cluster_id] @collection_name = [:collection_name] end |
.send_message(message = '') ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/watson/retrieve_and_rank.rb', line 11 def self.( = '') return if .empty? @message = query = URI.encode(@message) response = Excon.post(url(query), headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }, user: @username, password: @password) result = JSON.parse(response.body) answers(result['response']['docs']) end |
.url(query) ⇒ Object
33 34 35 36 |
# File 'lib/watson/retrieve_and_rank.rb', line 33 def self.url(query) @url + '/v1/solr_clusters/' + @cluster + '/solr/' + @collection_name + '/select?q=' + query + '&wt=json' end |