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.

Remaining tasks

Comments

daften created an issue. See original summary.

daften’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.56 KB

Status: Needs review » Needs work

The last submitted patch, 2: 3227659-double-facet-query-params-in-pager-2.patch, failed testing. View results

daften’s picture

Status: Needs work » Needs review
StatusFileSize
new1.61 KB
daften’s picture

Updated patch with a small improvement to isset for the pages

drunken monkey’s picture

Version: 8.x-1.19 » 8.x-1.x-dev
Component: General code » Views integration
StatusFileSize
new520 bytes

Thanks 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?

drunken monkey’s picture

Feedback would be very much appreciated, then I can commit this confidently.

  • drunken monkey committed 5d7c354 on 8.x-1.x
    Issue #3227659 by drunken monkey, daften: Fixed double-escaped query...
drunken monkey’s picture

Status: Needs review » Fixed

Would have been good to get feedback on the patch before committing, but still looks good enough to commit, I guess.
Committed.
Thanks again!

daften’s picture

Hi 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!

daften’s picture

Hi,

Checked and works perfectly. Thanks!

Status: Fixed » Closed (fixed)

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