Limit how many facets values a user can select

Created on 19 March 2025, about 2 months ago

Problem/Motivation

Our site is not behind a CDN and we are seeing a spike in traffic to our search page specifically with facet url parameters populated. My understanding is search pages cannot be cached so any hit to the search page is a full drupal boot and query to the search backend - but I wouldn't mind a verification of this. Also, since facets are rendered as links, bots seem to have a field day with them and can get locked into continuously crawling search results. We are still experiencing a spike in traffic even though links/facets are no follow and our robots.txt disallows traffic to our search page.

This problem is not limited to just our sites and other's in the community are experiencing it as well β†’ .

Steps to reproduce

* create a drupal search experience with facets
* publish/make live without any cdn
* take a look at access logs to review traffic.

Proposed resolution

I solved this by removing the facet that was being hammered by suspicious traffic. I also updated our .htaccess to redirect all traffic to our homepage if the url args did not match our approved facet list. The hope here is that our homepage has a better cache hit .

However, I think what would be more helpful is either a search page/search index specific facet limit or a per facet limit. Just to be clear, the limit here is the number of facets a user can select via the UI AND pass in the URL.

Here are some thoughts about approach:

  • Search page index global limit
    • I imagine a form where you can select index or search path
    • Then you select the max amount of facets options should be allowed
    • When a request comes in with more than the max options those url parameters exceeding the max are removed
  • Per facet limit
    • In the facet config form you select the max amount of facets options should be allowed
    • When a request comes in for that facet with more than the max options those selections exceeding the max are removed
    • The facet grouping should include a help text of "select a max of x" where x is the max.

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States robpowell Boston

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

Comments & Activities

Production build 0.71.5 2024