Place Google search input as standalone block

Created on 13 February 2023, almost 2 years ago
Updated 28 April 2023, over 1 year ago

Problem/Motivation

When using the search bar from GoogleCSESearchBoxForm.php, there is no autocomplete even when it is enabled on the Google Programmable Search Engine account, and autocomplete results are showing on the public version of the search engine (https://cse.google.com/cse).

Steps to reproduce

1) Install and enable 8.x-3.7 of Google CSE on a Drupal 9 instance.
2) Create a sample Google CSE page from Search and Metadata -> Search Pages
3) Configure the Google CSE ID in the edit page
4) Observe that although results show up as expected, when you search in the search bar, there are no autocomplete suggestions.
5) Observe in your Google account that Autocomplete is enabled and when you go to the public URL of it (https://cse.google.com/cse), autocomplete suggestions are working.

Image attached shows an example of autocomplete working in the Google account, but not in the Drupal integration.

✨ Feature request
Status

Fixed

Version

4.0

Component

User interface

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @bruce.yuen
  • Status changed to Needs review almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Thanks for asking about this, and for specifying that you're using the 3.7 version of this module.

    The Google Programmable Search feature for autocomplete relates to the search input that it provides, not the Drupal search input. Based on my research in the API documentation, there is no way to add Google's autocomplete functionality to a generic form markup. It has to be the Google-styled div tag with attributes that allow its JavaScript to create the form.

    That said, this module could definitely provide an option for people to choose to display Google's search input rather than the Drupal form input. It would work this way:

    1. Content editor places the "Google Programmable Search" block in the layout (e.g., the header), instead of the default Drupal search block:

    2. Content editor chooses the (new) "Google" option from the search input dropdown:

    3. Optionally, the content editor can use the configuration within Drupal (/admin/config/search/pages --> Google PSE search instance) to enable autocomplete, rather than configuring it in Google:

    The Google-provided search input, with autocomplete, would then display in the layout, and a search would redirect to the search page.

    The attached patch implements this.

    A couple notes:
    1. Theming of the Google search would be the responsibility of the site, not this module.
    2. The 3.x branch of this module can be considered outdated. Full support for the newer Google PSE API is in the 4.x branch. I'm updating this issue to reflect that.
    3. I'm going to reclassify this as a Feature Request rather than a Bug Report.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    The patch failed to apply because this issue was referencing the 3.x branch when it was created. Here's the same patch, now that this issue references the 4.x branch.

  • Status changed to Active almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Taking a step back, I think it'd be useful for the community and the maintainers to evaluate whether this feature request fits well with the purpose of the google_cse module.

    We can use the technique of the 'user story' to consider this.

    One user story could be "As a site builder, I want to be able to place the Google-provided search input in my layout instead of the Drupal search input so that I can make use of its features, such as autocomplete."

    With this user story, this feature request might be practical for the google_cse, as it doesn't change the scope of what the module does in relationship to the Google PSE API.

    Another user story could be "As a site builder, I want to have fine-grained control over how the Drupal search input implements the features of the Google PSE search input, so that I can retain the Drupal form markup but leverage Google search features."

    With this user story, the google_cse module is not the right tool for this user. Users looking for this kind of control would likely be better served using a different contributed module, https://www.drupal.org/project/google_json_api β†’

    Moving this issue back to "Active" for further discussion.

  • πŸ‡ΊπŸ‡ΈUnited States kreynen

    When I started looking at this, I was originally thinking that the autocomplete options wouldn't provide much value.

    Then I realized that autocomplete suggestions are CSE instance specific... to a certain extent.

    If there is no top content related to a term, it will just throw general suggestions. Even when there is CSE instance relevant suggestion, if there aren't enough it will start loading general suggestions.

    Good: On https://cse.google.com/cse?cx=17a13377043fa47f9 if you start typing terms with results on cu.edu like "serv..." or "ecom..." you will be prompted with more specific terms related to content on sites defined in scope of the CSE instance.

    Less Good: If you start typing something like "reynen", the autocomplete suggests "Reynen Court" or "Reynen Luxury Homes" and "Reynen Bardis LLC". These autocomplete suggestions are similar to what you get when using https://www.google.com/ and will not result in any content.

    Mixed Bag: The current President of the University of Colorado is Todd Saliman. If you start typing "tod..", it does prompt you with relevant terms at the top, but suggestion #5 if Todd Chrisley. There is no content about Todd Chrisley on any cu.edu site... and I'm not sure we want to imply there is.

    Not sure this information would influence the decision to add support for the feature one way or the other, but I didn't know how this worked until now so I'm guessing there other people who don't know the autocomplete suggestions are (to a certain extent) specific to the CSE instance.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Thanks, @kreynen! This is valuable information! I hadn't thought to test whether the search suggestions are scoped to the Google PSE search instance. My personal opinion is that, based on your testing, the "autocomplete" feature is of minimal/debatable value, and Google should really call it something like "search suggestions" rather than a true "autocomplete."

    This is helping me better understand how this issue relates to the scope of the google_cse module overall. Ultimately, I think this issue should be framed less as "support autocomplete" and more as "allow Google search input." This module already supports the autocomplete via the Google search input in the results page, if users configure that to be displayed, so the question is not really whether this module should support that feature or not, but where it makes the Google search input available.

    As a result, I've retitled this issue "Place Google search input as standalone block," which is really what the underlying change would be. This would allow the OP to achieve the goal of having a search input in the header, for instance, with autocomplete, but beyond that, this module's scope stays the same: it is simply a middleware for rendering the Google PSE functionality.

  • πŸ‡ΊπŸ‡ΈUnited States gravelpot

    I agree with @kreynen's input that PSE autocomplete is of questionable value given that Google will start offering autocomplete suggestions outside the scope of that particular PSE's configured search engines. But I also agree with @mark_fullmer's observation that since autocomplete is already available via the optional Google search input on the search results page, that horse has already left the barn.

    So this issue isn't so much about autocomplete per se, but can be viewed as supporting direct placement of the Google search input as a standalone block. What exactly that facilitates and what value it provides is up to the site owner. In a Google PSE instance that is set to the default behavior of searching the entire internet, the autocomplete feature could be considered more useful. It seems counter-intuitive to the value of using Google PSE for "site search," but maybe there's a valid use case for that.

    This seems like a pretty small lift to reinforce our goal in the 4.x rebuild of providing more direct access to all of the Google PSE core functionality, so I support it.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Based on the community input from above, I'm setting this now to "Needs Review," under the rationale that this module should support direct placement of the Google search input as a standalone block.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States mmarler

    PHP syntax error is reported in the tests:

    line 142 A comma should follow the last multiline array item. Found: 'Google'

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    1 pass
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Code syntax violation fixed!

    • mmarler β†’ committed e83c9cdf on 4.x
      Issue #3341409 by mark_fullmer, mmarler: Place Google search input as...
  • Status changed to Fixed over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States mmarler

    Reviewed, tested and merged. Moving to Fixed.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024