Skip to content

Option to disable the search index via the config file #10142

Discussion options

You must be logged in to vote

You can prevent elements’ search keywords from getting indexed using the craft\services\Elements::EVENT_BEFORE_UPDATE_SEARCH_INDEX event. Add this code to your module:

use craft\events\ElementEvent;
use craft\services\Elements;

Craft::$app->elements->on(
    Elements::EVENT_BEFORE_UPDATE_SEARCH_INDEX,
    function(ElementEvent $event) {
        $event->isValid = true;
        $event->handled = true;
    }
);

Note that this will also affect the search bar above element indexes within the control panel, which will likely frustrate authors, so not recommended.

Instead of disabling element keyword indexing altogether, you can prevent all custom fields from getting indexed, which will reduce …

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@alexanderloewe
Comment options

@alexanderloewe
Comment options

@brandonkelly
Comment options

@alexanderloewe
Comment options

Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #10138 on November 23, 2021 12:39.