Wrap scoped search autocomplete values in quotes when they contain a pipe character#1083
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR overrides the scoped_search tokenizer to remove the pipe character from its operator regex—allowing rule IDs containing '|' to be treated as single keywords—and updates the host association to explicitly reference Host::Base. Sequence diagram for scoped search keyword tokenization with pipe charactersequenceDiagram
actor User
participant InsightsHit
participant ScopedSearchTokenizer
User->>InsightsHit: Search for rule_id with pipe (e.g. dnf_install_update_issue|DNF_INSTALL_UPDATE_ISSUE_INFO)
InsightsHit->>ScopedSearchTokenizer: Tokenize keyword
ScopedSearchTokenizer-->>InsightsHit: Treat entire rule_id (with '|') as single keyword
InsightsHit-->>User: Return correct search results
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
The catch with this is that this applies application-wide, which means searches will behave differently based on whether rh_cloud is enabled or not.
scoped_search already wraps autocompleted values in quotes in case they contain whitespace (link). Wouldn't it be better to wrap the autocompleted values in quotes if they contain any special operators as well? |
6ca72dd to
8674ca0
Compare
|
@adamruzicka updated 👍 |
|
Why carry the fix here? Why not send it to https://github.com/wvanbergen/scoped_search ? |
|
I would also like to have it fixed in scoped_search. This PR can be a temporary change until that is in place. |
I am fine with a fix here for the time being, looking at pull requests and activity in that repo, it seems a fix would sit for a while before being merged. |
|
Opened wvanbergen/scoped_search#230 |
for values containing the pipe character
8674ca0 to
355fdbf
Compare
chris1984
left a comment
There was a problem hiding this comment.
Looks fine, had to use Gemini to figure out the regex 🤣 will test it tomorrow.
nofaralfasi
left a comment
There was a problem hiding this comment.
I tested the PR and can confirm it works as expected.
chris1984
left a comment
There was a problem hiding this comment.
Code looks fine and @nofaralfasi tested it
|
Thanks for the reviews all! I am going to merge this one unless I hear any objections. Will need to revert it once the scoped_search PR is fully in place. |
for values containing the pipe character (cherry picked from commit b2ffab5)
for values containing the pipe character (cherry picked from commit b2ffab5)
What are the changes introduced in this pull request?
Insights rule IDs frequently (almost always) contain the pipe character,
|. This causes problems when using scoped search to perform a search likebecause scoped search would take the pipe character as an "OR", and do separate searches for the keywords on each side of the pipe. This means that you don't get any results unless you put the keyword in quotes:
Which is fine, except that scoped search autocomplete suggests the search without the quotes.
I tried various ways of modifying scoped_search to add the quotes, including external search methods and
value_translation. But the problem there was that these receive the search keyword values after scoped search already split up the values on either side of the pipe.The solution here is to have the scoped search autocomplete builder suggest the quotes. This requires redefining a method.
Considerations taken when implementing this change?
This will affect the behavior of scoped_search application-wide, not just for InsightsHit or foreman_rh_cloud. Ideally scoped_search itself can be updated with this change eventually, and the change would apply to all special operators and not just pipe. For now, I have it only affecting pipe.
What are the testing steps for this pull request?
Non-IoP
get a host with recommendations
Insights > Recommendations
Perform a search for "rule_id = "
Accept one of the autocomplete suggestions
Before: You get 0 search results. If you put the rule ID in quotes, it works.
Now: Autocomplete suggested values are already in quotes, so it works.
Summary by Sourcery
Fix scoped_search to correctly handle Insights rule IDs containing '|' and update the InsightsHit host association to use an explicit class name
Bug Fixes:
Enhancements: