3

Drupal 7 - Can you you exclude an entire content type (or just selected entries from it) from being indexed so they won't come up in a search result? I'm just assuming that indexing is the answer but the main point is that neither of the items will come up on a search result.

4

You can use the Search API module in Drupal 7 to give you this granular control over your search indexing and results.

You will need at least one other module to use the Search API, namely one that defines a service class (e.g. search_api_db ("Database search"), provided with this module).

  • Creating a server (Configuration > Search API > Add server)

The most basic thing you have to create is a search server for indexing content. Go to Configuration > Search API in the administration pages and select "Add server". Name and description are usually only shown to administrators and can be used to differentiate between several servers, or to explain a server's use to other administrators (for larger sites). Disabling a server makes it unusable for indexing and searching and can e.g. be used if the underlying search engine is temporarily unavailable. The "service class" is the most important option here, since it lets you select which backend the search server will use. This cannot be changed after the server is created. Depending on the selected service class, further, service-specific settings will be available. For details on those settings, consult the respective service's documentation.

  • Creating an index (Configuration > Search API > Add index)

For adding a search index, choose "Add index" on the Search API administration page. Name, description and "enabled" status serve the exact same purpose as for servers. The most important option in this form is the indexed entity type. Every index contains data on only a single type of entities, e.g. nodes, users or taxonomy terms. This is therefore the only option that cannot be changed afterwards. The server on which the index lies determines where the data will actually be indexed. It doesn't affect any other settings of the index and can later be changed with the only drawback being that the index' content will have to be indexed again. You can also select a server that is at the moment disabled, or choose to let the index lie on no server at all, for the time being. Note, however, that you can only create enabled indexes on an enabled server. Also, disabling a server will disable all indexes that lie on it. The "Index items immediately" option specifies that you want items to be directly re-indexed after being changed, instead of waiting for the next cron run. Use this if it is important that users see no stale data in searches, and only when your setup enables relatively fast indexing. Lastly, the "Cron batch size" option allows you to set whether items will be indexed when cron runs (as long as the index is enabled), and how many items will be indexed in a single batch. The best value for this setting depends on how time-consuming indexing is for your setup, which in turn depends mostly on the server used and the enabled data alterations. You should set it to a number of items which can easily be indexed in 10 seconds' time. Items can also be indexed manually, or directly when they are changed, so even if this is set to 0, the index can still be used.

  • Indexed fields (Configuration > Search API > [Index name] > Fields)

Here you can select which of the entities' fields will be indexed, and how. Fields added by (enabled) data alterations will be available here, too. Without selecting fields to index, the index will be useless and also won't be available for searches. Select the "Fulltext" data type for fields which you want search for keywords, and other data types when you want to use the field for filtering (e.g., as facets). The "Item language" field will always be indexed as it contains important information for processors and hooks. You can also add fields of related entities here, via the "Add related fields" form at the bottom of the page. For instance, you might want to index the author's username to the indexed data of a node, and you need to add the "Body" entity to the node when you want to index the actual text it contains.

  • Index workflow (Configuration > Search API > [Index name] > Workflow)

This page lets you customize how the created index works, and what metadata will be available, by selecting data alterations and processors (see the glossary for further explanations). Data alterations usually only add one or more fields to the entity and their order is mostly irrelevant. The order of processors, however, often is important. Read the processors' descriptions or consult their documentation for determining how to use them most effectively.

  • Wow, thank you for your very thorough answer. I'll look into it and let you know if it works. Although from your explanation I'm pretty sure that it will. – enchance Aug 6 '11 at 15:34
  • What service class would you suggest? – enchance Aug 7 '11 at 13:47
  • just a quick question, does this also work for preventing comments from being indexed? – Alex Mar 21 '14 at 13:06
0

This is a native feature of the https://drupal.org/project/apachesolr module.

Using apachesolr + the apachesolr module you can configure the content types that you wish to have indexed using checkboxes. No coding required here.

Plus you get the added bonus of a far more advanced search engine, with facets etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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