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

Extract Aggregations Class #793

Merged
merged 1 commit into from
Feb 16, 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
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
Loading