Skip to content

Commit

Permalink
Merge pull request #37 from kulturbande/feature/page-searchable-toggle
Browse files Browse the repository at this point in the history
Page searchable toggle
  • Loading branch information
tvdeyen authored Jan 23, 2023
2 parents cb97ce9 + 56fa13c commit f86c841
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/extensions/alchemy/pg_search/page_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def self.prepended(base)

def searchable?
(definition.key?(:searchable) ? definition[:searchable] : true) &&
public? && !layoutpage?
searchable && public? && !layoutpage?
end

private
Expand Down
3 changes: 3 additions & 0 deletions lib/alchemy/pg_search/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Engine < ::Rails::Engine
# reindex the page after it was published
Alchemy.publish_targets << Alchemy::PgSearch::IndexPageJob

# enable searchable flag in page form
Alchemy.enable_searchable = true

# configure multiselect to find also partial words
# @link https://github.com/Casecommons/pg_search#searching-using-different-search-features
::PgSearch.multisearch_options = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true
# This migration comes from alchemy (originally 20220514072456)

class RestrictOnDeletePageIdForeignKeyFromAlchemyNodes < ActiveRecord::Migration[6.0]
def up
remove_foreign_key :alchemy_nodes, :alchemy_pages
add_foreign_key :alchemy_nodes, :alchemy_pages, column: :page_id, on_delete: :restrict
end

def down
remove_foreign_key :alchemy_nodes, :alchemy_pages
add_foreign_key :alchemy_nodes, :alchemy_pages, column: :page_id, on_delete: :cascade
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true
# This migration comes from alchemy (originally 20220622130905)

class AddPlaysinlineToAlchemyEssenceVideos < ActiveRecord::Migration[6.0]
def change
return if column_exists?(:alchemy_essence_videos, :playsinline)

add_column :alchemy_essence_videos, :playsinline, :boolean, default: false, null: false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This migration comes from alchemy (originally 20230119112425)
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
6 changes: 4 additions & 2 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2022_08_26_125413) do
ActiveRecord::Schema.define(version: 2023_01_19_143815) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -179,6 +179,7 @@
t.boolean "loop", default: false, null: false
t.boolean "muted", default: false, null: false
t.string "preload"
t.boolean "playsinline", default: false, null: false
t.index ["attachment_id"], name: "index_alchemy_essence_videos_on_attachment_id"
end

Expand Down Expand Up @@ -300,6 +301,7 @@
t.datetime "legacy_public_on"
t.datetime "legacy_public_until"
t.datetime "locked_at"
t.boolean "searchable", default: true, null: false
t.index ["creator_id"], name: "index_alchemy_pages_on_creator_id"
t.index ["language_id"], name: "index_alchemy_pages_on_language_id"
t.index ["locked_at", "locked_by"], name: "index_alchemy_pages_on_locked_at_and_locked_by"
Expand Down Expand Up @@ -390,7 +392,7 @@
add_foreign_key "alchemy_essence_pages", "alchemy_pages", column: "page_id"
add_foreign_key "alchemy_ingredients", "alchemy_elements", column: "element_id", on_delete: :cascade
add_foreign_key "alchemy_nodes", "alchemy_languages", column: "language_id"
add_foreign_key "alchemy_nodes", "alchemy_pages", column: "page_id", on_delete: :cascade
add_foreign_key "alchemy_nodes", "alchemy_pages", column: "page_id", on_delete: :restrict
add_foreign_key "alchemy_page_versions", "alchemy_pages", column: "page_id", on_delete: :cascade
add_foreign_key "alchemy_pages", "alchemy_languages", column: "language_id"
add_foreign_key "alchemy_picture_thumbs", "alchemy_pictures", column: "picture_id"
Expand Down
22 changes: 22 additions & 0 deletions spec/lib/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,28 @@
end
end
end

context 'page searchable' do
let(:searchable) { true }
let!(:page) { create(:alchemy_page, :public, name: "Searchable Page", searchable: searchable) }
let(:result) { Alchemy::PgSearch::Search.search "searchable" }

before do
Alchemy::PgSearch::Search.rebuild
end

it 'should find one page' do
expect(result.length).to eq(1)
end

context 'searchable disabled' do
let(:searchable) { false }

it 'should not find any page' do
expect(result.length).to eq(0)
end
end
end
end

context 'search' do
Expand Down

0 comments on commit f86c841

Please sign in to comment.