Skip to content

Commit

Permalink
Consolidate suggest behavior into the CatalogController
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Sep 15, 2016
1 parent 77dd08e commit 3083ae9
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 49 deletions.
12 changes: 12 additions & 0 deletions app/controllers/concerns/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ def opensearch
end
end

def suggest
respond_to do |format|
format.json do
render json: suggestions_service.suggestions
end
end
end

def action_documents
fetch(Array(params[:id]))
end
Expand Down Expand Up @@ -264,4 +272,8 @@ def invalid_document_id_error(exception)
def start_new_search_session?
action_name == "index"
end

def suggestions_service
Blacklight::SuggestSearch.new(params, repository).suggestions
end
end
25 changes: 0 additions & 25 deletions app/controllers/concerns/blacklight/suggest.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/controllers/suggest_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/catalog/_search_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<% end %>

<label for="q" class="sr-only"><%= t('blacklight.search.form.search.label') %></label>
<%= text_field_tag :q, params[:q], placeholder: t('blacklight.search.form.search.placeholder'), class: "search_q q form-control", id: "q", autofocus: should_autofocus_on_search_box?, data: { autocomplete_enabled: autocomplete_enabled?, autocomplete_path: blacklight.suggest_index_path } %>
<%= text_field_tag :q, params[:q], placeholder: t('blacklight.search.form.search.placeholder'), class: "search_q q form-control", id: "q", autofocus: should_autofocus_on_search_box?, data: { autocomplete_enabled: autocomplete_enabled?, autocomplete_path: search_action_path(action: :suggest) } %>

<span class="input-group-btn">
<button type="submit" class="btn btn-primary search-btn" id="search">
Expand Down
2 changes: 0 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
delete "saved_searches/forget/:id", :to => "saved_searches#forget", :as => "forget_search"
post "saved_searches/forget/:id", :to => "saved_searches#forget"
post "/catalog/:id/track", to: 'catalog#track', as: 'track_search_context'

resources :suggest, only: :index, defaults: { format: 'json' }
end
1 change: 1 addition & 0 deletions lib/blacklight/routes/searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def call(mapper, options = {})
mapper.post ":id/track", action: 'track', as: 'track'

mapper.get "opensearch"
mapper.get 'suggest', as: 'suggest_index', defaults: { format: 'json' }
mapper.get "facet/:id", action: 'facet', as: 'facet'
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,19 @@ def export_as_mock
end
end

describe 'GET suggest' do
it 'returns JSON' do
get :suggest, params: { format: 'json' }
expect(response.body).to eq [].to_json
end
it 'returns suggestions' do
get :suggest, params: { format: 'json', q: 'new' }
json = JSON.parse(response.body)
expect(json.count).to eq 3
expect(json.first['term']).to eq 'new jersey'
end
end

describe "email/sms" do
let(:mock_response) { instance_double(Blacklight::Solr::Response, documents: [SolrDocument.new(id: 'my_fake_doc'), SolrDocument.new(id: 'my_other_doc')]) }
before do
Expand Down
17 changes: 0 additions & 17 deletions spec/controllers/suggest_controller_spec.rb

This file was deleted.

0 comments on commit 3083ae9

Please sign in to comment.