Class: SearchController

Inherits:
UmlautController show all
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 Sfx4 direct database and Sfx4Solr (SFX indexed in Solr via Sunspot) 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

Methods included from Umlaut::ControllerBehavior

#default_url_options, #set_locale

Methods included from UmlautConfigurable

set_default_configuration!

Constructor Details

#initialize(*params) ⇒ SearchController

Returns a new instance of SearchController.



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

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

Instance Method Details

#auto_complete_for_journal_titleObject

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)



135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'app/controllers/search_controller.rb', line 135

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

#booksObject

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

#indexObject



43
44
45
46
# File 'app/controllers/search_controller.rb', line 43

def index
  @page_title = t('umlaut.search.journals_page_name')
  journals()
end

#journal_listObject

Used for browse-by-letter



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/controllers/search_controller.rb', line 115

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
  @page_title = t('umlaut.search.browse_by_jtitle', :query => params['id'])
  # 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_searchObject

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



67
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 67

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) && (umlaut_config.lookup!("search.display_zero_hit_results") != true)
    # If we have 0 hits, also redirect to resolve, unless config tells
    # us not to.
    redirect_to(  url_for_with_co({:controller => 'resolve'}, @search_context_object) )
  end

  @page_title = @display_results.length > 0 ? 'Journal titles that ' : 'No journal titles found that '
  @page_title +=
    (params["umlaut.title_search_type"] == "begins") ?
      'begin with ' : 'contain '
  @page_title += "'" + params['rft.jtitle'] + "'"
end

#journalsObject



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