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
- Find out the structure and contents of the array which is passed to the 'onSearch()' function when a search query includes a "-"
- Adapt the 'onSearch()' function to recombine that array into a string
Issue fork google_tag-3412226
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
Comment #2
jacobupal commentedComment #3
jacobupal commentedComment #6
chetan 11 commentedPlease check the above MR.
Comment #7
jacobupal commentedI'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.
Comment #8
jacobupal commentedNever mind, with that test failed, no wonder the error went away, it seems to have just deleted the query.
Comment #11
jacobupal commentedOK, 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 bazworksfoo -barwould 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"Comment #13
japerryIncremental progress is still progress, so gonna just commit this. If users need more functionality they should open a new issue and reference this one.