Class: SearchController
- Inherits:
-
UmlautController
- Object
- ApplicationController
- UmlautController
- SearchController
- Defined in:
- app/controllers/search_controller.rb
Overview
The search controller handles searches fo manually entered citations, or possibly ambiguous citations generally. It also provides an A-Z list.
As a source of this data, it generally talks to the SFX database directly. The particular method it uses to get this data is defined in a SearchMethod module (app/controllers/search_methods), that gets applied to the controller. Currently Sfx3 direct database or Sfx4 direct database are supported. In either case with database connection info in your database.yml file under sfx_db.
Future plans include a local database of titles, perhaps loaded from an external KB. Not done yet.
SearchMethod module implementation
A search method is just a ruby module, that will be applied to a controller, that defines two methods:
[#find_by_title]
Takes no arguments, instead use methods in the controller like
#sfx_az_profile, #title_query_param, #search_type_param, #batch_size and
#page to return state. Returns a two-element array pair, first element
is a list of OpenURL::ContextObject for current batch, send element
is int total hit count.
[#find_by_group]
Used for clicks on "A", "B" ... "0-9", "Other" links. Find the group
link clicked on in params[:id]. Use #batch_size and #page for paging.
As in #find_by_title, return two element array, first elememt is array
of OpenURL::ContextObject, second element is total hit count.
Constant Summary collapse
- @@search_batch_size =
20
- @@az_batch_size =
20
- @@autocomplete_limit =
15
Instance Method Summary collapse
-
#auto_complete_for_journal_title ⇒ Object
Should return an array of hashes, with each has having :title and :object_id keys.
-
#books ⇒ Object
Not sure if this action actually works or does anything at present.
- #index ⇒ Object
-
#initialize(*params) ⇒ SearchController
constructor
A new instance of SearchController.
-
#journal_list ⇒ Object
Used for browse-by-letter.
-
#journal_search ⇒ Object
Or, redirect to resolve action for single hit.
- #journals ⇒ Object
- #opensearch_description ⇒ Object
Methods included from UmlautConfigurable
Constructor Details
#initialize(*params) ⇒ SearchController
Returns a new instance of SearchController.
37 38 39 40 41 |
# File 'app/controllers/search_controller.rb', line 37 def initialize(*params) super(*params) self.extend( search_method_module ) end |
Instance Method Details
#auto_complete_for_journal_title ⇒ Object
Should return an array of hashes, with each has having :title and :object_id keys. Can come from local journal index or SFX or somewhere else. :object_id is the SFX rft.object_id, and can be blank. (I think it’s SFX rft.object_id for local journal index too)
144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/controllers/search_controller.rb', line 144 def auto_complete_for_journal_title # Don't search on blank query. query = params['rft.jtitle'] search_type = params["umlaut.title_search_type"] || "contains" unless ( query.blank? ) (context_objects, total_count) = find_by_title @titles = context_objects.collect do |co| = co.referent. {:object_id => ["object_id"], :title => (["jtitle"] || ["btitle"] || ["title"])} end end render :text => @titles.to_json, :content_type => "application/json" end |
#books ⇒ Object
Not sure if this action actually works or does anything at present.
56 57 58 |
# File 'app/controllers/search_controller.rb', line 56 def books @submit_action = params["umlaut.display_coins"] ? "display_coins" : "index" end |
#index ⇒ Object
43 44 45 46 |
# File 'app/controllers/search_controller.rb', line 43 def index @page_title = "Journals" journals() end |
#journal_list ⇒ Object
Used for browse-by-letter
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/controllers/search_controller.rb', line 116 def journal_list @batch_size = batch_size @page = page @start_result_num = (@page * @batch_size) - (@batch_size - 1) (@display_results, @hits) = find_by_group # Calculate end-result number for display @end_result_num = @start_result_num + @batch_size - 1 if @end_result_num > @hits @end_result_num = @hits end # Use our ordinary search displayer to display # It'll notice the action and do just a bit of special stuff. render(:template => "search/journal_search") end |
#journal_search ⇒ Object
Or, redirect to resolve action for single hit. O hit also redirects to resolve action, as per SFX behavior–this gives a catalog lookup and an ILL form for 0-hit. param umlaut.title_search_type (aka sfx.title_search) can be ‘begins’, ‘exact’, or ‘contains’. Other form params should be OpenURL, generally
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/search_controller.rb', line 68 def journal_search @batch_size = batch_size @start_result_num = (page * batch_size) - (batch_size - 1) @search_context_object = context_object_from_params if (! params["rft.object_id"].blank? || ! params["rft.issn"].blank? || ! params["rft_id"].blank? ) # If we have an exact-type 'search', just switch to 'resolve' action redirect_to url_for_with_co( {:controller => 'resolve'}, context_object_from_params ) # don't do anything else. return elsif (params['rft.jtitle'].blank?) #Bad, error condition. If we don't have any of that other stuff above, # we need a title! Send them back to entry page with an error message. flash[:error] = "You must enter a journal title or other identifying information." redirect_to :controller=>:search, :action=>:index return end # Call our particular search method, #find_by_title added by search # method module. (@display_results, @hits) = self.find_by_title #find_by_title_via_sfx_db # Calculate end-result number for display @end_result_num = @start_result_num + batch_size - 1 if @end_result_num > @hits @end_result_num = @hits end if (@page == 1) && (@display_results.length == 1) # If we narrowed down to one result redirect # to resolve action. redirect_to( url_for_with_co({:controller => 'resolve'}, @display_results[0]) ) elsif (@display_results.length == 0) # 0 hits, do it too. redirect_to( url_for_with_co({:controller => 'resolve'}, @search_context_object) ) end end |
#journals ⇒ Object
48 49 50 51 52 53 |
# File 'app/controllers/search_controller.rb', line 48 def journals @submit_hash = params["umlaut.display_coins"] ? {:controller=>'resolve', :action=>'display_coins'} : {:controller=>'search', :action=>'journal_search'} # Render configed view, if configed, or default render umlaut_config.lookup!("search_view", "journals") end |
#opensearch_description ⇒ Object
158 159 160 |
# File 'app/controllers/search_controller.rb', line 158 def opensearch_description @headers['Content-Type'] = 'application/opensearchdescription+xml' end |