Problem/Motivation
When using preserve_facet_query_args the exposed filter form gets the facet items injected in search_api_form_views_exposed_form_alter. When the pager manager then adds query parameters to each pager link it uses \Drupal\Core\Pager\PagerManager::getUpdatedParameters where the query parameters are in the form f->0->facet_item while the form has the items as f[0]->facet_item. This means facet items are added twice.
This means the pager causes a "spider trap" where search engines just keep finding pages to index. This destroys the SEO ranking of a site basically.
Steps to reproduce
* Create a search_api view with an exposed filter (e.g. for full-text search), make sure the preserve_facet_query_args setting is set
* Create a facet for the view, e.g. for a taxonomy term.
* Go to the page with the view and facet and use a facet
* Inspect the pager links.
Proposed resolution
* I tried updating search_api_form_views_exposed_form_alter to add the items as `$form["{$filter_key}"][$key] = [` instead of `$form["{$filter_key}[$key]"] = [`, which was a very stupid idea and didn't work. The other option involves updating core, which would be unmanageable.
At the moment I fixed it with the patch in attachment, but it feels like a less than ideal solution.
Comments
Comment #2
daften commentedComment #4
daften commentedComment #5
daften commentedUpdated patch with a small improvement to isset for the pages
Comment #6
drunken monkeyThanks for reporting this issue and providing such a detailed analysis. I could reproduce the problem without problems, and I think I even found a simple solution.
Does the attached patch resolve the issue for you?
Comment #7
drunken monkeyFeedback would be very much appreciated, then I can commit this confidently.
Comment #9
drunken monkeyWould have been good to get feedback on the patch before committing, but still looks good enough to commit, I guess.
Committed.
Thanks again!
Comment #10
daften commentedHi drunken monkey,
I had the mail marked down, but I lost track of it due to the holidays, my apologies. I'll try to test it on our project by the end of the weekend. Thanks for the patch!
Comment #11
daften commentedHi,
Checked and works perfectly. Thanks!