Skip to content

Conversation

@jazairi
Copy link
Contributor

@jazairi jazairi commented Jan 23, 2026

Why these changes are being introduced:

As we begin to experiment with reranking results
from multiple APIs, it will be useful to configure TIMDEX to return a flexible number of results.

Relevant ticket(s):

How this addresses that need:

This updates the OpenSearch model to calculate
query size based on the presence of a per_page
param. The model continues to fall back on the
SIZE and MAX_PAGE constants if no param is
provided.

Similarly, the QueryType class is updated to
provide a per_page query param. We here we set
the default value to 20 as a secondary layer of
defense against bad inputs.

Side effects of this change:

New VCR cassette to cover the GraphQL query
behavior. Normally I prefer stubs/mocks, but since this is a single additional test in a suite that
solely uses VCR, it felt appropriate to continue
that practice.

Developer

  • All new ENV is documented in README
  • All new ENV has been added to Heroku Pipeline, Staging and Prod
  • ANDI or Wave has been run in accordance to
    our guide and
    all issues introduced by these changes have been resolved or opened as new
    issues (link to those issues in the Pull Request details above)
  • Stakeholder approval has been confirmed (or is not needed)

Code Reviewer

  • The commit message is clear and follows our guidelines
    (not just this pull request message)
  • There are appropriate tests covering any new functionality
  • The documentation has been updated or is unnecessary
  • The changes have been verified
  • New dependencies are appropriate or there were no changes

Requires database migrations?

NO

Includes new or updated dependencies?

NO

Why these changes are being introduced:

As we begin to experiment with reranking results
from multiple APIs, it will be useful to configure
TIMDEX to return a flexible number of results.

Relevant ticket(s):

- [TIMX-593](https://mitlibraries.atlassian.net/browse/TIMX-593)

How this addresses that need:

This updates the OpenSearch model to calculate
query size based on the presence of a per_page
param. The model continues to fall back on the
SIZE and MAX_PAGE constants if no param is
provided.

Similarly, the QueryType class is updated to
provide a per_page query param. We here we set
the default value to 20 as a secondary layer of
defense against bad inputs.

Side effects of this change:

New VCR cassette to cover the GraphQL query
behavior. Normally I prefer stubs/mocks, but since
this is a single additional test in a suite that
solely uses VCR, it felt appropriate to continue
that practice.
@mitlib mitlib temporarily deployed to timdex-api-p-timx-593-yj4nexxi January 23, 2026 17:11 Inactive
Copy link
Member

@JPrevost JPrevost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be best to remove the OpenSearch reference in the public graphql description and consider renaming MAX_PAGE to MAX_SIZE to clarify the intent.

calculate_size = if @params && @params[:per_page]
per_page = @params[:per_page].to_i
per_page = SIZE if per_page <= 0
[per_page, MAX_PAGE].min
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what our initial intent of MAX_PAGE was. It doesn't seem to be in use at this time.

I think removing it and setting a clearer variable such as MAX_SIZE might be clearer later.

argument :from, String, required: false, default_value: '0',
description: 'Search result number to begin with (the first result is 0)'
argument :per_page, Integer, required: false, default_value: 20,
description: 'Number of results per page (OpenSearch size). Defaults to 20.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if noting in the public API that this is an OpenSearch size equivalent is helpful or confusing...

# allow overriding the OpenSearch `size` via params (per_page), capped by MAX_PAGE
calculate_size = if @params && @params[:per_page]
per_page = @params[:per_page].to_i
per_page = SIZE if per_page <= 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruby treating strings it doesn't know how to convert to an integer as zero is either brilliant or super weird. In this case it works well so I guess I should appreciate it.

@JPrevost JPrevost self-assigned this Jan 23, 2026
@jazairi jazairi temporarily deployed to timdex-api-p-timx-593-yj4nexxi January 23, 2026 21:49 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants