Skip to content

Commit

Permalink
Add searchable field to page
Browse files Browse the repository at this point in the history
Allow to toggle searchable field on page level. The field is only available if it was enabled in the Alchemy - module. The information can be used by search plugins (e.g. https://github.com/AlchemyCMS/alchemy-pg_search).
  • Loading branch information
kulturbande committed Jan 20, 2023
1 parent bef444b commit 57ec4db
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Page < BaseRecord
:restricted,
:robot_index,
:robot_follow,
:searchable,
:sitemap,
:tag_list,
:title,
Expand Down
9 changes: 9 additions & 0 deletions app/views/alchemy/admin/pages/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
<%= f.input :title,
input_html: {'data-alchemy-char-counter' => 60} %>

<% if Alchemy.enable_searchable %>
<div class="input check_boxes">
<label class="control-label"><%= Alchemy.t(:fulltext_search) %></label>
<div class="control_group">
<%= page_status_checkbox(@page, :searchable) %>
</div>
</div>
<% end %>

<div class="input check_boxes">
<label class="control-label"><%= Alchemy.t(:search_engines) %></label>
<div class="control_group">
Expand Down
2 changes: 2 additions & 0 deletions config/locales/alchemy.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ en:
saved_link: "Link saved."
search: "search"
search_engines: "Search engines"
fulltext_search: "Fulltext search"
select_element: "Select element"
seperate_tags_with_comma: "Seperate tags with comma"
show_element_content: "Show content of this element."
Expand Down Expand Up @@ -879,6 +880,7 @@ en:
page_layout: "Page type"
public: "public"
restricted: "restricted"
searchable: "show in search"
robot_follow: "robot may follow links"
robot_index: "allow robot to index"
sitemap: "visible in sitemap"
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20230119112425_add_searchable_to_alchemy_pages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddSearchableToAlchemyPages < ActiveRecord::Migration[6.0]
def change
return if column_exists?(:alchemy_pages, :searchable)

add_column :alchemy_pages, :searchable, :boolean, default: true, null: false
end
end
13 changes: 13 additions & 0 deletions lib/alchemy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,17 @@ def self.preview_sources=(sources)
def self.publish_targets
@_publish_targets ||= Set.new
end

# Enable full text search configuration
#
# It enables a searchable checkbox in the page form to toggle
# the searchable field. These information can used in a search
# plugin (e.g. https://github.com/AlchemyCMS/alchemy-pg_search).
#
# == Example
#
# # config/initializers/alchemy.rb
# Alchemy.enable_searchable = true
#
mattr_accessor :enable_searchable, default: false
end

0 comments on commit 57ec4db

Please sign in to comment.