Skip to content
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

Daccess 412 advanced search empty rows fix #2218

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from

Conversation

JeremyDuncan
Copy link
Contributor

@JeremyDuncan JeremyDuncan commented Jan 17, 2025

Key Features Added

1. Search History Enhancements

  • Location:
    • blacklight-cornell/app/controllers/search_history_controller.rb
    • blacklight-cornell/app/helpers/cornell_search_history_constraints_helper.rb
  • Improvements:
    • Filters redundant or empty search history entries.
    • Custom formatting for advanced searches with operators (AND, OR, etc.) and boolean values for clarity.

2. Search Session Management

  • Location: blacklight-cornell/app/controllers/catalog_controller.rb
  • Purpose: Refines session handling to avoid creating empty or redundant search history entries for advanced and regular searches.
  • Logic Updates:
    • Advanced searches: Only save sessions if a query (q_row) is present.
    • Regular searches: Save sessions if any relevant parameters (search_field, q, or f) are populated.

3. Query Parameter Filtering

  • Location: blacklight-cornell/app/services/blacklight/search_service.rb
  • Functionality:
    • Removes rows with blank values from advanced search query parameters.
    • Ensures consistency across related fields like q_row, search_field_row, and boolean_row.

4. Custom Blacklight Helper

  • Location: blacklight-cornell/config/initializers/backlight_custom_helper_loader.rb
  • Details: Introduced a loader to prepend custom helper methods to Blacklight’s helper modules, ensuring custom logic seamlessly integrates with default behavior.

@@ -1,4 +1,7 @@
class ApplicationController < ActionController::Base
# include ConsoleColors if CONSOLE_COLORS_ENABLED=true in dev.env
include ConsoleColors if ENV["CONSOLE_COLORS_ENABLED"] == "true"

Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nice to split out this ConsoleColors work into a separate PR so other folks can take a look? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I could do that. 👍

# For advanced search, only start a new session if query is present
if params[:search_field] == "advanced"
query, index = params[:q_row], action_name == "index"
start_new_search_history_record = index && !(query[0].blank?)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this check if any query in the array is not blank, not just the first? The first row could be blank, but the other rows could have values, and we'd still want to track this search in history.

query_params["search_field_row"] = filtered_indices.map { |i| search_field_row[i] } if search_field_row.present?
query_params["q_row"] = filtered_indices.map { |i| advanced_query[i] }
query_params["boolean_row"] = boolean_row.select { |key, _| filtered_indices.include?(key.to_i) } if boolean_row.present?
query_params["op_row"] = filtered_indices.map { |i| operator_row[i] }
Copy link
Contributor

Choose a reason for hiding this comment

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

This will actually change the search params stored in the search history, not just for display, which leads to the following behavior for this example advanced search with an empty 3rd query row:

  1. Go to: http://localhost:9292/edit?boolean_row%5B1%5D=AND&boolean_row%5B2%5D=OR&boolean_row%5B3%5D=NOT&op_row%5B%5D=AND&op_row%5B%5D=AND&op_row%5B%5D=begins_with&op_row%5B%5D=OR&q_row%5B%5D=testing&q_row%5B%5D=stuff&q_row%5B%5D=&q_row%5B%5D=things&search_field_row%5B%5D=publisher&search_field_row%5B%5D=subject&search_field_row%5B%5D=journaltitle&search_field_row%5B%5D=title
  2. Click Search
  3. Note that Solr query is: (((publisher:"testing") AND (subject:"stuff")) NOT (title:"things"))
  4. Go go "Search history"
  5. See search history displayed as: Publisher: testingAND Subject: stuffANY Title: things - which loses the final NOT boolean.
  6. Click on that search history
  7. Note the different solr query generated: (((publisher:"testing") AND (subject:"stuff")) AND (title:"things")). If you go back to the search history page, you'll see a 2nd search history row created for this new search.

Would it be better to handle this param cleanup in the #render_search_to_s_element method, instead of changing the search object?

# *** Only Overrides Blacklight Helper Methods You Add ***
# ------------------------------------------------------------------------------
Rails.application.config.to_prepare do
Blacklight::SearchHistoryConstraintsHelperBehavior.prepend(CornellSearchHistoryConstraintsHelper)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. We use this prepend pattern in a few other repos (usda-esmis-sufia, exhibits-library-cornell-edu), but we add all those prepends in application.rb instead of its own initializer - I like this better!

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.

3 participants