Sha256: 906c2ab39cf546c1c91b8cd1c623f3591e208bca6afcc9792d259f263cf5db0b
Contents?: true
Size: 1.46 KB
Versions: 17
Compression:
Stored size: 1.46 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 = options end # Accesses Cms Api Search using #query and fetches search hits. # @api public def fetch_hits search_enum = search_results result = SES::SearchResult.new(search_enum.size) search_enum.take(@options[:limit] || 10).each do |obj| hard_coded_score = 1 result << SES::Hit.new(obj.id, hard_coded_score, {}, obj) end result end private def search_results now = Time.now search_enum = Obj.where(:_valid_from, :is_less_than, now.to_iso ).and_not(:_valid_until, :is_less_than, now.to_iso ).and_not(:_obj_class, :equals, 'Image' ).offset(@options[:offset] || 0 ).batch_size(@options[:limit] || 10) @query_string.strip.split(/[\s]+/).each do |word| search_enum.and(:*, :contains_prefix, word) end search_enum end end end
Version data entries
17 entries across 17 versions & 1 rubygems