Class: SearchController

Inherits:
ApplicationController show all
Includes:
SearchMethods::Sfx4
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

@@search_batch_size =
20
@@az_batch_size =
20
@@autocomplete_limit =
15

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#app_before_filter, #calculate_url_for_response, #error_404, #escape_xml, #frameset_action_url, #log_error, #log_processing, #params_preserve_xhr, #rescue_action_in_public, #url_for_with_co

Constructor Details

- (SearchController) initialize(*params)



39
40
41
42
43
# File 'app/controllers/search_controller.rb', line 39

def initialize(*params)
  super(*params)
  
  self.extend( search_method_module  )
end

Instance Method Details

- (Object) auto_complete_for_journal_title

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)



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/controllers/search_controller.rb', line 148

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

- (Object) books

Not sure if this action actually works or does anything at present.



60
61
62
# File 'app/controllers/search_controller.rb', line 60

def books
   @submit_action = params["umlaut.display_coins"] ? "display_coins" : "index"
end

- (Object) index



45
46
47
48
# File 'app/controllers/search_controller.rb', line 45

def index
  @page_title = "Journals"  
  journals()          
end

- (Object) journal_list

Used for browse-by-letter



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'app/controllers/search_controller.rb', line 120

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

- (Object) journal_search

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



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
113
114
115
116
# File 'app/controllers/search_controller.rb', line 72

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

- (Object) journals



50
51
52
53
54
55
56
57
# File 'app/controllers/search_controller.rb', line 50

def journals
  #fall through to view
  @submit_hash = params["umlaut.display_coins"] ? {:controller=>'resolve', :action=>'display_coins'} : {:controller=>'search', :action=>'journal_search'}

  # Render configed view, if configed, or default 
  view = AppConfig.param("search_view", "search/journals")
  render :template => view
end

- (Object) opensearch_description



162
163
164
# File 'app/controllers/search_controller.rb', line 162

def opensearch_description
  @headers['Content-Type'] = 'application/opensearchdescription+xml' 
end