Skip to content

Commit

Permalink
Merge pull request #793 from MITLibraries/gdt-168-aggregations-part1
Browse files Browse the repository at this point in the history
Extract Aggregations Class
  • Loading branch information
JPrevost authored Feb 16, 2024
2 parents 66dd37a + 9483727 commit 5304eae
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 56 deletions.
84 changes: 84 additions & 0 deletions app/models/aggregations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
class Aggregations
# https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
def self.all
{
contributors:,
content_type:,
content_format:,
languages:,
literary_form:,
source:,
subjects:
}
end

def self.contributors
{
nested: {
path: 'contributors'
},
aggs: {
contributor_names: {
terms: {
field: 'contributors.value.keyword'
}
}
}
}
end

def self.content_type
{
terms: {
field: 'content_type'
}
}
end

def self.content_format
{
terms: {
field: 'format'
}
}
end

def self.languages
{
terms: {
field: 'languages.keyword'
}
}
end

def self.literary_form
{
terms: {
field: 'literary_form'
}
}
end

def self.source
{
terms: {
field: 'source'
}
}
end

def self.subjects
{
nested: {
path: 'subjects'
},
aggs: {
subject_names: {
terms: {
field: 'subjects.value.keyword'
}
}
}
}
end
end
57 changes: 1 addition & 56 deletions app/models/opensearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def build_query(from)
from:,
size: SIZE,
query:,
aggregations:,
aggregations: Aggregations.all,
sort:
}

Expand Down Expand Up @@ -245,61 +245,6 @@ def source_array(param)
sources
end

# https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
def aggregations
{
contributors: {
nested: {
path: 'contributors'
},
aggs: {
contributor_names: {
terms: {
field: 'contributors.value.keyword'
}
}
}
},
content_type: {
terms: {
field: 'content_type'
}
},
content_format: {
terms: {
field: 'format'
}
},
languages: {
terms: {
field: 'languages.keyword'
}
},
literary_form: {
terms: {
field: 'literary_form'
}
},
source: {
terms: {
field: 'source'
}
},
subjects: {
nested: {
path: 'subjects'
},
aggs: {
subject_names: {
terms: {
field: 'subjects.value.keyword'
}
}
}
}
}
end

private

def match_single_field(field, match_array)
Expand Down

0 comments on commit 5304eae

Please sign in to comment.