Skip to content

Commit

Permalink
Merge pull request #1319 from datacite/issue-838
Browse files Browse the repository at this point in the history
Ensure cursor-based pagination and random sorting are mutually exclusive (+bonus VCRs)
  • Loading branch information
digitaldogsbody authored Jan 28, 2025
2 parents f156484 + 632d614 commit a72701c
Show file tree
Hide file tree
Showing 12 changed files with 422 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1179,11 +1179,15 @@ def self.query(query, options = {})
bool: bool_query,
},
random_score: {
"seed": Rails.env.test? ? "random_1234" : "random_#{rand(1...100000)}",
"seed": "random_#{rand(1...100000)}",
},
}

if options[:random].present?
if options[:random].present? && options[:random].to_s.downcase == "true" # .present? will always be true even if "false" is the value, because strings are truthy
# Random results and cursor pagination are incompatible (https://github.com/datacite/lupo/issues/838), throw an error if attempted
if options.fetch(:page, {}).key?(:cursor)
fail ActionController::BadRequest, "Cursor-based pagination and random sampling are mutually exclusive, please choose one or the other."
end
es_query["function_score"] = function_score
# Don't do any sorting for random results
sort = nil
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a72701c

Please sign in to comment.