Class: EBSCO::EDS::SearchCriteria

Inherits:
Object
  • Object
show all
Includes:
JSONable
Defined in:
lib/ebsco/eds/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JSONable

#as_json, included, #to_json

Constructor Details

#initialize(options = {}, info) ⇒ SearchCriteria

Returns a new instance of SearchCriteria.



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/ebsco/eds/options.rb', line 164

def initialize(options = {}, info)

  # defaults
  @SearchMode = info.default_search_mode
  @IncludeFacets = 'y'
  @Sort = 'relevance'
  @AutoSuggest = info.default_auto_suggest
  @AutoCorrect = info.default_auto_correct
  _has_query = false

  @Expanders = info.default_expander_ids
  _my_expanders = []
  _available_expander_ids = info.available_expander_ids

  @Limiters = nil
  _my_limiters = []

  @FacetFilters = []
  filter_id = 1

  @RelatedContent = info.default_related_content_types
  _my_related_content = []
  _available_related_content_types = info.available_related_content_types

  # blacklight year range slider input
  # "range"=>{"pub_year_tisim"=>{"begin"=>"1970", "end"=>"1980"}}
  if options.has_key?('range')
    if options['range'].has_key?('pub_year_tisim')
      begin_year = nil
      end_year = nil
      if options['range']['pub_year_tisim'].has_key?('begin')
        begin_year = options['range']['pub_year_tisim']['begin']
      end
      if options['range']['pub_year_tisim'].has_key?('end')
        end_year = options['range']['pub_year_tisim']['end']
      end
      unless begin_year.nil? or end_year.nil?
        pub_year_tisim_range = begin_year + '-01/' + end_year + '-01'
        _my_limiters.push({:Id => 'DT1', :Values => [pub_year_tisim_range]})
      end
    end
  end

  options.each do |key, value|

    case key

      # ====================================================================================
      # query
      # ====================================================================================
      when :query, 'q'

        # add blacklight search_fields
        _field_code = ''
        if options.has_key? 'search_field'
          _field = options['search_field']
          case _field
            when 'author'
              _field_code = 'AU'
            when 'subject'
              _field_code = 'SU'
            when 'title'
              _field_code = 'TI'
            when 'text'
              _field_code = 'TX'
            when 'abstract'
              _field_code = 'AB'
            when 'source'
              _field_code = 'SO'
            when 'issn'
              _field_code = 'IS'
            when 'isbn'
              _field_code = 'IB'
            when 'descriptor'
              _field_code = 'DE'
            when 'series'
              _field_code = 'SE'
            when 'subject_heading'
              _field_code = 'SH'
            when 'keywords'
              _field_code = 'KW'
            when /[A-Z]{2}/
              _field_code = _field
          end
        end

        if not _field_code == ''
          @Queries =  [{:FieldCode => _field_code, :Term => value}]
        else
          @Queries =  [{:Term => value}]
        end
        _has_query = true

      # ====================================================================================
      # mode
      # ====================================================================================
      when :mode
        if info.available_search_mode_types.include? value.downcase
          @SearchMode = value.downcase
        else
          @SearchMode = info.default_search_mode
        end

      # ====================================================================================
      # facets
      # ====================================================================================
      when :include_facets
        @IncludeFacets = value ? 'y' : 'n'

      when :facet_filters
        @FacetFilters = value

      # ====================================================================================
      # sort
      # ====================================================================================
      when :sort, 'sort'
        if info.available_sorts(value.downcase).empty?
          if value.downcase == 'newest' || value.downcase == 'pub_date_sort desc'
            @Sort = 'date'
          elsif value.downcase == 'oldest' || value.downcase == 'pub_date_sort asc'
            @Sort = 'date2'
          elsif value.downcase == 'score desc'
            @Sort = 'relevance'
          else
            @Sort = 'relevance'
          end
        else
          @Sort = value.downcase
        end

      # ====================================================================================
      # publication id
      # ====================================================================================
      when :publication_id
        @PublicationId = value

      # ====================================================================================
      # auto suggest & correct
      # ====================================================================================
      when :auto_suggest, 'auto_suggest'
        @AutoSuggest = value ? 'y' : 'n'

      when :auto_correct, 'auto_correct'
        @AutoCorrect = value ? 'y' : 'n'

      # ====================================================================================
      # expanders
      # ====================================================================================
      when :expanders
        value.each do |item|
          if _available_expander_ids.include? item.downcase
            _my_expanders.push(item)
          end
        end
        if _my_expanders.empty?
          _my_expanders = info.default_expander_ids
        end
        @Expanders = _my_expanders

      # ====================================================================================
      # solr limiters & facets
      # ====================================================================================

      when 'f'
        _search_limiter_list = []
        if value.has_key?('eds_search_limiters_facet')
          _search_limiter_list = value['eds_search_limiters_facet']
        end
        info.available_limiters.each do |limiter|
          # only handle 'select' limiters (ones with values of 'y' or 'n')
          if ( _search_limiter_list.include? limiter['Label'] or _search_limiter_list.include? limiter['Id']) and limiter['Type'] == 'select'
            _my_limiters.push({:Id => limiter['Id'], :Values => ['y']})
          end
        end

        # date limiters
        if value.has_key?('eds_publication_year_range_facet')
          _list = value['eds_publication_year_range_facet']
          _this_year = Date.today.year
          _this_month = Date.today.month
          _list.each do |item|
            if item == 'This year'
              _range = _this_year.to_s + '-01/' + _this_year.to_s + '-' + _this_month.to_s
              _my_limiters.push({:Id => 'DT1', :Values => [_range]})
            end
            if item == 'Last 3 years'
              _range = (_this_year-3).to_s + '-' + _this_month.to_s + '/' + _this_year.to_s + '-' + _this_month.to_s
              _my_limiters.push({:Id => 'DT1', :Values => [_range]})
            end
            if item == 'Last 10 years'
              _range = (_this_year-10).to_s + '-' + _this_month.to_s + '/' + _this_year.to_s + '-' + _this_month.to_s
              _my_limiters.push({:Id => 'DT1', :Values => [_range]})
            end
            if item == 'Last 50 years'
              _range = (_this_year-50).to_s + '-' + _this_month.to_s + '/' + _this_year.to_s + '-' + _this_month.to_s
              _my_limiters.push({:Id => 'DT1', :Values => [_range]})
            end
            if item == 'More than 50 years ago'
              _range = '0000-01/' + (_this_year-50).to_s + '-12'
              _my_limiters.push({:Id => 'DT1', :Values => [_range]})
            end
          end
        end

        # Language
        if value.has_key?('eds_language_facet')
          lang_list = value['eds_language_facet']
          lang_list.each do |item|
            @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'Language', 'Value' => item}]})
            filter_id += 1
          end
        end
        # SubjectEDS
        if value.has_key?('eds_subject_topic_facet')
          subj_list = value['eds_subject_topic_facet']
          subj_list.each do |item|
            @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'SubjectEDS', 'Value' => item}]})
            filter_id += 1
          end
        end
        # SubjectGeographic
        if value.has_key?('eds_subjects_geographic_facet')
          subj_list = value['eds_subjects_geographic_facet']
          subj_list.each do |item|
            @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'SubjectGeographic', 'Value' => item}]})
            filter_id += 1
          end
        end
        # Publisher
        if value.has_key?('eds_publisher_facet')
          subj_list = value['eds_publisher_facet']
          subj_list.each do |item|
            @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'Publisher', 'Value' => item}]})
            filter_id += 1
          end
        end
        # Journal
        if value.has_key?('eds_journal_facet')
          subj_list = value['eds_journal_facet']
          subj_list.each do |item|
            @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'Journal', 'Value' => item}]})
            filter_id += 1
          end
        end
        # Category
        if value.has_key?('eds_category_facet')
          subj_list = value['eds_category_facet']
          subj_list.each do |item|
            @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'Category', 'Value' => item}]})
            filter_id += 1
          end
        end
        # LocationLibrary
        if value.has_key?('eds_library_location_facet')
          subj_list = value['eds_library_location_facet']
          subj_list.each do |item|
            @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'LocationLibrary', 'Value' => item}]})
            filter_id += 1
          end
        end
        # CollectionLibrary
        if value.has_key?('eds_library_collection_facet')
          subj_list = value['eds_library_collection_facet']
          subj_list.each do |item|
            @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'CollectionLibrary', 'Value' => item}]})
            filter_id += 1
          end
        end
        # AuthorUniversity
        if value.has_key?('eds_author_university_facet')
          subj_list = value['eds_author_university_facet']
          subj_list.each do |item|
            @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'AuthorUniversity', 'Value' => item}]})
            filter_id += 1
          end
        end
        # PublicationYear
        if value.has_key?('eds_publication_year_facet')
          year_list = value['eds_publication_year_facet']
          year_list.each do |item|
            @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'PublicationYear', 'Value' => item}]})
            filter_id += 1
          end
        end

        # Special Cases:

        # SourceType
        if value.has_key?('eds_publication_type_facet')
          f_list = value['eds_publication_type_facet']
          f_list.each do |item|
            @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'SourceType', 'Value' => item}]})
            filter_id += 1
          end
        end
        # ContentProvider
        if value.has_key?('eds_content_provider_facet')
          subj_list = value['eds_content_provider_facet']
          subj_list.each do |item|
            @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'ContentProvider', 'Value' => item}]})
            filter_id += 1
          end
        end

      # ====================================================================================
      # limiters
      # ====================================================================================

      when :limiters
        value.each do |item|
          _key = item.split(':',2).first.upcase
          _values = item.split(':',2).last
          # is limiter id available?
          if info.available_limiter_ids.include? _key
            _limiter = info.available_limiters(_key)
            # if multi-value, add the values if they're available
            if _limiter['Type'] == 'multiselectvalue'
              _available_values = info.available_limiter_values(_key)
              _multi_values = []
              _values.split(',').each do |val|
                # todo: make case insensitive?
                if _available_values.include? val
                  _multi_values.push(val)
                end
              end
              if _multi_values.empty?
                # do nothing, none of the values are available
              else
                _my_limiters.push({:Id => _key, :Values => _multi_values})
              end
              # single value, just pass it on
            else
              _my_limiters.push({:Id => _key, :Values => [_values]})
            end
          end
        end
        @Limiters = _my_limiters

      # ====================================================================================
      # related content
      # ====================================================================================
      when :related_content
        value.each do |item|
          if _available_related_content_types.include? item.downcase
            _available_related_content_types.push(item)
          else
            # silently ignore
          end
        end
        if _my_related_content.empty?
          _my_related_content = info.default_related_content_types
        end
        @RelatedContent = _my_related_content

      # ====================================================================================
      # unsupported parameters, ignore
      # ====================================================================================
      else
        # ignore

    end

  end # end options parsing

  # set solr limiters, if any
  @Limiters = _my_limiters

end

Instance Attribute Details

#AutoCorrectObject

Returns the value of attribute AutoCorrect.



161
162
163
# File 'lib/ebsco/eds/options.rb', line 161

def AutoCorrect
  @AutoCorrect
end

#AutoSuggestObject

Returns the value of attribute AutoSuggest.



161
162
163
# File 'lib/ebsco/eds/options.rb', line 161

def AutoSuggest
  @AutoSuggest
end

#ExpandersObject

Returns the value of attribute Expanders.



161
162
163
# File 'lib/ebsco/eds/options.rb', line 161

def Expanders
  @Expanders
end

#FacetFiltersObject

Returns the value of attribute FacetFilters.



161
162
163
# File 'lib/ebsco/eds/options.rb', line 161

def FacetFilters
  @FacetFilters
end

#IncludeFacetsObject

Returns the value of attribute IncludeFacets.



161
162
163
# File 'lib/ebsco/eds/options.rb', line 161

def IncludeFacets
  @IncludeFacets
end

#LimitersObject

Returns the value of attribute Limiters.



161
162
163
# File 'lib/ebsco/eds/options.rb', line 161

def Limiters
  @Limiters
end

#PublicationIdObject

Returns the value of attribute PublicationId.



161
162
163
# File 'lib/ebsco/eds/options.rb', line 161

def PublicationId
  @PublicationId
end

#QueriesObject

Returns the value of attribute Queries.



161
162
163
# File 'lib/ebsco/eds/options.rb', line 161

def Queries
  @Queries
end

#RelatedContentObject

Returns the value of attribute RelatedContent.



161
162
163
# File 'lib/ebsco/eds/options.rb', line 161

def RelatedContent
  @RelatedContent
end

#SearchModeObject

Returns the value of attribute SearchMode.



161
162
163
# File 'lib/ebsco/eds/options.rb', line 161

def SearchMode
  @SearchMode
end

#SortObject

Returns the value of attribute Sort.



161
162
163
# File 'lib/ebsco/eds/options.rb', line 161

def Sort
  @Sort
end