Class: Buhos::AnalysisSearches

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

Overview

Class to analysis groups of searches:

  • Resolutions of each document on every stage

  • Databases and types of every search

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(searches) ⇒ AnalysisSearches

Returns a new instance of AnalysisSearches.



37
38
39
40
41
# File 'lib/buhos/analysis_searches.rb', line 37

def initialize(searches)

  @searches=searches
  @searches_id=@searches.map(&:id)
end

Instance Attribute Details

#searchesObject (readonly)

Returns the value of attribute searches.



35
36
37
# File 'lib/buhos/analysis_searches.rb', line 35

def searches
  @searches
end

#searches_idObject (readonly)

Returns the value of attribute searches_id.



36
37
38
# File 'lib/buhos/analysis_searches.rb', line 36

def searches_id
  @searches_id
end

Instance Method Details

#canonical_documents_idObject



48
49
50
# File 'lib/buhos/analysis_searches.rb', line 48

def canonical_documents_id
  records.map(&:canonical_document_id).uniq
end

#recordsObject



45
46
47
# File 'lib/buhos/analysis_searches.rb', line 45

def records
  Record.join(:records_searches, record_id: :id ).where(search_id: @searches_id)
end

#records_by_cdObject



51
52
53
54
# File 'lib/buhos/analysis_searches.rb', line 51

def records_by_cd
  $db["SELECT canonical_document_id, COUNT(*) as n FROM records_searches rs
INNER JOIN records r ON rs.record_id=r.id WHERE rs.search_id #{sql_in} GROUP BY r.canonical_document_id ORDER BY n desc"]
end

#records_by_cd_summaryObject



74
75
76
77
78
79
80
# File 'lib/buhos/analysis_searches.rb', line 74

def records_by_cd_summary
  records_by_cd.inject({}) do |ac,v|
    ac[v[:n]]||=0
    ac[v[:n]]+=1
    ac
  end
end

#resolutions_by_cd(sr, stage) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/buhos/analysis_searches.rb', line 55

def resolutions_by_cd(sr,stage)
  ars=Analysis_SR_Stage.new(sr,stage)
  rbc=ars.resolutions_by_cd
  canonical_documents_id.inject({}) do |ac,v|
    ac[v]=rbc[v]
    ac
  end
end

#resolutions_by_cd_summary(sr, stage) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/buhos/analysis_searches.rb', line 64

def resolutions_by_cd_summary(sr,stage)
  resolutions_by_cd(sr, stage).inject({}) {|ac,v|
    type=v[1].nil? ? Resolution::PREVIOUS_REJECT : v[1]
    ac[type]||=0
    ac[type]+=1
    ac
  }
end

#sql_inObject



42
43
44
# File 'lib/buhos/analysis_searches.rb', line 42

def sql_in
  "IN (#{searches_id.join(",")})"
end

#summary_sources_databasesObject



81
82
83
84
85
86
# File 'lib/buhos/analysis_searches.rb', line 81

def summary_sources_databases
  $db["SELECT  s.source, s.bibliographic_database_id,  COUNT(*) as n FROM records r
INNER JOIN records_searches rs ON r.id=rs.record_id
INNER JOIN searches s ON s.id=rs.search_id WHERE s.id #{sql_in}
GROUP BY  s.source, s.bibliographic_database_id ORDER BY s.source, s.bibliographic_database_id"]
end