Sha256: b72706f942367dd464275844797a126e85419414a9ad3ae67398845a1062a097
Contents?: true
Size: 1.63 KB
Versions: 12
Compression:
Stored size: 1.63 KB
Contents
# frozen_string_literal: true module Lcms module Engine module Search class ElasticSearchDocument # return the corresponding repository def self.repository @repository ||= Lcms::Engine::Search::Repository.new end def repository self.class.repository end def index! repository.save self end def delete! repository.delete self end # Default search # # term: [String || Nil] # - [Nil] : return a match_all query # - [String] : perform a `fts_query` on the repository # # options: [Hash] # - per_page : number os results per page # - page : results page number # - <filter> : any doc specific filters, e.g: 'grade', 'subject', etc # def self.search(term, options = {}) return [] unless repository.index_exists? query = if term.present? repository.fts_query(term, options) else repository.all_query(options) end repository.search query end # this is necessary for the ActiveModel::Serializer::CollectionSerializer#as_json method to work # (used on the Pagination#serialize_with_pagination) # NOTE: https://github.com/rails-api/active_model_serializers/issues/891 def read_attribute_for_serialization(key) if key.try(:to_sym) == :id attributes.fetch(key) { id } else attributes[key] end end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems