class WinewooCore::Services::ElasticSearch::WinesServices
Public Class Methods
new()
click to toggle source
# File lib/winewoo_core/services/elastic_search/wines_services.rb, line 6 def initialize @client = Elasticsearch::Client.new host: 'reco.kasual.biz:9200' end
Public Instance Methods
fetch_wines(keywords, page, per_page)
click to toggle source
# File lib/winewoo_core/services/elastic_search/wines_services.rb, line 11 def fetch_wines(keywords, page, per_page) from = page * per_page size = per_page raw = @client.search index: "wines", body: request_body(keywords, from, size) Rails.logger.info "WINEWOO RAW #{raw}" Parsers::WinesParser.parse(raw["hits"]["hits"]) end
Private Instance Methods
request_body(keywords, from, size)
click to toggle source
# File lib/winewoo_core/services/elastic_search/wines_services.rb, line 25 def request_body(keywords, from, size) words = keywords.split(/( |-|')/).keep_if {|str| str.length > 2}.map {|str| "+#{str}*" } { query: { query_string: { fields:["name"], query: I18n.transliterate(words.join(" ")) } }, sort: [ { "_score" => { order: "desc" }} ], from: from, size: size } end