-
Notifications
You must be signed in to change notification settings - Fork 0
Implement unified 'all' search tab #274
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,15 +17,21 @@ def results | |
|
|
||
| @enhanced_query = Enhancer.new(params).enhanced_query | ||
|
|
||
| # Load GeoData results if applicable | ||
| if Feature.enabled?(:geodata) | ||
| load_geodata_results | ||
| render 'results_geo' | ||
| return | ||
| end | ||
|
|
||
| # Route to appropriate search based on active tab | ||
| case @active_tab | ||
| when 'primo' | ||
| load_primo_results | ||
| when 'timdex' | ||
| load_timdex_results | ||
| when 'geodata' | ||
| load_gdt_results | ||
| render 'results_geo' | ||
| when 'all' | ||
| load_all_results | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -50,7 +56,7 @@ def sleep_if_too_fast | |
| sleep(1 - duration) | ||
| end | ||
|
|
||
| def load_gdt_results | ||
| def load_geodata_results | ||
| query = QueryBuilder.new(@enhanced_query).query | ||
|
|
||
| response = query_timdex(query) | ||
|
|
@@ -66,49 +72,96 @@ def load_gdt_results | |
| end | ||
|
|
||
| def load_primo_results | ||
| data = fetch_primo_data | ||
| @results = data[:results] | ||
| @pagination = data[:pagination] | ||
| @errors = data[:errors] | ||
| @show_primo_continuation = data[:show_continuation] | ||
| end | ||
|
|
||
| def load_timdex_results | ||
| data = fetch_timdex_data | ||
| @results = data[:results] | ||
| @pagination = data[:pagination] | ||
| @errors = data[:errors] | ||
| end | ||
|
|
||
| def load_all_results | ||
| # Parallel fetching from both APIs | ||
| primo_thread = Thread.new { fetch_primo_data } | ||
| timdex_thread = Thread.new { fetch_timdex_data } | ||
|
|
||
| # Wait for both threads to complete | ||
| primo_data = primo_thread.value | ||
| timdex_data = timdex_thread.value | ||
|
|
||
| # Collect any errors from either API | ||
| all_errors = [] | ||
| all_errors.concat(primo_data[:errors]) if primo_data[:errors] | ||
| all_errors.concat(timdex_data[:errors]) if timdex_data[:errors] | ||
| @errors = all_errors.any? ? all_errors : nil | ||
|
|
||
| # Zipper merge results from both APIs | ||
| primo_results = primo_data[:results] || [] | ||
| timdex_results = timdex_data[:results] || [] | ||
| @results = primo_results.zip(timdex_results).flatten.compact | ||
|
Member
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. ✨ |
||
|
|
||
| # For now, just use primo pagination as a placeholder | ||
| @pagination = primo_data[:pagination] || {} | ||
|
|
||
| # Handle primo continuation for high page numbers | ||
| @show_primo_continuation = primo_data[:show_continuation] || false | ||
| end | ||
|
|
||
| def fetch_primo_data | ||
| current_page = @enhanced_query[:page] || 1 | ||
| per_page = @enhanced_query[:per_page] || 20 | ||
| offset = (current_page - 1) * per_page | ||
|
|
||
| # Check if we're beyond Primo API limits before making the request. | ||
| if offset >= Analyzer::PRIMO_MAX_OFFSET | ||
| @show_primo_continuation = true | ||
| return | ||
| return { results: [], pagination: {}, errors: nil, show_continuation: true } | ||
| end | ||
|
|
||
| primo_response = query_primo | ||
| @results = NormalizePrimoResults.new(primo_response, @enhanced_query[:q]).normalize | ||
| results = NormalizePrimoResults.new(primo_response, @enhanced_query[:q]).normalize | ||
| pagination = Analyzer.new(@enhanced_query, primo_response, :primo).pagination | ||
|
|
||
| # Handle empty results from Primo API. Sometimes Primo will return no results at a given offset, | ||
| # despite claiming in the initial query that more are available. This happens randomly and | ||
| # seemingly for no reason (well below the recommended offset of 2,000). While the bug also | ||
| # exists in Primo UI, sending users there seems like the best we can do. | ||
| if @results.empty? | ||
| show_continuation = false | ||
| errors = nil | ||
|
|
||
| if results.empty? | ||
| docs = primo_response['docs'] if primo_response.is_a?(Hash) | ||
| if docs.nil? || docs.empty? | ||
| # Only show continuation for pagination scenarios (page > 1), not for searches with no results | ||
| @show_primo_continuation = true if current_page > 1 | ||
| show_continuation = true if current_page > 1 | ||
| else | ||
| @errors = [{ 'message' => 'No more results available at this page number.' }] | ||
| errors = [{ 'message' => 'No more results available at this page number.' }] | ||
| end | ||
| end | ||
|
|
||
| # Use Analyzer for consistent pagination across all search types | ||
| @pagination = Analyzer.new(@enhanced_query, primo_response, :primo).pagination | ||
| { results: results, pagination: pagination, errors: errors, show_continuation: show_continuation } | ||
| rescue StandardError => e | ||
| @errors = handle_primo_errors(e) | ||
| { results: [], pagination: {}, errors: handle_primo_errors(e), show_continuation: false } | ||
| end | ||
|
|
||
| def load_timdex_results | ||
| def fetch_timdex_data | ||
| query = QueryBuilder.new(@enhanced_query).query | ||
| response = query_timdex(query) | ||
|
|
||
| @errors = extract_errors(response) | ||
| return unless @errors.nil? | ||
|
|
||
| @pagination = Analyzer.new(@enhanced_query, response, :timdex).pagination | ||
| raw_results = extract_results(response) | ||
| @results = NormalizeTimdexResults.new(raw_results, @enhanced_query[:q]).normalize | ||
| errors = extract_errors(response) | ||
|
|
||
| if errors.nil? | ||
| pagination = Analyzer.new(@enhanced_query, response, :timdex).pagination | ||
| raw_results = extract_results(response) | ||
| results = NormalizeTimdexResults.new(raw_results, @enhanced_query[:q]).normalize | ||
| { results: results, pagination: pagination, errors: nil } | ||
| else | ||
| { results: [], pagination: {}, errors: errors } | ||
| end | ||
| end | ||
|
|
||
| def active_filters | ||
|
|
@@ -121,9 +174,9 @@ def query_timdex(query) | |
|
|
||
| # Builder hands off to wrapper which returns raw results here. | ||
| Rails.cache.fetch("#{cache_key}/#{@active_tab}", expires_in: 12.hours) do | ||
| raw = if @active_tab == 'geodata' | ||
| raw = if Feature.enabled?(:geodata) | ||
| execute_geospatial_query(query) | ||
| elsif @active_tab == 'timdex' | ||
| elsif @active_tab == 'timdex' || @active_tab == 'all' | ||
| TimdexBase::Client.query(TimdexSearch::BaseQuery, variables: query) | ||
| end | ||
|
|
||
|
|
||
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
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.
Alternatively to removing the first condition in the active_tab logic, we should instead set
geodataas a valid tab. I think in real-world scenarios that is fine but when changing your local or a pr build between geodata and normal you may end up in wonky states where the cookie says to load an invalid tab?I think I'd either remove the geodata logic from
active_tabor keep it and add which tabs are valid here in each mode with a feature flag. I'm happy to chat if it would be helpful to work through the edge cases we are trying to support in real time.