Sha256: 3133ef16baf3eed50cad1a6525b3b08f352ed8d27dd5f525ec5503605e879782
Contents?: true
Size: 1.89 KB
Versions: 3
Compression:
Stored size: 1.89 KB
Contents
module RailsConnector # This class provides a basic implementation for accessing the search using the cms api. # It can be activated by making it the superclass of SearchRequest. # It should be customized by subclassing. # @api public class CmsApiSearchRequest # Takes +query_string+ and +options+ for accessing Cms Api Search. # # +options+ is a hash and may include: # # <tt>:limit</tt>:: The maximum number of hits # <tt>:offset</tt>:: The search offset # @api public def initialize(query_string, options = {}) @query_string = query_string @options = Configuration.cms_api_options.merge(options) end # Accesses Cms Api Search using #query and fetches search hits. # @api public def fetch_hits hits = CmsRestApi.get(resource_path, { :query => query, :offset => @options[:offset], :size => @options[:limit], }) result = SES::SearchResult.new(hits['total']) hits['results'].each do |hit| hard_coded_score = 1 result << SES::Hit.new(hit['id'], hard_coded_score, hit) end result end private def resource_path "revisions/#{Workspace.current.revision_id}/objs/search" end def query now = Time.now q = [ { "field" => "_obj_class", "operator" => "equal", "value" => "Image", "negate" => true }, { "field" => "_valid_from", "operator" => "less_than", "value" => now.to_iso }, { "field" => "_valid_until", "operator" => "less_than", "value" => now.to_iso, "negate" => true } ] @query_string.strip.split(/[\s]+/).each do |word| q << { "field" => "*", "operator" => "prefix_search", "value" => word, } end q end end end
Version data entries
3 entries across 3 versions & 1 rubygems