Class: EDSApi::EDSAPIResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/edsapi_wrapper.rb

Overview

SEARCH RESPONSE PARSING

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = []
	relatedrecords = @results.fetch('SearchResult',{}).fetch('RelatedContent',{}).fetch('RelatedRecords',{})
	if relatedrecords.count > 0
		relatedrecords.each do |related_item|
			if related_item["Type"] == "rs"
				rs_entries = related_item.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 = []
	relatedpublications = @results.fetch('SearchResult',{}).fetch('RelatedContent',{}).fetch('RelatedPublications',{})
	if relatedpublications.count > 0
		relatedpublications.each do |related_item|
			if related_item["Type"] == "emp"
				publicationmatches = related_item.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

#dblabelObject

Returns the value of attribute dblabel.



599
600
601
# File 'lib/edsapi_wrapper.rb', line 599

def dblabel
  @dblabel
end

#debugObject

Returns the value of attribute debug.



599
600
601
# File 'lib/edsapi_wrapper.rb', line 599

def debug
  @debug
end

#publicationmatchObject

Returns the value of attribute publicationmatch.



599
600
601
# File 'lib/edsapi_wrapper.rb', line 599

def publicationmatch
  @publicationmatch
end

#recordsObject

Returns the value of attribute records.



599
600
601
# File 'lib/edsapi_wrapper.rb', line 599

def records
  @records
end

#researchstartersObject

Returns the value of attribute researchstarters.



599
600
601
# File 'lib/edsapi_wrapper.rb', line 599

def researchstarters
  @researchstarters
end

#resultsObject

Returns the value of attribute results.



599
600
601
# File 'lib/edsapi_wrapper.rb', line 599

def results
  @results
end

Instance Method Details

#applied_expandersObject



697
698
699
700
701
702
703
704
705
706
707
# File 'lib/edsapi_wrapper.rb', line 697

def applied_expanders

	af = []

	applied_expanders_section = @results["SearchRequestGet"].fetch('SearchCriteriaWithActions',{}).fetch('ExpandersWithAction',{})
	applied_expanders_section.each do |applied_explander|
		af.push(applied_explander)
	end

	return af
end

#applied_facetsObject



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_limitersObject



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_searchObject



661
662
663
# File 'lib/edsapi_wrapper.rb', line 661

def current_search
	CGI::parse(self.querystring)
end

#database_statsObject



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_rangeObject



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_meanObject



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

#hitcountObject



649
650
651
# File 'lib/edsapi_wrapper.rb', line 649

def hitcount
	@results["SearchResult"]["Statistics"]["TotalHits"]
end

#querystringObject



657
658
659
# File 'lib/edsapi_wrapper.rb', line 657

def querystring
	@results["SearchRequestGet"]["QueryString"]
end

#searchtermsObject



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

#searchtimeObject



653
654
655
# File 'lib/edsapi_wrapper.rb', line 653

def searchtime
	@results["SearchResult"]["Statistics"]["TotalSearchTime"]
end