Suppose I have a custom page built in a custom controller. Or similarly, a view page the displays the list of nodes, such as the classic "admin/content" page.

I want certain user roles to be able to find this page when they search the site. The search does not have to index the entire view/page content, but rather a select parts of the content.

Is this possible to do using core hooks? If not, then perhaps using search api hooks? I am thinking of hooking into the indexing process, and then, retrieve the pages I want to index and send them along. But I am not sure how to do this in a abstract manner where the implementation would work using core database search or search api with solr.

Note Drupal 7 or 8 ideas would be much appreciated.

  • When you want more out of your search you should install search api. Once downloaded take a look at the file search_api.api.php inside the module folder for available hooks that may help in your case. Search api is very powerful but also very complex module and things like indexing and handling custom content or custom facets are all possible with this module.
    – seroton
    Mar 21, 2019 at 16:18

1 Answer 1


Yes, it's possible to provide a custom search index for either the Core/Search API module. Both modules are using the D8 plugin API to create their own plugin types for providing new indexing.

  • In Core, the SearchPlugin plugin type allows you to define the methods that you will need to implement for all aspects of search. To see how this works, look at the core UserSearch & NodeSearch plugins to see how it interfaces with queries and indexing.

  • For SearchAPI, there are many different plugin types for interfacing with its different aspects of search. For brevity, you should start looking at the SearchApiDatasource plugin type to start providing a new indexable source.

In regards to an "abstract manner where the implementation would work using core database search or search api with solr," you're going to have to get clever with OOP and the plugin classes you're providing in your module if you want to do something like that. You're better off implementing each first, then abstracting later (if it provides benefits).

  • Thats very helpful. Thanks. So in my custom code I will have to take over the core search and index what I want.
    – awm
    Mar 22, 2019 at 14:19
  • I wouldn't say "take over" is how you describe it; you're not replacing/modifying the existing code. Rather, you're implementing a plugin/methods that core search knows how to run for indexing, searching, etc. to provide new search functionality.
    – Shawn Conn
    Mar 22, 2019 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.