From b54dbec6832a23694934d6b99348b8d1176bd8ad Mon Sep 17 00:00:00 2001 From: j-corry Date: Thu, 12 Sep 2024 12:19:37 +0100 Subject: [PATCH] - Fix facet tests (use topic and subject for 'standard' facet behaviour) --- coverage/.last_run.json | 2 +- coverage/.resultset.json | 199 ++- coverage/index.html | 2465 +++++++++++++++++++++++++++---- spec/models/search_data_spec.rb | 30 +- 4 files changed, 2398 insertions(+), 298 deletions(-) diff --git a/coverage/.last_run.json b/coverage/.last_run.json index 9880d09..ca574ee 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "line": 83.76 + "line": 81.33 } } diff --git a/coverage/.resultset.json b/coverage/.resultset.json index f19890a..92b14d1 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -134,6 +134,7 @@ null, null, null, + null, 2, null, null, @@ -161,7 +162,7 @@ 1, null, null, - 0, + 132, null, null, 1, @@ -3005,15 +3006,6 @@ null, null, 1, - 15, - null, - 14, - 14, - null, - 32, - null, - null, - 1, 2, null, 1, @@ -3027,12 +3019,33 @@ null, null, 1, + 15, + null, + 14, + 14, + null, + 14, + null, + null, + 18, + null, + null, + 1, 4, 16, 4, null, null, 1, + 3, + null, + 3, + 3, + null, + 9, + null, + null, + 1, 54, null, null @@ -3369,6 +3382,13 @@ 0, null, 0, + 4, + 0, + 0, + 0, + null, + null, + 0, null, 4, null, @@ -3376,6 +3396,104 @@ null, null, 1, + null, + null, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + 0, + null, + null, + null, + 1, 3, 2, null, @@ -3396,7 +3514,6 @@ null, null, null, - null, 0, 0, 0, @@ -3421,6 +3538,14 @@ null, null, 0, + 0, + null, + null, + null, + null, + null, + null, + 0, null, null, 1, @@ -3431,6 +3556,7 @@ null, null, 1, + null, 0, null, 0, @@ -3447,6 +3573,55 @@ null, 1, null, + 9, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, 1, null, 0, @@ -3713,6 +3888,6 @@ ] } }, - "timestamp": 1725878428 + "timestamp": 1726139945 } } diff --git a/coverage/index.html b/coverage/index.html index 531d1e9..5da11f3 100644 --- a/coverage/index.html +++ b/coverage/index.html @@ -14,7 +14,7 @@ loading
-
Generated 2024-09-09T11:40:29+01:00
+
Generated 2024-09-12T12:19:05+01:00
@@ -23,14 +23,14 @@

All Files ( - 83.77% + 81.33% covered at - 91.21 + 87.95 hits/line ) @@ -43,11 +43,11 @@

- 1620 relevant lines, - 1357 lines covered and - 263 lines missed. + 1682 relevant lines, + 1368 lines covered and + 314 lines missed. ( - 83.77% + 81.33% )
@@ -138,12 +138,12 @@

app/helpers/application_helper.rb - 80.39 % - 143 + 82.35 % + 144 51 - 41 - 10 - 23.80 + 42 + 9 + 26.39 @@ -721,12 +721,12 @@

app/models/search_data.rb - 86.57 % - 264 - 134 - 116 + 87.14 % + 276 + 140 + 122 18 - 8.95 + 8.70 @@ -776,12 +776,12 @@

app/models/solr_search.rb - 61.64 % - 192 - 73 - 45 - 28 - 4.41 + 37.98 % + 354 + 129 + 49 + 80 + 2.61 @@ -2379,7 +2379,7 @@

app/helpers/application_helper.rb

- 80.39% + 82.35% lines covered @@ -2389,8 +2389,8 @@

51 relevant lines. - 41 lines covered and - 10 lines missed. + 42 lines covered and + 9 lines missed.
@@ -3573,7 +3573,7 @@

- month: 'Date' + month: 'Date',

@@ -3584,7 +3584,7 @@

- } + session: 'Session' @@ -3595,12 +3595,23 @@

+ } + + + +
+
  • + + + + +
  • -
  • +
  • 2 @@ -3611,7 +3622,7 @@

  • -
  • +
  • @@ -3622,7 +3633,7 @@

  • -
  • +
  • @@ -3633,7 +3644,7 @@

  • -
  • +
  • 1 @@ -3644,7 +3655,7 @@

  • -
  • +
  • 2 @@ -3655,7 +3666,7 @@

  • -
  • +
  • @@ -3666,7 +3677,7 @@

  • -
  • +
  • @@ -3677,7 +3688,7 @@

  • -
  • +
  • @@ -3688,7 +3699,7 @@

  • -
  • +
  • @@ -3699,7 +3710,7 @@

  • -
  • +
  • @@ -3710,7 +3721,7 @@

  • -
  • +
  • @@ -3721,7 +3732,7 @@

  • -
  • +
  • @@ -3732,7 +3743,7 @@

  • -
  • +
  • @@ -3743,7 +3754,7 @@

  • -
  • +
  • @@ -3754,7 +3765,7 @@

  • -
  • +
  • 1 @@ -3765,7 +3776,7 @@

  • -
  • +
  • @@ -3776,7 +3787,7 @@

  • -
  • +
  • @@ -3787,7 +3798,7 @@

  • -
  • +
  • @@ -3798,7 +3809,7 @@

  • -
  • +
  • @@ -3809,7 +3820,7 @@

  • -
  • +
  • @@ -3820,7 +3831,7 @@

  • -
  • +
  • 1 @@ -3831,7 +3842,7 @@

  • -
  • +
  • 2 @@ -3842,7 +3853,7 @@

  • -
  • +
  • @@ -3853,7 +3864,7 @@

  • -
  • +
  • @@ -3864,7 +3875,7 @@

  • -
  • +
  • 1 @@ -3875,7 +3886,7 @@

  • -
  • +
  • @@ -3886,7 +3897,7 @@

  • -
  • +
  • @@ -3897,8 +3908,8 @@

  • -
  • - +
  • + 132 @@ -3908,7 +3919,7 @@

  • -
  • +
  • @@ -3919,7 +3930,7 @@

  • -
  • +
  • @@ -3930,7 +3941,7 @@

  • -
  • +
  • 1 @@ -3941,7 +3952,7 @@

  • -
  • +
  • 3 @@ -3952,7 +3963,7 @@

  • -
  • +
  • @@ -3963,7 +3974,7 @@

  • -
  • +
  • @@ -30565,7 +30576,7 @@

    app/models/search_data.rb

    - 86.57% + 87.14% lines covered @@ -30574,8 +30585,8 @@

    - 134 relevant lines. - 116 lines covered and + 140 relevant lines. + 122 lines covered and 18 lines missed.
    @@ -33145,18 +33156,18 @@

    - def facets + def query_time

  • -
  • - 15 +
  • + 2 - return [] unless search + return unless search&.dig(:data, 'responseHeader', 'QTime')
  • @@ -33172,24 +33183,24 @@

    -
  • - 14 +
  • + 1 - facet_field_data = search.dig(:data, 'facets') + time = search&.dig(:data, 'responseHeader', 'QTime')
  • -
  • - 14 +
  • + 1 - return [] if facet_field_data.blank? + return if time.blank?
  • @@ -33205,13 +33216,13 @@

    -
  • - 32 +
  • + 1 - facet_field_data.except("count").map { |k, v| { field_name: k, facets: sort_facets(v['buckets']) } } + time.to_f / 1000
  • @@ -33244,18 +33255,18 @@

    - def query_time + def filter
    -
  • - 2 +
  • + 17 - return unless search&.dig(:data, 'responseHeader', 'QTime') + search.dig(:search_parameters, :filter)
  • @@ -33266,18 +33277,18 @@

    - + end
    -
  • - 1 +
  • + - time = search&.dig(:data, 'responseHeader', 'QTime') +
  • @@ -33288,12 +33299,23 @@

    - return if time.blank? + def facets + + + +
    +
  • + 15 + + + + + return [] unless search
  • -
  • +
  • @@ -33304,29 +33326,29 @@

  • -
  • - 1 +
  • + 14 - time.to_f / 1000 + facet_field_data = search.dig(:data, 'facets')
  • -
  • - +
  • + 14 - end + return [] if facet_field_data.blank?
  • -
  • +
  • @@ -33337,29 +33359,51 @@

  • -
  • - 1 +
  • + 14 - def filter + facet_field_data.slice("type_sesrollup", "publisher_ses", "legislature_ses", "date_dt", "department_ses",
  • -
  • - 17 +
  • + - search.dig(:search_parameters, :filter) + "member_ses", "tablingMember_ses", "askingMember_ses", "leadMember_ses",
  • -
  • +
  • + + + + + + "answeringMember_ses", "legislativeStage_ses", "legislationTitle_ses", "subject_ses", +
  • +
    + +
    +
  • + 18 + + + + + "topic_ses", "year").map { |k, v| { field_name: k, facets: sort_facets(v['buckets']) } } +
  • +
    + +
    +
  • @@ -33370,7 +33414,7 @@

  • -
  • +
  • @@ -33381,7 +33425,7 @@

  • -
  • +
  • 1 @@ -33392,7 +33436,7 @@

  • -
  • +
  • 4 @@ -33403,7 +33447,7 @@

  • -
  • +
  • 16 @@ -33414,7 +33458,7 @@

  • -
  • +
  • 4 @@ -33425,7 +33469,7 @@

  • -
  • +
  • @@ -33436,7 +33480,7 @@

  • -
  • +
  • @@ -33447,7 +33491,106 @@

  • -
  • +
  • + 1 + + + + + def session_facets +
  • +
    + +
    +
  • + 3 + + + + + return [] unless search +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + 3 + + + + + facet_field_data = search.dig(:data, 'facets') +
  • +
    + +
    +
  • + 3 + + + + + return [] if facet_field_data.blank? +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + 9 + + + + + facet_field_data.select { |field| field.split('_').first == "session" } +
  • +
    + +
    +
  • + + + + + + end +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • 1 @@ -33458,7 +33601,7 @@

  • -
  • +
  • 54 @@ -33469,7 +33612,7 @@

  • -
  • +
  • @@ -33480,7 +33623,7 @@

  • -
  • +
  • @@ -35945,7 +36088,7 @@

    app/models/solr_search.rb

    - 61.64% + 37.98% lines covered @@ -35954,9 +36097,9 @@

    - 73 relevant lines. - 45 lines covered and - 28 lines missed. + 129 relevant lines. + 49 lines covered and + 80 lines missed.
    @@ -36171,7 +36314,7 @@

    - 'session_t', + 'legislature_ses',

  • @@ -37089,46 +37232,46 @@

    -
  • - +
  • + 4 - else + elsif field_name == "session"
  • -
  • - 4 +
  • + - "{!tag=#{field_name}}#{field_name}:(#{values.join(" ")})" + ranges = []
  • -
  • +
  • - end + values.each do |value|
  • -
  • +
  • - end + ranges << session_range_lookup(value)
  • @@ -37139,7 +37282,7 @@

    - end + end @@ -37150,40 +37293,40 @@

    - + # "{!tag=session_t}date_dt:(#{ranges.join(" OR ")})"
    -
  • - 1 +
  • + - def sort + "{!tag=session_t}(date_dt:(#{ranges.join(" OR ")}) OR session_t:(#{values.join(" OR ")}))"
  • -
  • - 3 +
  • + - return 'date_dt desc' if sort_by == "date_desc" + else
  • -
  • - 2 +
  • + 4 - return 'date_dt asc' if sort_by == "date_asc" + "{!tag=#{field_name}}#{field_name}:(#{values.join(" ")})"
  • @@ -37194,18 +37337,18 @@

    - + end
    -
  • - 1 +
  • + - 'date_dt desc' + end
  • @@ -37238,7 +37381,7 @@

    - def facet_hash + def session_range_lookup(value) @@ -37249,7 +37392,7 @@

    - # hash with keys as names of facets + # TODO: this will likely become a Session model, with persistance and admin features to set the names @@ -37260,18 +37403,18 @@

    - + # as well as 'from' and 'to' dates.
    -
  • +
  • - ret = {} +
  • @@ -37282,29 +37425,29 @@

    - SolrSearch.facet_fields.each do |field_name| + case value
    -
  • +
  • - ret[field_name] = { + when '2024-25'
  • -
  • +
  • - "type" => facet_type(field_name), + '[2024-05-25T00:00:00Z TO *]'
  • @@ -37315,18 +37458,18 @@

    - "field" => field_name, + when '2023-24'
    -
  • +
  • - "limit" => facet_limit(field_name), + '[2023-10-27T00:00:00Z TO 2024-05-24T23:59:00Z]'
  • @@ -37337,18 +37480,18 @@

    - "missing" => true, + when '2022-23'
    -
  • +
  • - "mincount" => facet_mincount(field_name), + '[2022-04-29T00:00:00Z TO 2023-10-26T23:59:59Z]'
  • @@ -37359,18 +37502,18 @@

    - "domain" => { excludeTags: field_name } + when '2021-22'
    -
  • +
  • - } + '[2021-05-11T00:00:00Z TO 2022-04-28T23:59:59Z]'
  • @@ -37381,29 +37524,29 @@

    - end + when '2019-21'
    -
  • +
  • - + '[2019-12-17T00:00:00Z TO 2021-05-10T23:59:59Z]'
  • -
  • +
  • - if filter&.dig(:year).present? + when '2019-19'
  • @@ -37414,29 +37557,29 @@

    - year = filter.dig(:year).first + '[2019-10-14T01:00:00Z TO 2019-11-06T00:01:00Z]'
    -
  • +
  • - ret['month'] = { + when '2017-19'
  • -
  • +
  • - "type": "range", + '[2017-05-03T00:00:00Z TO 2019-10-13T23:59:59Z]'
  • @@ -37447,18 +37590,18 @@

    - "field": "date_dt", + when '2016-17'
    -
  • +
  • - "start": "#{year}-01-01T00:00:00Z", + '[2016-05-13T00:00:00Z TO 2017-05-02T23:59:59Z]'
  • @@ -37469,18 +37612,18 @@

    - "end": "#{year}-12-31T23:59:59Z", + when '2015-16'
    -
  • +
  • - "gap": "+1MONTH", + '[2015-04-01T00:00:00Z TO 2016-05-12T23:59:59Z]'
  • @@ -37491,18 +37634,18 @@

    - "mincount": 0, + when '2014-15'
    -
  • +
  • - "domain": { excludeTags: 'month' } + '[2014-05-14T23:00:00Z TO 2015-03-30T23:59:59Z]'
  • @@ -37513,40 +37656,40 @@

    - } + when '2013-14'
    -
  • +
  • - else + '[2013-04-25T23:00:00Z TO 2014-06-03T22:59:59Z]'
  • -
  • +
  • - ret['year'] = { + when '2012-13'
  • -
  • +
  • - "type": "range", + '[2012-05-08T23:00:00Z TO 2013-04-25T22:59:59Z]'
  • @@ -37557,18 +37700,18 @@

    - "field": "date_dt", + when '2010-12'
    -
  • +
  • - "start": "1500-01-01T00:00:00Z", + '[2010-05-17T23:00:00Z TO 2012-05-08T22:59:59Z]'
  • @@ -37579,18 +37722,18 @@

    - "end": "#{Date.today.strftime("%Y-%m-%d")}T23:59:59Z", + when '2009-10'
    -
  • +
  • - "gap": "+1YEAR", + '[2009-11-18T00:00:00Z TO 2010-05-17T22:59:59Z]'
  • @@ -37601,18 +37744,18 @@

    - "mincount": 1, + when '2008-09'
    -
  • +
  • - "limit": 100 + '[2008-12-03T00:00:00Z TO 2009-11-17T23:59:59Z]'
  • @@ -37623,18 +37766,18 @@

    - } + when '2007-08'
    -
  • +
  • - end + '[2007-11-06T00:00:00Z TO 2008-12-02T23:59:59Z]'
  • @@ -37645,7 +37788,7 @@

    - + when '2006-07' @@ -37656,7 +37799,7 @@

    - ret.to_json + '[2006-11-15T00:00:00Z TO 2007-11-05T23:59:59Z]' @@ -37667,29 +37810,29 @@

    - end + when '2005-06'
    -
  • +
  • - + '[2005-05-10T23:00:00Z TO 2006-11-14T23:59:59Z]'
  • -
  • - 1 +
  • + - def facet_type(field_name) + when '2004-05'
  • @@ -37700,51 +37843,51 @@

    - arr = [] + '[2004-11-23T00:00:00Z TO 2005-05-10T22:59:59Z]'
    -
  • +
  • - return "terms" unless arr.include?(field_name) + when '2003-04'
  • -
  • +
  • - + '[2003-11-26T00:00:00Z TO 2004-11-22T23:59:59Z]'
  • -
  • +
  • - " " # replacement type + when '2002-03'
  • -
  • +
  • - end + '[2002-11-10T00:00:00Z TO 2003-11-25T23:59:59Z]'
  • @@ -37755,84 +37898,84 @@

    - + when '2001-02'
    -
  • - 1 +
  • + - def facet_limit(field_name) + '[2001-06-12T23:00:00Z TO 2002-11-09T23:59:59Z]'
  • -
  • +
  • - type_facet_names = ["type_sesrollup"] + when '2000-01'
  • -
  • +
  • - + '[2000-12-06T00:00:00Z TO 2001-06-12T22:59:59Z]'
  • -
  • +
  • - return 80 unless type_facet_names.include?(field_name) + when '1999-00'
  • -
  • +
  • - + '[1999-11-17T00:00:00Z TO 2000-12-05T23:59:59Z]'
  • -
  • +
  • - -1 + when '1998-99'
  • -
  • +
  • - end + '[1998-11-24T00:00:00Z TO 1999-11-16T23:59:59Z]'
  • @@ -37843,29 +37986,29 @@

    - + when '1997-98'
    -
  • - 1 +
  • + - def facet_mincount(field_name) + '[1997-05-06T23:00:00Z TO 1998-11-23T23:59:59Z]'
  • -
  • +
  • - arr = [] + when '1996-97'
  • @@ -37876,7 +38019,7 @@

    - return 1 unless arr.include?(field_name) + '[1996-10-22T23:00:00Z TO 1997-05-06T22:59:59Z]' @@ -37887,7 +38030,7 @@

    - + when '1995-96' @@ -37898,7 +38041,7 @@

    - 0 # replacement mincount + '[1995-11-15T00:00:00Z TO 1996-10-22T22:59:59Z]' @@ -37909,84 +38052,84 @@

    - end + when '1994-95'
    -
  • +
  • - + '[1994-11-16T00:00:00Z TO 1995-11-14T23:59:59Z]'
  • -
  • - 1 +
  • + - private + when '1993-94'
  • -
  • +
  • - + '[1993-11-18T00:00:00Z TO 1994-11-15T23:59:59Z]'
  • -
  • - 1 +
  • + - def search_params + when '1992-93'
  • -
  • +
  • - { + '[1992-04-26T23:00:00Z TO 1993-11-17T23:59:59Z]'
  • -
  • +
  • - q: search_query, + when '1991-92'
  • -
  • +
  • - 'q.op': 'AND', + '[1991-10-31T00:00:00Z TO 1992-04-26T22:59:59Z]'
  • @@ -37997,18 +38140,18 @@

    - fq: search_filter, + when '1990-91'
    -
  • +
  • - start: start, + '[1990-11-07T00:00:00Z TO 1991-10-30T23:59:59Z]'
  • @@ -38019,18 +38162,18 @@

    - rows: rows, + when '1989-90'
    -
  • +
  • - sort: sort, + '[1989-11-21T00:00:00Z TO 1990-11-06T23:59:59Z]'
  • @@ -38041,18 +38184,18 @@

    - 'json.facet': facet_hash + when '1988-89'
    -
  • +
  • - } + '[1988-11-22T00:00:00Z TO 1989-11-20T23:59:59Z]'
  • @@ -38063,12 +38206,1794 @@

    + 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 +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + 1 + + + + + def sort +
  • +
    + +
    +
  • + 3 + + + + + return 'date_dt desc' if sort_by == "date_desc" +
  • +
    + +
    +
  • + 2 + + + + + return 'date_dt asc' if sort_by == "date_asc" +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + 1 + + + + + 'date_dt desc' +
  • +
    + +
    +
  • + + + + + end
  • -
  • +
  • + + + + + + +
  • +
    + +
    +
  • + 1 + + + + + def facet_hash +
  • +
    + +
    +
  • + + + + + + # hash with keys as names of facets +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + + + + + + ret = {} +
  • +
    + +
    +
  • + + + + + + SolrSearch.facet_fields.each do |field_name| +
  • +
    + +
    +
  • + + + + + + ret[field_name] = { +
  • +
    + +
    +
  • + + + + + + "type" => facet_type(field_name), +
  • +
    + +
    +
  • + + + + + + "field" => field_name, +
  • +
    + +
    +
  • + + + + + + "limit" => facet_limit(field_name), +
  • +
    + +
    +
  • + + + + + + "mincount" => facet_mincount(field_name), +
  • +
    + +
    +
  • + + + + + + "domain" => { excludeTags: field_name } +
  • +
    + +
    +
  • + + + + + + } +
  • +
    + +
    +
  • + + + + + + end +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + + + + + + if filter&.dig(:year).present? +
  • +
    + +
    +
  • + + + + + + year = filter.dig(:year).first +
  • +
    + +
    +
  • + + + + + + ret['month'] = { +
  • +
    + +
    +
  • + + + + + + "type": "range", +
  • +
    + +
    +
  • + + + + + + "field": "date_dt", +
  • +
    + +
    +
  • + + + + + + "start": "#{year}-01-01T00:00:00Z", +
  • +
    + +
    +
  • + + + + + + "end": "#{year}-12-31T23:59:59Z", +
  • +
    + +
    +
  • + + + + + + "gap": "+1MONTH", +
  • +
    + +
    +
  • + + + + + + "mincount": 0, +
  • +
    + +
    +
  • + + + + + + "domain": { excludeTags: 'month' } +
  • +
    + +
    +
  • + + + + + + } +
  • +
    + +
    +
  • + + + + + + else +
  • +
    + +
    +
  • + + + + + + ret['year'] = { +
  • +
    + +
    +
  • + + + + + + "type": "range", +
  • +
    + +
    +
  • + + + + + + "field": "date_dt", +
  • +
    + +
    +
  • + + + + + + "start": "1500-01-01T00:00:00Z", +
  • +
    + +
    +
  • + + + + + + "end": "#{Date.today.strftime("%Y-%m-%d")}T23:59:59Z", +
  • +
    + +
    +
  • + + + + + + "gap": "+1YEAR", +
  • +
    + +
    +
  • + + + + + + "mincount": 1, +
  • +
    + +
    +
  • + + + + + + "limit": 100 +
  • +
    + +
    +
  • + + + + + + } +
  • +
    + +
    +
  • + + + + + + 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 +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + 1 + + + + + def facet_type(field_name) +
  • +
    + +
    +
  • + + + + + + arr = [] +
  • +
    + +
    +
  • + + + + + + return "terms" unless arr.include?(field_name) +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + + + + + + " " # replacement type +
  • +
    + +
    +
  • + + + + + + end +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + 1 + + + + + def facet_limit(field_name) +
  • +
    + +
    +
  • + + + + + + # limit to 80 except for +
  • +
    + +
    +
  • + + + + + + facet_names = ["type_sesrollup"] +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + + + + + + return 80 unless facet_names.include?(field_name) +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + + + + + + -1 +
  • +
    + +
    +
  • + + + + + + end +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + 1 + + + + + def facet_mincount(field_name) +
  • +
    + +
    +
  • + + + + + + arr = [] +
  • +
    + +
    +
  • + + + + + + return 1 unless arr.include?(field_name) +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + + + + + + 0 # replacement mincount +
  • +
    + +
    +
  • + + + + + + end +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + 1 + + + + + def self.sessions +
  • +
    + +
    +
  • + + + + + + [ +
  • +
    + +
    +
  • + 9 + + + + + '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 +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + 1 + + + + + private +
  • +
    + +
    +
  • + + + + + + +
  • +
    + +
    +
  • + 1 + + + + + def search_params +
  • +
    + +
    +
  • + + + + + + { +
  • +
    + +
    +
  • + + + + + + q: search_query, +
  • +
    + +
    +
  • + + + + + + 'q.op': 'AND', +
  • +
    + +
    +
  • + + + + + + fq: search_filter, +
  • +
    + +
    +
  • + + + + + + start: start, +
  • +
    + +
    +
  • + + + + + + rows: rows, +
  • +
    + +
    +
  • + + + + + + sort: sort, +
  • +
    + +
    +
  • + + + + + + 'json.facet': facet_hash +
  • +
    + +
    +
  • + + + + + + } +
  • +
    + +
    +
  • + + + + + + end +
  • +
    + +
    +
  • diff --git a/spec/models/search_data_spec.rb b/spec/models/search_data_spec.rb index 98f5629..592cfdf 100644 --- a/spec/models/search_data_spec.rb +++ b/spec/models/search_data_spec.rb @@ -2,7 +2,7 @@ RSpec.describe SearchData, type: :model do let(:search_data) { SearchData.new(search_output) } - let!(:search_output) { { search_parameters: { filter: ['type_ses:12345'], query: 'horse' }, + let!(:search_output) { { search_parameters: { filter: ['topic_ses:12345'], query: 'horse' }, data: { "responseHeader" => { "status" => 0, @@ -21,8 +21,8 @@ "highlighting" => { "test_url" => {} }, "facets" => { "count" => 1234, - "type_ses" => { "buckets" => [{ "val" => 90996, "count" => 123 }, { "val" => 90995, "count" => 234 }] }, - "subtype_ses" => { "buckets" => [{ "val" => 123456, "count" => 455 }, { "val" => 234556, "count" => 66 }] } + "topic_ses" => { "buckets" => [{ "val" => 90996, "count" => 123 }, { "val" => 90995, "count" => 234 }] }, + "subject_ses" => { "buckets" => [{ "val" => 123456, "count" => 455 }, { "val" => 234556, "count" => 66 }] } } }, } @@ -40,7 +40,7 @@ end end context 'when an error code is present' do - let!(:search_output) { { search_parameters: { filter: ['type_ses:12345'] }, data: { "code" => 500, "msg" => "error_message" } } } + let!(:search_output) { { search_parameters: { filter: ['topic_ses:12345'] }, data: { "code" => 500, "msg" => "error_message" } } } it 'returns true' do expect(search_data.solr_error?).to be true end @@ -54,7 +54,7 @@ end end context 'when an error code is present' do - let!(:search_output) { { search_parameters: { filter: ['type_ses:12345'] }, data: { "code" => 500, "msg" => "error_message" } } } + let!(:search_output) { { search_parameters: { filter: ['topic_ses:12345'] }, data: { "code" => 500, "msg" => "error_message" } } } it 'returns the message' do expect(search_data.error_message).to eq('error_message') end @@ -68,7 +68,7 @@ end end context 'when an error code is present' do - let!(:search_output) { { search_parameters: { filter: ['type_ses:12345'] }, data: { "code" => 500, "msg" => "error_message" } } } + let!(:search_output) { { search_parameters: { filter: ['topic_ses:12345'] }, data: { "code" => 500, "msg" => "error_message" } } } it 'returns the code' do expect(search_data.error_code).to eq(500) end @@ -82,7 +82,7 @@ end end context 'when an error code is present' do - let!(:search_output) { { search_parameters: { filter: ['type_ses:12345'] }, data: { "code" => 500, "msg" => "error_message" } } } + let!(:search_output) { { search_parameters: { filter: ['topic_ses:12345'] }, data: { "code" => 500, "msg" => "error_message" } } } it 'returns the partial path' do expect(search_data.error_partial_path).to eq('layouts/shared/error/500') end @@ -100,7 +100,7 @@ end end context 'where data is missing' do - let!(:search_output) { { search_parameters: { filter: ['type_ses:12345'] }, + let!(:search_output) { { search_parameters: { filter: ['topic_ses:12345'] }, data: { "responseHeader" => { "status" => 0, "QTime" => 4, @@ -126,7 +126,7 @@ end end context 'where data is missing' do - let!(:search_output) { { search_parameters: { filter: ['type_ses:12345'] }, + let!(:search_output) { { search_parameters: { filter: ['topic_ses:12345'] }, data: { "responseHeader" => { "status" => 0, "QTime" => 4, @@ -153,7 +153,7 @@ end context 'where no data is present' do - let!(:search_output) { { search_parameters: { filter: ['type_ses:12345'] } } } + let!(:search_output) { { search_parameters: { filter: ['topic_ses:12345'] } } } it 'returns nil' do expect(search_data.number_of_results).to be nil @@ -169,7 +169,7 @@ end context 'where no query is present' do - let!(:search_output) { { search_parameters: { filter: ['type_ses:12345'] } } } + let!(:search_output) { { search_parameters: { filter: ['topic_ses:12345'] } } } it 'returns nil' do expect(search_data.query).to be nil @@ -194,9 +194,9 @@ describe 'filter' do context 'where data is present' do - let!(:search_output) { { search_parameters: { filter: ['type_ses:12345'] } } } + let!(:search_output) { { search_parameters: { filter: ['topic_ses:12345'] } } } it 'returns an array of filter strings' do - expect(search_data.filter).to eq(["type_ses:12345"]) + expect(search_data.filter).to eq(["topic_ses:12345"]) end end @@ -272,11 +272,11 @@ end it 'includes the field name string' do - expect(search_data.facets.pluck(:field_name)).to eq(["type_ses", "subtype_ses"]) + expect(search_data.facets.pluck(:field_name)).to match_array(["topic_ses", "subject_ses"]) end it 'includes facets sorted by count (descending)' do - expect(search_data.facets.pluck(:facets)).to eq([[{ "count" => 234, "val" => 90995 }, { "count" => 123, "val" => 90996 }], [{ "count" => 455, "val" => 123456 }, { "count" => 66, "val" => 234556 }]]) + expect(search_data.facets.pluck(:facets)).to eq([[{ "count" => 455, "val" => 123456 }, { "count" => 66, "val" => 234556 }], [{ "count" => 234, "val" => 90995 }, { "count" => 123, "val" => 90996 }]]) end end end