-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store Alchemy::Page as a single PgSearch::Document
Previously the page and the ingredients (and in previous versions also essences) were stored as separate PgSearch::Document entries. On search these document were combined to a single document to make it usable in the search itself. These mechanic made it pretty difficult to extend the search with other models. In newer versions of Alchemy the page is only available after a new page version is released and these mechanic is used to create a single PgSearch::Document with the content of the page and all supported ingredients. This change makes the whole search and the index creation less complex. The Alchemy module now has searchable_ingredients attribute which makes it easier to change the indexing from the outside. Furthermore a few extensions are now in a Search namespace, because they are not related to the PgSearch gem.
- Loading branch information
1 parent
7418988
commit acc17d3
Showing
13 changed files
with
147 additions
and
296 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Alchemy::Search::IngredientExtension | ||
def searchable_content | ||
send(Alchemy.searchable_ingredients[type.to_sym])&.squish | ||
end | ||
|
||
def searchable? | ||
Alchemy.searchable_ingredients.has_key?(type.to_sym) && | ||
(definition.key?(:searchable) ? definition[:searchable] : true) && | ||
!!element&.searchable? | ||
end | ||
end | ||
|
||
# add the PgSearch model to all ingredients | ||
Alchemy::Ingredient.prepend(Alchemy::Search::IngredientExtension) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Enable Postgresql full text indexing. | ||
# | ||
module Alchemy::Search::PageExtension | ||
def searchable? | ||
(definition.key?(:searchable) ? definition[:searchable] : true) && | ||
searchable && public? && !layoutpage? | ||
end | ||
end | ||
|
||
Alchemy::Page.prepend(Alchemy::Search::PageExtension) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,6 @@ | ||
<li class="search_result"> | ||
<% page = result.page %> | ||
<% page = result.searchable %> | ||
<h3><%= link_to page.name, show_alchemy_page_path(page) %></h3> | ||
<% if result.excerpts.any? %> | ||
<% result.excerpts.each do |excerpt| %> | ||
<p><%= highlighted_excerpt(excerpt, params[:query]) %></p> | ||
<% end %> | ||
<% else %> | ||
<p><%= page.meta_description %></p> | ||
<% end %> | ||
<p><%= highlighted_excerpt(result.content, params[:query]) %></p> | ||
<p><%= link_to page.urlname, show_alchemy_page_path(page) %></p> | ||
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.