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

Add explicit search query option. #2592

Merged
merged 3 commits into from
Aug 7, 2023

Conversation

Hyperkid123
Copy link
Contributor

Jira: https://issues.redhat.com/browse/RHCLOUD-27216

In addition to a wildcard search option add some variants and also an explicit term query to bypass the expected character. Gives higher priority to the explicit search matches.

Primarily deals with issues when an exact query does not match the search term.

@codecov-commenter
Copy link

codecov-commenter commented Jul 26, 2023

Codecov Report

Merging #2592 (d97d103) into master (f2edb10) will decrease coverage by 5.12%.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2592      +/-   ##
==========================================
- Coverage   57.60%   52.48%   -5.12%     
==========================================
  Files          92       92              
  Lines        2788     2450     -338     
  Branches      699      503     -196     
==========================================
- Hits         1606     1286     -320     
+ Misses       1140      763     -377     
- Partials       42      401     +359     

see 58 files with indirect coverage changes

@@ -196,7 +196,7 @@ const SearchInput = () => {
}, [isOpen, menuRef]);

const handleFetch = (value = '') => {
return fetch(SEARCH_QUERY.replace(REPLACE_TAG, value).replace(FUZZY_RANGE_TAG, value.length > 3 ? '2' : '1'))
return fetch(SEARCH_QUERY.replaceAll(REPLACE_TAG, value).replaceAll(FUZZY_RANGE_TAG, value.length > 3 ? '2' : '1'))
Copy link
Contributor

@vkrizan vkrizan Jul 26, 2023

Choose a reason for hiding this comment

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

Could the search query build be moved to a separate function?

Can the URL prams be build safely using a URL builder instead of search and replace? For example with URLSearchParams.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The query is built with URLSearchParams and then the URL is built with URL classes on the top of the file. The search endpoint currently does not allow encoded query string. It had to be disabled a few months back. Therefore there is no point in rebuilding the query on each request and the creating was lifted out of the callback to be static and save some resources.

Currently, the replace method is as good as using the search params constructor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I've missed the use of URLSearchParams.

Do we escape special characters within the search query?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I said, the search API does not support encoded/escaped characters. You can see that we actually have to decode the query params before using them in the query. My assumption is that the API requires special characters like * or ~ to build a valid SOLR query. But you would have to ask the search team for details.

Copy link
Contributor

Choose a reason for hiding this comment

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

Which API does not support encoded URI (query string)? Is that SOLR? Query string is part of the standard of RFC3986.

Copy link
Contributor

Choose a reason for hiding this comment

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

Found the references:

@Hyperkid123 do you have more info on the reason or can you ask the search team please? Was it reported to them?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm trying to send encoded ampersand %26 to stage API, it does not fail. However, not encoding these characters leads to HTTP 400.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not have any formal records. Discussion with the search team happened on a chat. I understand the encoded strings are part of the spec. The hydra API was returning 400 responses when we tried to send encoded queries.

Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed with Martin offline. IMO we will need to follow up on the URL encoding in a separate pull request - that way we can revert either (or both) PRs if there is an issue. It seems the search team fixed an issue with the Hydra REST endpoint that was originally causing the 400's (see slack thread). We should now be able to send the encoded special characters in the SOLR queries.

@Hyperkid123
Copy link
Contributor Author

/retest

@Hyperkid123
Copy link
Contributor Author

/retest

@Hyperkid123 Hyperkid123 merged commit ec0c8f3 into RedHatInsights:master Aug 7, 2023
6 checks passed
@Hyperkid123 Hyperkid123 deleted the fix-search-argument branch August 7, 2023 13:27
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