lib/redi_search_rails.rb
# search the index for specific keyword(s) and return output as array of objects
#
# @param keyword [String]  'some keyword'
# @param offset [Integer]   default 0
# @param keyword [Integer]  default 10
# @return [Array]   [{"id": "gid://application_name/User/unique_id", "name": "Bob", "age": "100"}, ...]
search the index for specific keyword(s) and return output as array of objects
search the index for specific keyword ( s ) and return output as array of objects
def ft_search_format(args)
      results = ft_search(args)
      output = []
      results.shift  
      results.each_slice(2) do |result|
        attributes = {}
        result[1].each_slice(2) do |attribute|
          attributes[attribute[0]] = attribute[1]
        end
        hash = {id: result[0]}.merge(attributes)
        output << OpenStruct.new(hash)
      end
      return output
    rescue Exception => e
      Rails.logger.error e if defined? Rails
      return e.message
    end
def ft_search_format ( args ) results = ft_search ( args ) output = [ ] results . shift results . each_slice ( 2 ) do | result | attributes = { } result [ 1 ] . each_slice ( 2 ) do | attribute | attributes [ attribute [ 0 ] ] = attribute [ 1 ] end hash = { id : result [ 0 ] } . merge ( attributes ) output << OpenStruct . new ( hash ) end return output rescue Exception => e Rails . logger . error e if defined? Rails return e . message end
search the index for specific keyword(s) and return output as array of objects
search the index for specific keyword ( s ) and return output as array of objects
# => transform into array of objects # => remove count
None
Array
args
<not_specific>
keyword
<not_specific>
None
offset
<not_specific>
None