Oct 24, 2011

Backend search improvements in TYPO3 4.6

TYPO3 4.6 brings a lot of great enhancements. I would not tell you all of them in this post but you will learn about one of them. The reason to choose this enhancement is that it has a certain effects on TYPO3 extensions. Extension authors need to be aware of this change and adjust their extensions accordingly.
The enhancement I mean is an improvement of the Backend search. What was wrong with the old search? The old search worked like this:

Take all numeric fields and add them to the list of searchable fields (including uid and date/time fields)

Take all input and text fields and add them to the list (including, for example TSConfig field)

Use LIKE %...%

Search every table in the database if the table is in $TCA

Search 4 levels deep maximum but never say it to anybody. So people would wonder why can't they find results deep in the tree.

That causes too many fields to search for each table (most of them unnecessary). Also it searches numeric fields for string patterns using LIKE, which is a very slow operation. In case if there are many extensions installed, searching could take minutes.

What was changed? The search was adjusted to work like this:

Use only specially configured fields for search (i.e. we can search "bodytext" field but generally there is no need to search "TSConfig" or i18n_diffsource field)

This method has a lot of advantages. Firsts, it is much faster. There are less SQL queries. And of those there are less LIKE queries. The search skips tables that do not need to be searched. There are no hidden strange restrictions on pid. There are no searching of numeric fields for strings.

So, where is the catch? Nothing good comes without a catch. The catch is that all extension tables are not searchable anymore because they do not have search configuration in them. Fortunately, this is very easy to fix.

For integrators, to get the old behavior, you can install the extension named "Compatible Backend search" (extension key is compat_besearch). That would scan extension tables and make them searchable. There is no configuration, just install the extension and you get extension search back. But this will work only for TYPO3 4.6.x. As soon as you upgrade to a future 4.7.x, this extension will stop working. It is expected that all extension authors update their extensions till that time.

For extension authors, you need to add a new entry to the ctrl section of the $TCA named searchFields. There you list fields you want to be searchable. You can put both text and numeric fields here. Search will examine field's configuration and automatically exclude numeric fields from the search. Have a look to the TYPO3 sources to see how it is done for the TYPO3 core tables. If you do not want the table to be searchable, you should have an empty searchFields for TYPO3 4.6.x with compat_besearch extension and you can leave out searchFields at all for TYPO3 4.7.x.

If you want even more control, you can define when the field will be used for search. For example, it makes no sense to use bodytext column of the tt_content table when content type is header. You only need to configure it in the field configuration (example). This is handled efficiently in the new Backend search, so not costly operations are executed before this check.

Extension authors can start adding search configuration for TYPO3 4.6.x already now. It does not affect older TYPO3 versions in anyway but extensions will be fully ready when a great new TYPO3 release is out.