Allow search keywords in GET arguments (rather than path)

Created on 28 July 2022, over 2 years ago
Updated 28 November 2023, about 1 year ago

Currently, panopoly_search puts the search keywords into the path, just like Drupal core. For example: /search/site/MY_KEYWORDS

For analytics, it can be useful to have them into the GET arguments instead. For example: /search/site?keys=MY_KEYWORDS

Let's give site builders the option to have them in the GET arguments if they want.

πŸ“Œ Task
Status

Fixed

Version

1.0

Component

Search

Created by

πŸ‡ΊπŸ‡ΈUnited States dsnopek USA

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs work almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States cboyden

    These patches are working on a Panopoly child distribution. However, there is an issue with the Behat test step.

    Here's the new step that's being added to check that the GET parameter is empty when the system is set to use the path instead of query parameters:

      /**
       * @Then /the (?i)get(?-i) argument "(?P<argument>[^"]*)" should match "(?P<value>[^"]*)"$/
       */
      public function getArgumentMatches($argument, $value) {
        $url = $this->getSession()->getCurrentUrl();
        $query_string = parse_url($url, PHP_URL_QUERY);
        parse_str($query_string, $query);
    
        if (!isset($query[$argument])) {
          $query[$argument] = '';
        }
    
        if ($query[$argument] !== $value) {
          throw new \Exception("GET argument '{$argument}' with value '{$query[$argument]}' doesn't match '{$value}'");
        }
      }
    

    And here's the scenario in the test that checks for it:

    @api @panopoly_search
      Scenario: Performing a search with results
        Given I am on the homepage
          And I run drush "vdel" "panopoly_search_keys_mode -y"
          And "panopoly_test_page" content:
          | title           | body        | created            | status |
          | fxabR86L Page 1 | Test page 1 | 01/01/2001 11:00am |      1 |
          | fxabR86L Page 2 | Test page 2 | 01/02/2001 11:00am |      1 |
          | X9A1YXwc Page 3 | Test page 3 | 01/03/2001 11:00am |      1 |
          And I run drush "cron"
        When I fill in "fxabR86L" for "Enter your keywords" in the "Search" region
          And I press "Search" in the "Search" region
        Then I should see "Search Results"
          And I should see "2 items matched fxabR86L"
          And I should see "Filter by Type"
          And I should not see "X9A1YXwc"
          And the URL should match "/search/site/fxabR86L$"
          And the GET argument "search" should match ""
    

    The problem is that in PHP 8.1, the test code hits a runtime error:
    8192: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated in /panopoly_test/behat/steps/panopoly_test.behat.inc line 1165

    It looks like we either need a separate test step to check that a GET parameter is missing, or we need to do something different if there are no query string parameters at all, or if the one we're checking for is missing.

  • Status changed to Needs review almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States dsnopek USA

    Here's a patch that fixes the PHP error in my testing.

    • dsnopek β†’ committed 1c9645a5 on 7.x-1.x
      Issue #3300552 by dsnopek: Allow search keywords in GET arguments (...
  • Status changed to Fixed about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States dsnopek USA

    Merged. Thanks!

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

Production build 0.71.5 2024