-
Notifications
You must be signed in to change notification settings - Fork 6
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
Adds support for querying specific indexes #540
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
class Retrieve | ||
def fetch(id, client) | ||
def fetch(id, client, index = nil) | ||
f = to_filter(id) | ||
record = client.search(index: ENV['ELASTICSEARCH_INDEX'], body: f) | ||
|
||
index = default_index unless index.present? | ||
|
||
record = client.search(index: index, body: f) | ||
|
||
if client.instance_of?(OpenSearch::Client) | ||
raise OpenSearch::Transport::Transport::Errors::NotFound if record['hits']['total']['value'].zero? | ||
else | ||
raise Elasticsearch::Transport::Transport::Errors::NotFound if record['hits']['total'].zero? | ||
elsif record['hits']['total'].zero? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't the point of the PR, but I want to note that I like this a lot better than the former syntax. Good catch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was a rubocop fix that I included because I touched the file with this changes, but I agree! |
||
raise Elasticsearch::Transport::Transport::Errors::NotFound | ||
end | ||
|
||
record | ||
end | ||
|
||
def default_index | ||
ENV.fetch('ELASTICSEARCH_INDEX', nil) | ||
end | ||
|
||
def to_filter(id) | ||
{ | ||
query: { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,7 +153,7 @@ def setup | |
}' } | ||
assert_equal(200, response.status) | ||
json = JSON.parse(response.body) | ||
assert json['data']['search']['records'].first['contributors'].any? { |c| c.has_value? 'Moon, Intae' } | ||
assert json['data']['search']['records'].first['contributors'].any? { |c| c.value? 'Moon, Intae' } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming that changes like this are about rubocop flagging There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this was just rubocop fixes. I ran it on any file I touched and it fixed a few things out of scope of my changes but it seemed fine to include them. I should have made a note about that though in side effects to clarify the things that were not really part of this work that slid in. |
||
end | ||
end | ||
|
||
|
@@ -177,9 +177,9 @@ def setup | |
assert_equal 'A common table : 80 recipes and stories from my shared cultures /', | ||
json['data']['search']['records'].first['title'] | ||
assert json['data']['search']['records'].first['contributors'].any? { |c| | ||
c.has_value? 'McTernan, Cynthia Chen, author.' | ||
c.value? 'McTernan, Cynthia Chen, author.' | ||
} | ||
assert json['data']['search']['records'].first['identifiers'].any? { |i| i.has_value? '163565002X (hardback)' } | ||
assert json['data']['search']['records'].first['identifiers'].any? { |i| i.value? '163565002X (hardback)' } | ||
end | ||
end | ||
|
||
|
@@ -317,7 +317,6 @@ def setup | |
|
||
test 'graphqlv2 filter multiple sources' do | ||
VCR.use_cassette('graphql v2 filter multiple sources') do | ||
|
||
# no filters to return all sources. used later to test filters return less than the total. | ||
post '/graphql', params: { query: | ||
'{ | ||
|
@@ -330,8 +329,7 @@ def setup | |
} | ||
} | ||
} | ||
}' | ||
} | ||
}' } | ||
|
||
json = JSON.parse(response.body) | ||
initial_source_array = json['data']['search']['aggregations']['source'] | ||
|
@@ -348,8 +346,7 @@ def setup | |
} | ||
} | ||
} | ||
}' | ||
} | ||
}' } | ||
assert_equal(200, response.status) | ||
|
||
json = JSON.parse(response.body) | ||
|
@@ -359,14 +356,13 @@ def setup | |
assert_equal(2, filtered_source_array.count) | ||
|
||
expected_sources = ['zenodo', 'dspace@mit'] | ||
actual_sources = filtered_source_array.map{|source| source["key"]} | ||
actual_sources = filtered_source_array.map { |source| source['key'] } | ||
assert_equal(expected_sources, actual_sources) | ||
end | ||
end | ||
|
||
test 'graphqlv2 filter single source' do | ||
VCR.use_cassette('graphql v2 filter single source') do | ||
|
||
# no filters to return all sources. used later to test filters return less than the total. | ||
post '/graphql', params: { query: | ||
'{ | ||
|
@@ -379,8 +375,7 @@ def setup | |
} | ||
} | ||
} | ||
}' | ||
} | ||
}' } | ||
|
||
json = JSON.parse(response.body) | ||
initial_source_array = json['data']['search']['aggregations']['source'] | ||
|
@@ -397,8 +392,7 @@ def setup | |
} | ||
} | ||
} | ||
}' | ||
} | ||
}' } | ||
assert_equal(200, response.status) | ||
|
||
json = JSON.parse(response.body) | ||
|
@@ -408,8 +402,40 @@ def setup | |
assert_equal(1, filtered_source_array.count) | ||
|
||
expected_sources = ['dspace@mit'] | ||
actual_sources = filtered_source_array.map{|source| source["key"]} | ||
actual_sources = filtered_source_array.map { |source| source['key'] } | ||
assert_equal(expected_sources, actual_sources) | ||
end | ||
end | ||
|
||
test 'graphqlv2 can retrieve a record from a default index' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't object to this test, but wonder how it differs from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't disagree, but I think the difference is intent. In this case, the distinction is the name of the test declares what we intend to test... the actual test logic is the same. I'm waffly on how I feel about it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok - I don't think we should remove this test to be clear. Reading through the file, I see this test as paired with the adjacent one that changes the index value, while the earlier test is removed enough that it isn't clear that we're testing both conditions without a higher cognitive load. While this may be a small amount of over-testing, I don't think that's particularly an issue. The suite runs pretty quickly, so there's no downside IMO. |
||
# fragile test: specific item expected in default index | ||
VCR.use_cassette('graphql v2 retrieve from default index') do | ||
post '/graphql', params: { query: | ||
'{ | ||
recordId(id: "dspace:1721.1-44968") { | ||
timdexRecordId | ||
title | ||
} | ||
}' } | ||
|
||
json = JSON.parse(response.body) | ||
assert_equal('dspace:1721.1-44968', json['data']['recordId']['timdexRecordId']) | ||
end | ||
end | ||
|
||
test 'graphqlv2 can retrive a record from a specified index' do | ||
# fragile test: specific item expected in specified index | ||
VCR.use_cassette('graphql v2 retrieve from rdi* index') do | ||
post '/graphql', params: { query: | ||
'{ | ||
recordId(id: "zenodo:5728409", index: "rdi*") { | ||
timdexRecordId | ||
title | ||
} | ||
}' } | ||
|
||
json = JSON.parse(response.body) | ||
assert_equal('zenodo:5728409', json['data']['recordId']['timdexRecordId']) | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be something we want to update when we fully convert to opensearch and remove the older elasticsearch implementation - but I got really confused for a moment wondering why this doesn't also make changes to
search.rb
when it also deals with the same env. I get it now, we're using the same name in both underlying systems so it makes sense to have one env - but it tripped me up for a few minutes.I'm guessing that this will eventually become
OPENSEARCH_INDEX
or even justSEARCH_INDEX
or something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point, the
ELASTICSEARCH_INDEX
is a legacy name that should go away.