Class: Search
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Search
- Defined in:
- model/search.rb
Constant Summary collapse
- TYPES =
[:bibliographic_file, :uploaded_files, :references_list, :manual ]
- TYPES_NAMES =
{ bibliographic_file: "search_types.bibliographic_file", uploaded_files: "search_types.uploaded_files", references_list: "search_types.references_list", manual: "search_types.type_manual" }
- SOURCES =
[:database_search, :informal_search, :backward_snowballing, :forward_snowballing ]
- SOURCES_NAMES =
{:database_search=> "source.database_search", :informal_search => "source.informal_search", :backward_snowballing=> "source.backward_snowballing", :forward_snowballing=> "source.forward_snowballing"}
- SOURCES_NAMES_SHORT =
{:database_search=> "source.database_search_short", :informal_search => "source.informal_search_short", :backward_snowballing=> "source.backward_snowballing_short", :forward_snowballing=> "source.forward_snowballing_short"}
Class Method Summary collapse
- .get_source_name(source) ⇒ Object
- .get_source_name_short(source) ⇒ Object
- .get_type_name(type) ⇒ Object
Instance Method Summary collapse
- #bibliographical_database_name ⇒ Object
-
#delete ⇒ Object
Delete a search, and all references and associations to records.
- #is_type?(type) ⇒ Boolean
- #name ⇒ Object
- #records_n ⇒ Object
- #references ⇒ Object
- #references_n ⇒ Object
- #references_with_canonical_n(limit = nil) ⇒ Object
- #references_wo_canonical_n(limit = nil) ⇒ Object
- #references_wo_canonical_w_doi_n(limit = nil) ⇒ Object
- #source_name ⇒ Object
- #source_name_short ⇒ Object
- #type_name ⇒ Object
- #update_records(ref_ids) ⇒ Object
- #user_name ⇒ Object
Class Method Details
.get_source_name(source) ⇒ Object
76 77 78 |
# File 'model/search.rb', line 76 def self.get_source_name(source) source.nil? ? "source.error_no_source" : SOURCES_NAMES[source.to_sym] end |
.get_source_name_short(source) ⇒ Object
80 81 82 83 |
# File 'model/search.rb', line 80 def self.get_source_name_short(source) source.nil? ? "source.error_no_source" : SOURCES_NAMES_SHORT[source.to_sym] end |
.get_type_name(type) ⇒ Object
72 73 74 |
# File 'model/search.rb', line 72 def self.get_type_name(type) type.nil? ? "source.error_no_type" : TYPES_NAMES[type.to_sym] end |
Instance Method Details
#bibliographical_database_name ⇒ Object
112 113 114 |
# File 'model/search.rb', line 112 def bibliographical_database_name bibliographic_database ? bibliographic_database.name : nil end |
#delete ⇒ Object
Delete a search, and all references and associations to records
150 151 152 153 |
# File 'model/search.rb', line 150 def delete RecordsSearch.where(search_id:self[:id]).delete super end |
#is_type?(type) ⇒ Boolean
86 87 88 89 |
# File 'model/search.rb', line 86 def is_type? (type) raise "Invalid type" unless TYPES.include? type.to_sym self[:search_type]==type.to_s end |
#name ⇒ Object
68 69 70 |
# File 'model/search.rb', line 68 def name "#{self[:id]} - #{I18n::t(Search.get_source_name(self[:source]))} - #{self.date_creation} - #{self.bibliographical_database_name}" end |
#records_n ⇒ Object
105 106 107 |
# File 'model/search.rb', line 105 def records_n records.count end |
#references ⇒ Object
115 116 117 118 |
# File 'model/search.rb', line 115 def references ref_ids=$db["SELECT DISTINCT(rr.reference_id) FROM records_references rr INNER JOIN records_searches br ON rr.record_id=br.record_id WHERE br.search_id=?", self[:id]].map {|v| v[:reference_id]} Reference.where(:id=>ref_ids) end |
#references_n ⇒ Object
108 109 110 |
# File 'model/search.rb', line 108 def references_n references.count end |
#references_with_canonical_n(limit = nil) ⇒ Object
120 121 122 123 |
# File 'model/search.rb', line 120 def references_with_canonical_n(limit=nil) sql_limit= limit.nil? ? "" : "LIMIT #{limit.to_i}" $db["SELECT d.id, d.title, d.journal,d.volume, d.pages, d.author, d.year,COUNT(DISTINCT(br.record_id)) as n_records, COUNT(DISTINCT(r.id)) as n_references FROM canonical_documents d INNER JOIN bib_references r ON d.id=r.canonical_document_id INNER JOIN records_references rr ON r.id=rr.reference_id INNER JOIN records_searches br ON rr.record_id=br.record_id WHERE br.search_id=? GROUP BY d.id ORDER BY n_records DESC #{sql_limit}", self[:id] ] end |
#references_wo_canonical_n(limit = nil) ⇒ Object
125 126 127 128 |
# File 'model/search.rb', line 125 def references_wo_canonical_n(limit=nil) sql_limit= limit.nil? ? "" : "LIMIT #{limit.to_i}" $db["SELECT r.id, r.text, COUNT(DISTINCT(br.record_id)) as n FROM bib_references r INNER JOIN records_references rr ON r.id=rr.reference_id INNER JOIN records_searches br ON rr.record_id=br.record_id WHERE br.search_id=? AND canonical_document_id IS NULL GROUP BY r.id ORDER BY n DESC #{sql_limit}", self[:id] ] end |
#references_wo_canonical_w_doi_n(limit = nil) ⇒ Object
130 131 132 133 |
# File 'model/search.rb', line 130 def references_wo_canonical_w_doi_n(limit=nil) sql_limit= limit.nil? ? "" : "LIMIT #{limit.to_i}" $db["SELECT r.doi, MIN(r.text) as text , COUNT(DISTINCT(br.record_id)) as n FROM bib_references r INNER JOIN records_references rr ON r.id=rr.reference_id INNER JOIN records_searches br ON rr.record_id=br.record_id WHERE br.search_id=? AND canonical_document_id IS NULL AND doi IS NOT NULL GROUP BY r.doi ORDER BY n DESC #{sql_limit}", self[:id]] end |
#source_name ⇒ Object
94 95 96 |
# File 'model/search.rb', line 94 def source_name Search.get_source_name(self[:source]) end |
#source_name_short ⇒ Object
98 99 100 |
# File 'model/search.rb', line 98 def source_name_short Search.get_source_name_short(self[:source]) end |
#type_name ⇒ Object
90 91 92 |
# File 'model/search.rb', line 90 def type_name Search.get_type_name(self[:search_type]) end |
#update_records(ref_ids) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'model/search.rb', line 137 def update_records(ref_ids) records_ya_ingresados=$db["SELECT record_id FROM records_searches WHERE search_id=?", self[:id]].map {|v| v[:record_id]} records_por_ingresar = (ref_ids - records_ya_ingresados).uniq records_por_borrar = (records_ya_ingresados - ref_ids).uniq if records_por_ingresar $db[:records_searches].multi_insert (records_por_ingresar.map {|v| {:record_id => v, :search_id => self[:id]}}) end if records_por_borrar $db[:records_searches].where(:search_id => self[:id], :record_id => records_por_borrar).delete end end |
#user_name ⇒ Object
102 103 104 |
# File 'model/search.rb', line 102 def user_name user_id.nil? ? I18n::t(:No_username) : User[self.user_id].name end |