Closed (fixed)
Project:
Google Programmable Search Engine
Version:
4.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
30 Jan 2024 at 18:17 UTC
Updated:
18 Apr 2024 at 15:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #4
mark_fullmerThis feature request makes sense as a plausible use case for sites, and I think this also forces the configuration of the existing query parameter to be refactored in a way that makes it less haphazard across the code, requiring a centralized definition of the query parameter.
The merge request, above, provides a new "Query parameter key" setting in the Search configuration, as shown in the image below. Community testing of this would be great; automated test coverage is added as part of the merge request.
Comment #5
afschHey @markfullmer, thank you for this contribution, I was testing it (patch) but, it looks like there is a conflict with the Core Search code. Let me give you more context.
I do have the following scenario, Drupal 10.1.8, Web Server nginx/1.24.0, PHP 8.1.26, DB 10.3.39-MariaDB, google_cse 4.0.0-alpha3.
For this project, I had to create 2 patches (attached), the first for `google_cse` and another for `drupal:search`. The patches update the keyword used in the URL from `keys` to `query`. It works.
Now, after using your solution I could configure the `Query parameter key` value. Still, I saw something odd with the block added in the Block Layout and the Search form shown on the Search results page, using the first block for searching, effectively uses the `query` parameter, but using the form from the Search results page uses the `keys` parameter. NO RESULTS are displayed in either case.
- Block and configuration


- Configuring the parameter keyword

- Using the Form from Search Results page

- Using the block added via Layout Builder

As an important note, this module requires the `drupal:search` module, IMO I'd say to find a way to override the search class so we could have it configurable in this module only.
Comment #6
mark_fullmerHey afsch! Thanks for the review! In my testing (and intended design), both the block and the standalone search form work with a custom-defined query setting, and the updated test coverage appears to demonstrate this for both contexts, per https://git.drupalcode.org/project/google_cse/-/merge_requests/5/diffs#0...
That's the precise intention of the route subscriber here: https://git.drupalcode.org/project/google_cse/-/merge_requests/5/diffs#c...
I'll take a closer look at the steps you took and see where we're getting different results and report back.
Comment #7
mark_fullmerAh...at first I thought that the patch attached in #5 was a replica of what is in the merge request. It is not. Can you test what is in the merge request? If that is new to you, you can get a patchfile from https://git.drupalcode.org/project/google_cse/-/merge_requests/5.diff
Comment #8
afschHey Mark, effectively I'm using your patch and the screenshots are the result of using it in my project. The attached files (patches) are the custom solution I'm currently using to have the parameter updated.
Comment #9
mark_fullmerThanks for the additional info, afsch! The problem ended up being some logic that was expecting only the machine name
google_cse_searchas the search ID. The latest commit to the merge request makes the Controller override work with any machine name.If you have a chance to test again, we'd appreciate it!
Comment #10
afschHey @mark_fuller, it works, now I can see the Results Page with results. But, I had to do a small configuration update in the Search block, this is changing the "Search input type" to 'Drupal'. It was previously set to 'Google' option, when submitting for search it was again using the "keys" parameter hence no results.
Here are the screenshots:
Results:
Maybe it needs a small adjustment about that configuration with "Google" option when configuring the search block, but for now, I'm using your solution as a local patch because it works. If you need me for more testing please let me know :)
Comment #11
mark_fullmerThanks, @afsch! This is fixed in https://git.drupalcode.org/project/google_cse/-/merge_requests/5/diffs?c...
Comment #12
afschHey @mark_fullmer, it works like a charm! I tested with the "Google" option for the block configuration.
For the same search block configured with "Drupal" option something weird happens, this is because it doesn't redirect to the Search Results page, but keeps the current URL adding extra parameters. E.g.:
Comment #13
afschHey Mark, Here I leave a custom code I added to resolve the extra query parameters.
It overrides the default redirect specifying the path and query only, making it cleaner.
File:
google_cse/src/Form/GoogleCSESearchBoxForm.phpInstead of:
Use:
And for the
submitForm()function add this code:Probably this is the faster way to have it fixed. Let me know if that works. Thanks.
Comment #14
mark_fullmerI *think* this may be a case of "works as designed." In other words, my understanding is that the purpose of the Google CSE-provided block is to have a standalone block that can be placed in the layout and will provide a search input plus search results at that place in the layout. It is explicitly intended *not* to redirect to the search page. My understanding is that if someone wants to have the search redirect to the search page, they are expected to use the Drupal core search block, rather than the Google CSE-provided search block.
If there is a reason that someone would want/need to use the Google CSE-provided search block rather than the Drupal core search block, and have it redirect to the search page, we need to understand why, and I think it would need to be written up as a new feature request, because changing the behavior to redirect to the search page would change how the block behaves on existing sites.
So, with that said, if there is a use case for this scenario, let's write it up as a separate issue and investigate further (importantly noting that the implementation would need to honor the new
'query_key'configuration option introduced in this issue.Based on the rest of the comments, it appears that this issue is ready to be merged.
Comment #16
mark_fullmerComment #17
jenna.tollersonReally stoked to see this merged and released, thanks y'all. :)