Skip to content

Commit

Permalink
Make search facets work properly in media mentions view
Browse files Browse the repository at this point in the history
Enlarge work description fields in admin
  • Loading branch information
peter-hank committed Sep 23, 2022
1 parent fbfccdf commit 2e65372
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). It uses [CalVer](https://calver.org/) as of May 2019.

## [22.09e](https://github.com/berkmancenter/lumendatabase/releases/tag/2022.09e) - 2022-09-23
### Fixed
* Enlarge the `work description` fields in the `admin`.
* Made `search facets` work properly in the `media mentions` view.

## [22.09d](https://github.com/berkmancenter/lumendatabase/releases/tag/2022.09d) - 2022-09-21
### Changed
* Moved the `site language` to the `database`.
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/lumen/faceted_search_form.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $('ol.results-facets .dropdown-toggle').on 'click', (event) ->
list.html(loader)

$.get(
facet_notices_search_index_path + window.location.search,
facet_search_index_path + window.location.search,
{ facet_id: clicked_elem.nextAll('input[type=hidden]').first().attr('id') },
(response) ->
new_facet_list = $(response).find('ol').html()
Expand Down
6 changes: 4 additions & 2 deletions app/assets/javascripts/rails_admin/custom/notice_edit_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ class NoticeEditForm {
'type': 'object',
'properties': {
'description': {
'type': 'string'
'type': 'string',
'format': 'html'
},
'description_original': {
'type': 'string'
'type': 'string',
'format': 'html'
},
'kind': {
'type': 'string'
Expand Down
1 change: 1 addition & 0 deletions app/controllers/media_mentions/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def set_model_specific_variables
@ordering_options = MediaMention::ORDERING_OPTIONS
@url_root = URL_ROOT
@search_all_placeholder = 'Search all research and media mentions...'
@facet_search_index_path = facet_media_mentions_search_index_path
end

def item_searcher
Expand Down
24 changes: 1 addition & 23 deletions app/controllers/notices/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,6 @@ class Notices::SearchController < SearchController
URL_ROOT = 'notices'.freeze
SEARCHED_MODEL = Notice

def facet
if current_user.nil? && !Rails.env.test?
time_permission = session[:captcha_permission]
return if time_permission.nil? || time_permission < Time.now
end

filterable_field_facet = Notice::FILTERABLE_FIELDS.select { |filterable_field| filterable_field.parameter.to_s == params[:facet_id] }.first

resource_not_found and return if filterable_field_facet.nil?

@searcher = ElasticsearchQuery.new(params).tap do |searcher|
Notice::SEARCHABLE_FIELDS.each do |searched_field|
searcher.register searched_field
end

searcher.register(filterable_field_facet)
end

@searchdata = @searcher.search

render filterable_field_facet, locals: { results: @searchdata.response['aggregations'] }
end

private

def set_model_specific_variables
Expand All @@ -36,6 +13,7 @@ def set_model_specific_variables
@ordering_options = Notice::ORDERING_OPTIONS
@url_root = URL_ROOT
@search_all_placeholder = 'Search all notices...'
@facet_search_index_path = facet_notices_search_index_path
end

def item_searcher
Expand Down
18 changes: 18 additions & 0 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ def index
end
end

def facet
filterable_field_facet = @filterable_fields.select { |filterable_field| filterable_field.parameter.to_s == params[:facet_id] }.first

resource_not_found and return if filterable_field_facet.nil?

@searcher = ElasticsearchQuery.new(params, @model_class).tap do |searcher|
@searchable_fields.each do |searched_field|
searcher.register searched_field
end

searcher.register(filterable_field_facet)
end

@searchdata = @searcher.search

render filterable_field_facet, locals: { results: @searchdata.response['aggregations'] }
end

private

def html_responder; end
Expand Down
2 changes: 1 addition & 1 deletion app/views/search/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
<% end %>

<script type="text/javascript">
facet_notices_search_index_path = '<%= facet_notices_search_index_path %>';
facet_search_index_path = '<%= @facet_search_index_path %>';
loader_url = '<%= image_url("loader.gif") %>';
</script>
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@
get 'blog_feed', to: 'blog_feed#index'

namespace :media_mentions do
resources :search, only: [:index]
resources :search, only: %i[index] do
collection do
get :facet
end
end
end

resources :media_mentions, only: :show
Expand Down

0 comments on commit 2e65372

Please sign in to comment.