Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development merge #175

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/assets/stylesheets/primary.css
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ table {
}

/* Tablet, 640-900px */
@media only screen and (min-width: 640px) and (max-width: 900px) {
@media only screen and (min-width: 640px) and (max-width: 1020px) {

/*nav bar*/
.nav-container {
Expand Down Expand Up @@ -541,8 +541,8 @@ table {
}
}

/* Desktop, from 900px */
@media only screen and (min-width: 900px) {
/* 'Large' desktop, from 1020px */
@media only screen and (min-width: 1020px) {

/*nav bar*/
.nav-container {
Expand Down Expand Up @@ -583,6 +583,10 @@ table {
.result-panel {
flex-direction: row;
justify-content: space-between;
gap: 1rem;
gap: 0.75rem;

div {
flex: 1 0 100px;
}
}
}
3 changes: 2 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def filter_field_name(field)
legislationTitle_t: 'Legislation',
department_t: 'Department',
year: 'Date',
month: 'Date'
month: 'Date',
session: 'Session'
}

field_names[field.to_sym]
Expand Down
30 changes: 21 additions & 9 deletions app/models/search_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,6 @@ def ses_data
hierarchy_ses_data.merge(returned_data)
end

def facets
return [] unless search

facet_field_data = search.dig(:data, 'facets')
return [] if facet_field_data.blank?

facet_field_data.except("count").map { |k, v| { field_name: k, facets: sort_facets(v['buckets']) } }
end

def query_time
return unless search&.dig(:data, 'responseHeader', 'QTime')

Expand All @@ -252,12 +243,33 @@ def filter
search.dig(:search_parameters, :filter)
end

def facets
return [] unless search

facet_field_data = search.dig(:data, 'facets')
return [] if facet_field_data.blank?

facet_field_data.slice("type_sesrollup", "publisher_ses", "legislature_ses", "date_dt", "department_ses",
"member_ses", "tablingMember_ses", "askingMember_ses", "leadMember_ses",
"answeringMember_ses", "legislativeStage_ses", "legislationTitle_ses", "subject_ses",
"topic_ses", "year").map { |k, v| { field_name: k, facets: sort_facets(v['buckets']) } }
end

def type_facets
ret = {}
facets.select { |facet| facet.dig(:field_name) == "type_sesrollup" }.first&.dig(:facets)&.each { |h| ret[h.dig("val")] = h.dig("count") }
ret
end

def session_facets
return [] unless search

facet_field_data = search.dig(:data, 'facets')
return [] if facet_field_data.blank?

facet_field_data.select { |field| field.split('_').first == "session" }
end

def sort_facets(facet_field)
facet_field.sort_by { |h| h["count"] }.reverse
end
Expand Down
170 changes: 166 additions & 4 deletions app/models/solr_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.facet_fields
[
'type_sesrollup',
'publisher_ses',
'session_t',
'legislature_ses',
'date_dt',
'department_ses',
'member_ses',
Expand Down Expand Up @@ -100,12 +100,117 @@ def search_filter
ranges << "[#{first_day}T00:00:00Z TO #{last_day}T23:59:59Z]"
end
"{!tag=month}date_dt:(#{ranges.join(" OR ")})"
elsif field_name == "session"
ranges = []
values.each do |value|
ranges << session_range_lookup(value)
end
# "{!tag=session_t}date_dt:(#{ranges.join(" OR ")})"
"{!tag=session_t}(date_dt:(#{ranges.join(" OR ")}) OR session_t:(#{values.join(" OR ")}))"
else
"{!tag=#{field_name}}#{field_name}:(#{values.join(" ")})"
end
end
end

def session_range_lookup(value)
# TODO: this will likely become a Session model, with persistance and admin features to set the names
# as well as 'from' and 'to' dates.

case value
when '2024-25'
'[2024-05-25T00:00:00Z TO *]'
when '2023-24'
'[2023-10-27T00:00:00Z TO 2024-05-24T23:59:00Z]'
when '2022-23'
'[2022-04-29T00:00:00Z TO 2023-10-26T23:59:59Z]'
when '2021-22'
'[2021-05-11T00:00:00Z TO 2022-04-28T23:59:59Z]'
when '2019-21'
'[2019-12-17T00:00:00Z TO 2021-05-10T23:59:59Z]'
when '2019-19'
'[2019-10-14T01:00:00Z TO 2019-11-06T00:01:00Z]'
when '2017-19'
'[2017-05-03T00:00:00Z TO 2019-10-13T23:59:59Z]'
when '2016-17'
'[2016-05-13T00:00:00Z TO 2017-05-02T23:59:59Z]'
when '2015-16'
'[2015-04-01T00:00:00Z TO 2016-05-12T23:59:59Z]'
when '2014-15'
'[2014-05-14T23:00:00Z TO 2015-03-30T23:59:59Z]'
when '2013-14'
'[2013-04-25T23:00:00Z TO 2014-06-03T22:59:59Z]'
when '2012-13'
'[2012-05-08T23:00:00Z TO 2013-04-25T22:59:59Z]'
when '2010-12'
'[2010-05-17T23:00:00Z TO 2012-05-08T22:59:59Z]'
when '2009-10'
'[2009-11-18T00:00:00Z TO 2010-05-17T22:59:59Z]'
when '2008-09'
'[2008-12-03T00:00:00Z TO 2009-11-17T23:59:59Z]'
when '2007-08'
'[2007-11-06T00:00:00Z TO 2008-12-02T23:59:59Z]'
when '2006-07'
'[2006-11-15T00:00:00Z TO 2007-11-05T23:59:59Z]'
when '2005-06'
'[2005-05-10T23:00:00Z TO 2006-11-14T23:59:59Z]'
when '2004-05'
'[2004-11-23T00:00:00Z TO 2005-05-10T22:59:59Z]'
when '2003-04'
'[2003-11-26T00:00:00Z TO 2004-11-22T23:59:59Z]'
when '2002-03'
'[2002-11-10T00:00:00Z TO 2003-11-25T23:59:59Z]'
when '2001-02'
'[2001-06-12T23:00:00Z TO 2002-11-09T23:59:59Z]'
when '2000-01'
'[2000-12-06T00:00:00Z TO 2001-06-12T22:59:59Z]'
when '1999-00'
'[1999-11-17T00:00:00Z TO 2000-12-05T23:59:59Z]'
when '1998-99'
'[1998-11-24T00:00:00Z TO 1999-11-16T23:59:59Z]'
when '1997-98'
'[1997-05-06T23:00:00Z TO 1998-11-23T23:59:59Z]'
when '1996-97'
'[1996-10-22T23:00:00Z TO 1997-05-06T22:59:59Z]'
when '1995-96'
'[1995-11-15T00:00:00Z TO 1996-10-22T22:59:59Z]'
when '1994-95'
'[1994-11-16T00:00:00Z TO 1995-11-14T23:59:59Z]'
when '1993-94'
'[1993-11-18T00:00:00Z TO 1994-11-15T23:59:59Z]'
when '1992-93'
'[1992-04-26T23:00:00Z TO 1993-11-17T23:59:59Z]'
when '1991-92'
'[1991-10-31T00:00:00Z TO 1992-04-26T22:59:59Z]'
when '1990-91'
'[1990-11-07T00:00:00Z TO 1991-10-30T23:59:59Z]'
when '1989-90'
'[1989-11-21T00:00:00Z TO 1990-11-06T23:59:59Z]'
when '1988-89'
'[1988-11-22T00:00:00Z TO 1989-11-20T23:59:59Z]'
when '1987-88'
'[1987-06-16T23:00:00Z TO 1988-11-21T23:59:59Z]'
when '1986-87'
'[1986-11-12T00:00:00Z TO 1987-06-16T22:59:59Z]'
when '1985-86'
'[1985-11-05T00:00:00Z TO 1986-11-11T23:59:59Z]'
when '1984-85'
'[1984-11-06T00:00:00Z TO 1985-11-04T23:59:59Z]'
when '1983-84'
'[1983-06-14T23:00:00Z TO 1984-11-05T23:59:59Z]'
when '1982-83'
'[1982-11-03T00:00:00Z TO 1983-06-14T22:59:59Z]'
when '1981-82'
'[1981-11-04T00:00:00Z TO 1982-11-02T23:59:59Z]'
when '1980-81'
'[1980-11-20T00:00:00Z TO 1981-11-03T23:59:59Z]'
when '1979-80'
'[1979-05-08T23:00:00Z TO 1980-11-19T23:59:59Z]'
else
''
end
end

def sort
return 'date_dt desc' if sort_by == "date_desc"
return 'date_dt asc' if sort_by == "date_asc"
Expand All @@ -122,7 +227,6 @@ def facet_hash
"type" => facet_type(field_name),
"field" => field_name,
"limit" => facet_limit(field_name),
"missing" => true,
"mincount" => facet_mincount(field_name),
"domain" => { excludeTags: field_name }
}
Expand Down Expand Up @@ -151,6 +255,14 @@ def facet_hash
}
end

SolrSearch.sessions.each do |session|
ret["session_#{session}"] = {
"type": "query",
"q": "(session_t:#{session} OR date_dt:#{session_range_lookup(session)})",
"domain": { excludeTags: 'session_t' }
}
end

ret.to_json
end

Expand All @@ -162,9 +274,10 @@ def facet_type(field_name)
end

def facet_limit(field_name)
type_facet_names = ["type_sesrollup"]
# limit to 80 except for
facet_names = ["type_sesrollup"]

return 80 unless type_facet_names.include?(field_name)
return 80 unless facet_names.include?(field_name)

-1
end
Expand All @@ -176,6 +289,55 @@ def facet_mincount(field_name)
0 # replacement mincount
end

def self.sessions
[
'2024-25',
'2023-24',
'2022-23',
'2021-22',
'2019-21',
'2019-19',
'2017-19',
'2016-17',
'2015-16',
'2014-15',
'2013-14',
'2012-13',
'2010-12',
'2009-10',
'2008-09',
'2007-08',
'2006-07',
'2005-06',
'2004-05',
'2003-04',
'2002-03',
'2001-02',
'2000-01',
'1999-00',
'1998-99',
'1997-98',
'1996-97',
'1995-96',
'1994-95',
'1993-94',
'1992-93',
'1991-92',
'1990-91',
'1989-90',
'1988-89',
'1987-88',
'1986-87',
'1985-86',
'1984-85',
'1983-84',
'1982-83',
'1981-82',
'1980-81',
'1979-80'
]
end

private

def search_params
Expand Down
28 changes: 28 additions & 0 deletions app/views/search/_applied_filters.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<% unless request.params.dig(:filter).blank? %>
<section class="applied-filters">
<div class="applied-filter-container">
<% request.params.dig(:filter).sort.each do |filter| %>
<% filter.last.sort.each do |filter_value| %>
<div class="filter-wrapper">
<div class="filter">
<div class="top-row">
<span class="filter-name-label">
<%= filter_field_name(filter.first) %>
</span>
<span class="flex-spacer"></span>
<span class="filter-link">
<%= link_to sanitize("&#x2717;"), url_for(remove_filter_url(request.params, filter.first, filter_value)), class: 'modifiable-link' %>
</span>
</div>
<div class="bottom-row">
<div class="filter-name">
<%= object_display_name({ value: filter_field_value(filter, filter_value), field_name: filter.first }, singular: false) %>
</div>
</div>
</div>
</div>
<% end %>
<% end %>
</div>
</section>
<% end %>
44 changes: 44 additions & 0 deletions app/views/search/_search_control_panel.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<section class="search-control-panel">
<div class="search-control-panel-row">
<strong><%= number_to_delimited(@search_data.number_of_results, separator: ",") %><%= @search_data.number_of_results && @search_data.number_of_results > 1 ? " results" : " result" %></strong>
</div>
<div class="search-control-panel-row">
<span class="search-control-panel-item">
<span class="search-control-panel-label">Show detailed:</span>
<% if @search_data.show_detailed? %>
<%= render 'control_panel_current', value: 'On' %>
<%= render 'control_panel_link', link_text: 'Off', link_url: search_url(query: @search_data.query, filter: @search_data.filter, sort_by: @search_data.sort, results_per_page: @search_data.results_per_page, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: false) %>
<% else %>
<%= render 'control_panel_link', link_text: 'On', link_url: search_url(query: @search_data.query, filter: @search_data.filter, sort_by: @search_data.sort, results_per_page: @search_data.results_per_page, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: true) %>
<%= render 'control_panel_current', value: 'Off' %>
<% end %>
</span>

<span class="search-control-panel-item">
<label class="search-control-panel-label">
<span>Results:</span>
</label>
<% [10, 20, 50, 100].each do |per_page_option| %>
<% if @search_data.results_per_page == per_page_option %>
<%= render 'control_panel_current', value: per_page_option.to_i %>
<% else %>
<%= render 'control_panel_link', link_text: per_page_option.to_s, link_url: search_url(query: @search_data.query, filter: @search_data.filter, sort_by: @search_data.sort, results_per_page: per_page_option, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: @search_data.show_detailed) %>
<% end %>
<% end %>
</span>

<span class="search-control-panel-item">
<label class="search-control-panel-label">
<span>Sort by:</span>
</label>
<% if @search_data.sort == "date_desc" %>
<%= render 'control_panel_current', value: 'Newest first' %>
<%= render 'control_panel_link', link_text: 'Oldest first', link_url: search_url(query: @search_data.query, filter: @search_data.filter, sort_by: 'date_asc', results_per_page: @search_data.results_per_page, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: @search_data.show_detailed) %>
<% else %>
<%= render 'control_panel_link', link_text: 'Newest first', link_url: search_url(query: @search_data.query, filter: @search_data.filter, sort_by: 'date_desc', results_per_page: @search_data.results_per_page, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: @search_data.show_detailed) %>
<%= render 'control_panel_current', value: 'Oldest first' %>
<% end %>
</span>

</div>
</section>
Loading
Loading