Class: Ddr::Index::CSVQueryResult
Constant Summary
collapse
- MAX_ROWS =
10**8
- CSV_MV_SEPARATOR =
";"
lambda { ||
if term = Ddr::Models::DescriptiveMetadata.mapping[.to_sym]
term.unqualified_name.to_s
else
end
}
Instance Attribute Summary
#conn, #query
Instance Method Summary
collapse
#count, #initialize
Instance Method Details
#[](index_or_header) ⇒ Object
27
28
29
|
# File 'lib/ddr/index/csv_query_result.rb', line 27
def []()
table.by_col_or_row![]
end
|
55
56
57
|
# File 'lib/ddr/index/csv_query_result.rb', line 55
def
query.fields.empty? ? :first_row : query_field_headings
end
|
#csv_opts ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/ddr/index/csv_query_result.rb', line 35
def csv_opts
{ headers: ,
return_headers: false,
write_headers: true,
header_converters: [ DESCMD_HEADER_CONVERTER ],
}
end
|
#data ⇒ Object
71
72
73
74
|
# File 'lib/ddr/index/csv_query_result.rb', line 71
def data
raw = conn.get("select", params: solr_csv_params)
raw.gsub(/\\#{CSV_MV_SEPARATOR}/, CSV_MV_SEPARATOR)
end
|
#delete_empty_columns! ⇒ Object
19
20
21
|
# File 'lib/ddr/index/csv_query_result.rb', line 19
def delete_empty_columns!
table.by_col!.delete_if { |c, vals| vals.all?(&:nil?) }
end
|
#each(&block) ⇒ Object
23
24
25
|
# File 'lib/ddr/index/csv_query_result.rb', line 23
def each(&block)
table.by_row!.each(&block)
end
|
#query_field_headings ⇒ Object
51
52
53
|
# File 'lib/ddr/index/csv_query_result.rb', line 51
def query_field_headings
query.fields.map { |f| f.respond_to?(:heading) ? f.heading : f.to_s }
end
|
59
60
61
|
# File 'lib/ddr/index/csv_query_result.rb', line 59
def
== :first_row
end
|
#solr_csv_opts ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/ddr/index/csv_query_result.rb', line 43
def solr_csv_opts
{ "csv.mv.separator" => CSV_MV_SEPARATOR,
"csv.header" => ,
"rows" => solr_csv_rows,
"wt" => "csv",
}
end
|
#solr_csv_params ⇒ Object
67
68
69
|
# File 'lib/ddr/index/csv_query_result.rb', line 67
def solr_csv_params
params.merge(solr_csv_opts)
end
|
#solr_csv_rows ⇒ Object
63
64
65
|
# File 'lib/ddr/index/csv_query_result.rb', line 63
def solr_csv_rows
query.rows || MAX_ROWS
end
|
#table ⇒ Object
31
32
33
|
# File 'lib/ddr/index/csv_query_result.rb', line 31
def table
@table ||= CSV.parse(data, csv_opts)
end
|