Skip to content

Commit

Permalink
Merge pull request #823 from datacite/repo-facets
Browse files Browse the repository at this point in the history
Fix Repository facets
  • Loading branch information
jrhoads authored Jun 8, 2022
2 parents a7a221e + 61c75d7 commit dd116fb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
5 changes: 3 additions & 2 deletions app/graphql/types/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ def facet_by_year(arr)
end
end

def facet_by_key(arr)
def facet_by_key(arr, title_case: true)
arr.map do |hsh|
title = title_case ? hsh["key"].titleize : hsh["key"]
{
"id" => hsh["key"],
"title" => hsh["key"].titleize,
"title" => title,
"count" => hsh["doc_count"],
}
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/repository_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def repository_types
end

def certificates
facet_by_key(object.aggregations.certificates.buckets)
facet_by_key(object.aggregations.certificates.buckets, title_case: false)
end

def members
Expand Down
32 changes: 28 additions & 4 deletions app/models/reference_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,24 @@ def as_indexed_json(_options = {})
ReferenceRepositoryDenormalizer.new(self).to_hash
end

settings index: { number_of_shards: 1 } do
settings index: {
number_of_shards: 1,
analysis: {
analyzer: {
string_lowercase: {
tokenizer: "keyword", filter: %w[lowercase ascii_folding]
},
},
normalizer: {
keyword_lowercase: { type: "custom", filter: %w[lowercase] },
},
filter: {
ascii_folding: {
type: "asciifolding", preserve_original: true
},
},
},
} do
mapping dynamic: "false" do
indexes :id
indexes :uid, type: :text,
Expand Down Expand Up @@ -132,7 +149,14 @@ def as_indexed_json(_options = {})
indexes :provider_type, type: :keyword
indexes :repository_type, type: :keyword
indexes :data_upload_licenses, type: :keyword
indexes :software, type: :keyword
indexes :software,
type: :text,
fields: {
keyword: { type: "keyword" },
raw: {
type: "text", analyzer: "string_lowercase", "fielddata": true
},
}
indexes :subject, type: :object,
properties: {
text: { type: :keyword },
Expand Down Expand Up @@ -169,7 +193,7 @@ def query_aggregations(facet_count: 10)
},
software: {
terms: {
field: "software",
field: "software.keyword",
size: facet_count,
min_doc_count: 1
},
Expand Down Expand Up @@ -315,7 +339,7 @@ def filter(options)
end
if options[:software].present?
retval << { terms: {
"software": options[:software].split(",")
"software.raw": options[:software].split(",")
} }
end
if options[:certificate].present?
Expand Down
8 changes: 4 additions & 4 deletions spec/graphql/types/repository_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@
expect(
response.dig("data", "repositories", "certificates"),
).to eq([
{ "count" => 4, "id" => "CoreTrustSeal", "title" => "Core Trust Seal" },
{ "count" => 1, "id" => "DINI Certificate", "title" => "Dini Certificate" },
{ "count" => 1, "id" => "DSA", "title" => "Dsa" }
{ "count" => 4, "id" => "CoreTrustSeal", "title" => "CoreTrustSeal" },
{ "count" => 1, "id" => "DINI Certificate", "title" => "DINI Certificate" },
{ "count" => 1, "id" => "DSA", "title" => "DSA" }
])
end

Expand Down Expand Up @@ -203,7 +203,7 @@
it "filters based on software" do
response = LupoSchema.execute(
search_query,
variables: { software: "DataVerse" }
variables: { software: "dataverse" }
).as_json
expect(response.dig("data", "repositories", "totalCount")).to eq(2)
end
Expand Down

0 comments on commit dd116fb

Please sign in to comment.