Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toward replicating fact architecture for searches #120

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class SearchController < ApplicationController
before_action :validate_q!, only: %i[results]

layout false

def results
# hand off to Enhancer chain
@enhanced_query = Enhancer.new(params).enhanced_query
Expand Down
16 changes: 16 additions & 0 deletions app/controllers/static_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
class StaticController < ApplicationController
def style_guide; end

def results
@internal = internal_params
end

private

# TODO: More rigorously handle the validation of parameters for this request. The @internal instance variable will
# then be routed through the to_query method for the request to the internal search handler.
#
# This is duplicative of the validation in the search controller, but there should be a way to abstract that
# validation to a shared method somewhere.
def internal_params
params.permit(:q, :advanced, :citation)
.to_h { |key, value| [:"#{key}", value] }
end
end
91 changes: 42 additions & 49 deletions app/views/search/results.html.erb
Original file line number Diff line number Diff line change
@@ -1,55 +1,48 @@
<%= content_for(:title, "Search Results | MIT Libraries") %>
<%= render partial: "search_summary" %>

<div class="space-wrap">

<%= render partial: "shared/site_title" %>
<%= render partial: "form" %>
<%= render partial: "search_summary" %>

<div id="hint" aria-live="polite">
<%= render(partial: 'search/issn') %>
<%= render(partial: 'search/isbn') %>
<%= render(partial: 'search/pmid') %>
<%= render(partial: 'search/doi') %>
</div>
<div id="hint" aria-live="polite">
<%= render(partial: 'search/issn') %>
<%= render(partial: 'search/isbn') %>
<%= render(partial: 'search/pmid') %>
<%= render(partial: 'search/doi') %>
</div>

<%= render(partial: 'shared/error', collection: @errors) %>
<%= render(partial: 'shared/error', collection: @errors) %>

<div class="<%= @filters.present? ? 'layout-1q3q' : 'layout-3q1q' %> layout-band top-space">
<% if @filters.present? %>
<aside class="col1q filter-container">
<div id="filters">
<h2 class="hd-3">Filter your results</h2>
<h3 class="hd-4"><em><%= results_summary(@pagination[:hits]) %></em></h3>
<% @filters&.each_with_index do |(category, values), index| %>
<% if index == 0 %>
<%= render(partial: 'search/filter', locals: { category: category, values: values, first: true }) %>
<% else %>
<%= render(partial: 'search/filter', locals: { category: category, values: values, first: false }) %>
<% end %>
<div class="<%= @filters.present? ? 'layout-1q3q' : 'layout-3q1q' %> layout-band top-space">
<% if @filters.present? %>
<aside class="col1q filter-container">
<div id="filters">
<h2 class="hd-3">Filter your results</h2>
<h3 class="hd-4"><em><%= results_summary(@pagination[:hits]) %></em></h3>
<% @filters&.each_with_index do |(category, values), index| %>
<% if index == 0 %>
<%= render(partial: 'search/filter', locals: { category: category, values: values, first: true }) %>
<% else %>
<%= render(partial: 'search/filter', locals: { category: category, values: values, first: false }) %>
<% end %>
</div>
<%= render partial: 'shared/ask', locals: { display: 'view-lg' } %>
</aside>
<% end %>
<% end %>
</div>
<%= render partial: 'shared/ask', locals: { display: 'view-lg' } %>
</aside>
<% end %>

<div class="col3q wrap-results">
<% if @results.present? %>
<ul id="results" class="list-unbulleted">
<%= render(partial: 'search/result', collection: @results) %>
</ul>
<% else %>
<div id="results" class="no-results">
<p class="hd-2">No results found for your search</p>
</div>
<% end %>
</div>
<%= render partial: 'shared/ask', locals: { display: 'aside' } if @results.blank? %>
<div class="col3q wrap-results">
<% if @results.present? %>
<ul id="results" class="list-unbulleted">
<%= render(partial: 'search/result', collection: @results) %>
</ul>
<% else %>
<div id="results" class="no-results">
<p class="hd-2">No results found for your search</p>
</div>
<% end %>
</div>
<%= render partial: 'shared/ask', locals: { display: 'aside' } if @results.blank? %>

<% if @results.present? %>
<div id="pagination">
<%= render partial: "pagination" %>
</div>
<%= render partial: 'shared/ask', locals: { display: 'view-md' } %>
<% end %>
</div>
<% if @results.present? %>
<div id="pagination">
<%= render partial: "pagination" %>
</div>
<%= render partial: 'shared/ask', locals: { display: 'view-md' } %>
<% end %>
17 changes: 17 additions & 0 deletions app/views/static/results.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= content_for(:title, "Search Results | MIT Libraries") %>

<% data_url = "/internal?#{@internal.to_query}" %>

<div class="space-wrap">

<%= render partial: "shared/site_title" %>
<%= render partial: "search/form" %>

<div class="result-container top-space"
id="result-container"
data-controller="content-loader"
data-content-loader-url-value=<%= data_url %>>
<p>Your search is being completed...</p>
</div>

</div>
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
get 'issn', to: 'fact#issn'
get 'pmid', to: 'fact#pmid'

get 'internal', to: 'search#results', as: 'internal'

get 'record/(:id)',
to: 'record#view',
as: 'record',
:constraints => { :id => /[0-z\.\-\_~\(\)]+/ }
get 'results', to: 'search#results'
get 'style-guide', to: 'static#style_guide'
get 'results', to: 'static#results'
end
Loading