Problem/Motivation

I was trying out my newly configured Database search and found that when I used the "-" character, which is used in search to negate one of the search terms, a warning message was produced from google_tag.

I don't know if this has any other negative impact besides failing to log the query.

Steps to reproduce

1. Set up Search API, server, index, and results view
2. Install google tags
3. enter "back -forward" any other combination of words where one of them has a "-" directly before it.
4. your search will work fine, but if you have the same issue as me, you will see this warning message:
Warning: Array to string conversion in Drupal\google_tag\EventSubscriber\SearchApiSubscriber->onSearch() (line 61 of modules\contrib\google_tag\src\EventSubscriber\SearchApiSubscriber.php).

Proposed resolution

  1. Find out the structure and contents of the array which is passed to the 'onSearch()' function when a search query includes a "-"
  2. Adapt the 'onSearch()' function to recombine that array into a string

Issue fork google_tag-3412226

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jacobupal created an issue. See original summary.

jacobupal’s picture

Issue summary: View changes
jacobupal’s picture

Issue summary: View changes

chetan 11 made their first commit to this issue’s fork.

chetan 11’s picture

Status: Active » Needs review

Please check the above MR.

jacobupal’s picture

I'm afraid your addition incurred the same warning, however I've made a different change to the MR that seems to work:

This version checks whether each item in 'keys' is a string, and converts it if not, just before the 'implode' step recombines the whole thing.

jacobupal’s picture

Never mind, with that test failed, no wonder the error went away, it seems to have just deleted the query.

jacobupal changed the visibility of the branch 3412226-warning-array-to to hidden.

jacobupal changed the visibility of the branch 3412226-warning-array-to to active.

jacobupal’s picture

OK, I got it passing... the only problem now is that the logged query will not include the hyphen so even though the test string foo bar baz works foo -bar would probably fail the test as the '-' becomes the boolean operator 'NOT' and this version strips boolean operators so the result would befoo bar. So somehow among all the array-to-string stuff the '-' needs to be brought back.

This is good enough for me, for now though, as I think only a minority of searches will use this feature and be logged wrong.

Probably the event test should include a hyphen, and maybe even quote marks, for completeness, something like
foo -bar "fizz buzz" -"far boo"

japerry made their first commit to this issue’s fork.

japerry’s picture

Status: Needs review » Fixed

Incremental progress is still progress, so gonna just commit this. If users need more functionality they should open a new issue and reference this one.

  • japerry committed 3811eead on 2.0.x authored by chetan 11
    Issue #3412226 by jacobupal: "Warning: Array to string" when Search API...

Status: Fixed » Closed (fixed)

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