Class: EDSApi::EDSAPIResponse
- Inherits:
-
Object
- Object
- EDSApi::EDSAPIResponse
- Defined in:
- lib/edsapi_wrapper.rb
Overview
SEARCH RESPONSE PARSING
Instance Attribute Summary collapse
-
#dblabel ⇒ Object
Returns the value of attribute dblabel.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#publicationmatch ⇒ Object
Returns the value of attribute publicationmatch.
-
#records ⇒ Object
Returns the value of attribute records.
-
#researchstarters ⇒ Object
Returns the value of attribute researchstarters.
-
#results ⇒ Object
Returns the value of attribute results.
Instance Method Summary collapse
- #applied_expanders ⇒ Object
- #applied_facets ⇒ Object
- #applied_limiters ⇒ Object
- #current_search ⇒ Object
- #database_stats ⇒ Object
- #date_range ⇒ Object
- #did_you_mean ⇒ Object
- #facets(facet_provided_id = "all") ⇒ Object
- #hitcount ⇒ Object
-
#initialize(search_results) ⇒ EDSAPIResponse
constructor
A new instance of EDSAPIResponse.
- #querystring ⇒ Object
- #searchterms ⇒ Object
- #searchtime ⇒ Object
Constructor Details
#initialize(search_results) ⇒ EDSAPIResponse
Returns a new instance of EDSAPIResponse.
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 |
# File 'lib/edsapi_wrapper.rb', line 601 def initialize(search_results) @debug = "" @results = search_results unless @results['ErrorNumber'].nil? return search_results end if self.hitcount > 0 @records = [] search_results["SearchResult"]["Data"]["Records"].each do |record| @records.push(EDSApi::EDSAPIRecord.new(record)) end else @records = [] end @researchstarters = [] = @results.fetch('SearchResult',{}).fetch('RelatedContent',{}).fetch('RelatedRecords',{}) if .count > 0 .each do || if ["Type"] == "rs" rs_entries = .fetch('Records',{}) if rs_entries.count > 0 rs_entries.each do |rs_record| @researchstarters.push(EDSApi::EDSAPIRecord.new(rs_record)) end end end end end @publicationmatch = [] = @results.fetch('SearchResult',{}).fetch('RelatedContent',{}).fetch('RelatedPublications',{}) if .count > 0 .each do || if ["Type"] == "emp" publicationmatches = .fetch('PublicationRecords',{}) if publicationmatches.count > 0 publicationmatches.each do |publication_record| @publicationmatch.push(EDSApi::EDSAPIRecord.new(publication_record)) end end end end end end |
Instance Attribute Details
#dblabel ⇒ Object
Returns the value of attribute dblabel.
599 600 601 |
# File 'lib/edsapi_wrapper.rb', line 599 def dblabel @dblabel end |
#debug ⇒ Object
Returns the value of attribute debug.
599 600 601 |
# File 'lib/edsapi_wrapper.rb', line 599 def debug @debug end |
#publicationmatch ⇒ Object
Returns the value of attribute publicationmatch.
599 600 601 |
# File 'lib/edsapi_wrapper.rb', line 599 def publicationmatch @publicationmatch end |
#records ⇒ Object
Returns the value of attribute records.
599 600 601 |
# File 'lib/edsapi_wrapper.rb', line 599 def records @records end |
#researchstarters ⇒ Object
Returns the value of attribute researchstarters.
599 600 601 |
# File 'lib/edsapi_wrapper.rb', line 599 def researchstarters @researchstarters end |
#results ⇒ Object
Returns the value of attribute results.
599 600 601 |
# File 'lib/edsapi_wrapper.rb', line 599 def results @results end |
Instance Method Details
#applied_expanders ⇒ Object
697 698 699 700 701 702 703 704 705 706 707 |
# File 'lib/edsapi_wrapper.rb', line 697 def af = [] = @results["SearchRequestGet"].fetch('SearchCriteriaWithActions',{}).fetch('ExpandersWithAction',{}) .each do |applied_explander| af.push(applied_explander) end return af end |
#applied_facets ⇒ Object
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
# File 'lib/edsapi_wrapper.rb', line 665 def applied_facets af = [] applied_facets_section = @results["SearchRequestGet"].fetch('SearchCriteriaWithActions',{}).fetch('FacetFiltersWithAction',{}) applied_facets_section.each do |applied_facets| applied_facets.fetch('FacetValuesWithAction',{}).each do |applied_facet| af.push(applied_facet) # unless applied_facet['FacetValuesWithAction'].nil? # applied_facet_values = applied_facet.fetch('FacetValuesWithAction',{}) # applied_facet_values.each do |applied_facet_value| # af.push(applied_facet_value) # end # end end end return af end |
#applied_limiters ⇒ Object
685 686 687 688 689 690 691 692 693 694 695 |
# File 'lib/edsapi_wrapper.rb', line 685 def applied_limiters af = [] applied_limters_section = @results["SearchRequestGet"].fetch('SearchCriteriaWithActions',{}).fetch('LimitersWithAction',{}) applied_limters_section.each do |applied_limter| af.push(applied_limter) end return af end |
#current_search ⇒ Object
661 662 663 |
# File 'lib/edsapi_wrapper.rb', line 661 def current_search CGI::parse(self.querystring) end |
#database_stats ⇒ Object
709 710 711 712 713 714 715 716 717 718 719 720 721 |
# File 'lib/edsapi_wrapper.rb', line 709 def database_stats databases = [] databases_facet = @results["SearchResult"]["Statistics"]["Databases"] databases_facet.each do |database| if DB_LABEL_LOOKUP.key?(database["Id"].upcase) db_label = DB_LABEL_LOOKUP[database["Id"].upcase]; else db_label = database["Label"] end databases.push({id: database["Id"], hits: database["Hits"], label: db_label}) end return databases end |
#date_range ⇒ Object
743 744 745 746 747 748 749 |
# File 'lib/edsapi_wrapper.rb', line 743 def date_range mindate = @results["SearchResult"]["AvailableCriteria"]["DateRange"]["MinDate"] maxdate = @results["SearchResult"]["AvailableCriteria"]["DateRange"]["MaxDate"] minyear = mindate[0..3] maxyear = maxdate[0..3] return {mindate: mindate, maxdate: maxdate, minyear:minyear, maxyear:maxyear} end |
#did_you_mean ⇒ Object
751 752 753 754 755 756 757 |
# File 'lib/edsapi_wrapper.rb', line 751 def did_you_mean dym_suggestions = @results.fetch('SearchResult', {}).fetch('AutoSuggestedTerms',{}) dym_suggestions.each do |term| return term end return nil end |
#facets(facet_provided_id = "all") ⇒ Object
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 |
# File 'lib/edsapi_wrapper.rb', line 723 def facets (facet_provided_id = "all") facets_hash = [] available_facets = @results.fetch('SearchResult',{}).fetch('AvailableFacets',{}) available_facets.each do |available_facet| if available_facet["Id"] == facet_provided_id || facet_provided_id == "all" facet_label = available_facet["Label"] facet_id = available_facet["Id"] facet_values = [] available_facet["AvailableFacetValues"].each do |available_facet_value| facet_value = available_facet_value["Value"] facet_count = available_facet_value["Count"] facet_action = available_facet_value["AddAction"] facet_values.push({value: facet_value, hitcount: facet_count, action: facet_action}) end facets_hash.push(id: facet_id, label: facet_label, values: facet_values) end end return facets_hash end |
#hitcount ⇒ Object
649 650 651 |
# File 'lib/edsapi_wrapper.rb', line 649 def hitcount @results["SearchResult"]["Statistics"]["TotalHits"] end |
#querystring ⇒ Object
657 658 659 |
# File 'lib/edsapi_wrapper.rb', line 657 def querystring @results["SearchRequestGet"]["QueryString"] end |
#searchterms ⇒ Object
759 760 761 762 763 764 765 766 767 768 769 770 |
# File 'lib/edsapi_wrapper.rb', line 759 def searchterms queries = @results.fetch('SearchRequestGet',{}).fetch('SearchCriteriaWithActions',{}).fetch('QueriesWithAction',{}) terms = [] queries.each do |query| query['Query']['Term'].split.each do |word| terms.push(word) end end return terms end |
#searchtime ⇒ Object
653 654 655 |
# File 'lib/edsapi_wrapper.rb', line 653 def searchtime @results["SearchResult"]["Statistics"]["TotalSearchTime"] end |