-
Notifications
You must be signed in to change notification settings - Fork 0
Zipper via Reranker. Load more. Result numbers. #448
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
Open
JPrevost
wants to merge
5
commits into
main
Choose a base branch
from
reranker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8e14fc4
Add reranker gem and refactor to use it
JPrevost da11715
Load More reranked results
JPrevost 90f97a7
Display result number
JPrevost 45a7229
Keep default zipper for initial work
JPrevost 7875e39
Address automated review feedback
JPrevost File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,10 @@ def results | |
| # Load GeoData results if applicable | ||
| if Feature.enabled?(:geodata) | ||
| load_geodata_results | ||
| render 'results_geo' | ||
| respond_to do |format| | ||
| format.turbo_stream { render :results_geo } | ||
| format.html { render 'results_geo' } | ||
| end | ||
| return | ||
| end | ||
|
|
||
|
|
@@ -42,6 +45,7 @@ def results | |
| # Render the response in HTML or JSON format | ||
| respond_to do |format| | ||
| format.json { render json: { results: @results, pagination: @pagination, errors: @errors } } | ||
| format.turbo_stream { render :results } | ||
| format.html { render :results } | ||
| end | ||
| end | ||
|
|
@@ -81,6 +85,8 @@ def load_geodata_results | |
| raw_results = extract_results(response) | ||
| @results = NormalizeTimdexResults.new(raw_results, @enhanced_query[:q]).normalize | ||
| @filters = extract_filters(response) | ||
| @append_results = @results | ||
| @load_more = load_more_from_pagination(@pagination) | ||
|
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. |
||
| end | ||
|
|
||
| def load_primo_results | ||
|
|
@@ -89,35 +95,68 @@ def load_primo_results | |
| @pagination = data[:pagination] | ||
| @errors = data[:errors] | ||
| @show_primo_continuation = data[:show_continuation] | ||
| @append_results = @results | ||
| @load_more = load_more_from_pagination(@pagination) | ||
| end | ||
|
|
||
| def load_timdex_results | ||
| data = fetch_timdex_data | ||
| @results = data[:results] | ||
| @pagination = data[:pagination] | ||
| @errors = data[:errors] | ||
| @append_results = @results | ||
| @load_more = load_more_from_pagination(@pagination) | ||
| end | ||
|
|
||
| def load_all_results | ||
| current_page = @enhanced_query[:page] || 1 | ||
| per_page = ENV.fetch('RESULTS_PER_PAGE', '20').to_i | ||
|
|
||
| # Inject wrapper fetchers instead of using the service defaults. We use lambdas here so the | ||
| # service can call back into this controller's instance methods while preserving request-scoped | ||
| # context (for example `@enhanced_query`) and the controller's caching/normalization behavior. | ||
| # Using lambdas keeps the service decoupled from controller internals. | ||
| # Inject wrapper fetchers so the service can call back into this controller's | ||
| # instance methods while preserving request-scoped context and caching behavior. | ||
| merge_service = MergedSearchService.new( | ||
| enhanced_query: @enhanced_query, | ||
| active_tab: @active_tab, | ||
| primo_fetcher: ->(offset:, per_page:, query: nil) { fetch_primo_data(offset: offset, per_page: per_page) }, | ||
| timdex_fetcher: ->(offset:, per_page:, query: nil) { fetch_timdex_data(offset: offset, per_page: per_page) } | ||
| ) | ||
| data = merge_service.fetch(page: current_page, per_page: per_page) | ||
| display_count = sanitized_load_count | ||
| stable_count = [display_count - load_more_batch_size, 0].max | ||
| data = merge_service.fetch(display_count: display_count, stable_count: stable_count) | ||
|
|
||
| @results = data[:results] | ||
| @append_results = data[:append_results] | ||
| @errors = data[:errors] | ||
| @pagination = data[:pagination] | ||
| @show_primo_continuation = data[:show_primo_continuation] | ||
| @load_more = data[:load_more] | ||
|
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. |
||
| end | ||
|
|
||
| # Builds the shared load-more view model for source-specific tabs that still | ||
| # use traditional page/offset mechanics internally. The UI presents one | ||
| # growing list, while the next request simply fetches the next existing page. | ||
| def load_more_from_pagination(pagination) | ||
| return nil if pagination.blank? | ||
|
|
||
| { | ||
| display_count: pagination[:end], | ||
| next_page: pagination[:next], | ||
| has_more: pagination[:next].present?, | ||
| total_hits: pagination[:hits] | ||
| } | ||
| end | ||
|
|
||
| # Returns the visible all-tab result count requested by the browser. This is | ||
| # intentionally separate from `page`: source-specific tabs keep using page for | ||
| # API offsets, while the all tab uses a display count to grow a stable reranked | ||
| # result list. | ||
| def sanitized_load_count | ||
| requested = params[:load_count].to_i | ||
| requested = load_more_batch_size if requested < 1 | ||
| [requested, max_load_count].min | ||
| end | ||
|
|
||
| def load_more_batch_size | ||
| ENV.fetch('RESULTS_PER_PAGE', '20').to_i | ||
| end | ||
|
|
||
| def max_load_count | ||
| ENV.fetch('LOAD_MORE_MAX_RESULTS', '200').to_i | ||
| end | ||
|
|
||
| def fetch_primo_data(offset: nil, per_page: nil) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Found 3 issues:
1. Assignment Branch Condition size for
resultsis too high. [<6, 33, 8> 34.48/17] [rubocop:Metrics/AbcSize]2. Cyclomatic complexity for
resultsis too high. [8/7] [rubocop:Metrics/CyclomaticComplexity]3. Method has too many lines. [25/10] [rubocop:Metrics/MethodLength]