Sha256: bb04bb5e201b4a0fa6cece92e3343bb10d2b6aaf35760ce8743e8239564ce2d9
Contents?: true
Size: 1.08 KB
Versions: 17
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true # rubocop:disable Style/ClassAndModuleChildren module Maglev::Page::SearchConcern extend ActiveSupport::Concern class_methods do def search(keyword, locale) return [] if keyword.blank? title = search_title_node(locale) query = all.select(Maglev::Page.arel_table[Arel.star], title).distinct.joins(:paths).order(title.asc) matching = "%#{keyword}%" query.where( search_title_clause(matching, locale).or( search_path_clause(matching, locale) ) ) end protected def search_title_clause(query, locale) search_title_node(locale).matches(query) end def search_path_clause(query, locale) path = Maglev::PagePath.arel_table[:value] path.matches(query).and(path.eq(locale)) end def search_title_node(locale) Arel::Nodes::InfixOperation.new('->>', arel_table[:title_translations], Arel::Nodes.build_quoted(locale)) end end end # rubocop:enable Style/ClassAndModuleChildren
Version data entries
17 entries across 17 versions & 1 rubygems