Global SearchReplace (done)

Note: this has been implemented, as a service available in Silva 2.2.

Sometimes it’s necessary to search all content of a site for a specific string of text and replace it with another. This blueprint attempts to work out the use cases for a site-wide SearchReplace service. The SR functionality will be a Silva service, located in services in the ZMI, and thus can only be accessed by managers.

Note that authors can use a Code Source which also searches the whole site, but it only scans the url (not text) of links and image paths. This was created by Marc Petitmermet and the global SearchReplace service uses some of his ideas. The Code Source can be found at:

Base case

The service interface has an input field for a search string, another input for the replacement string, and a search button.

The result of the search is a listing of documents which contain the string. Above the listing statistics are provided, e.g. “57 documents scanned, 4 occurrences found in 2 documents”. For each result in the listing the following information is shown:

  • A checkbox
  • Number of occurrences of the string in the document
  • The path to the document, which is rendered as a link
  • The version state (published or editable)

Below the listing a ‘select all’ checkbox is provided, and a replace button.

The manager can select some or all of the documents in the listing and execute a replace.

After the replace action, the documents are left in their original state. A published document remains published, and an editable version is still editable. If both versions exist and were selected both are modified.

Points to consider

  • Only ‘versioned content’ objects are searched. Closed versions are not searched, nor the content of textual assets.
  • Empty replacement strings are allowed.
  • The fields must support unicode.

Torvald, 08/06: Also consider alt attributes of images and any title attributes

Special use case: SearchReplace Paths Only Option

The textual SearchReplace doesn’t find or change paths. That could be dangerous, breaking links and references in a site. When searching and replacing paths is the intention, the manager can activate a checkbox which will limit the search to urls/paths in links and image paths.

Edge cases

In a large site there could be thousands of results. The results screen has batching if needed. This could be configurable, with the default at, say, 200 documents. When batching is in effect, there needs to be an additional option to select the complete result set and do a replace.
Code Sources
We need to decide whether to SearchReplace within Code Source parameters. For example:
<parameter type=“string” key=“capsule_title”>Presentations</parameter>
We should never replace a type parameter (someone could search for the word ‘string’ and it would break every Code Source in the site). Same goes for the key which would bread individual sources. But the parameter value could be changed.

Irene, 08/06:
Search and replace within Code Sources is not necessary in my opinion, as they are usually limited in quantity. 
Other elements
We need to check how the search and replace handles anchor/index items, abbreviations and acronyms, and how it works within tables.
Searching only under a specific path
Irene, 08/06: In case of a large Silva Root the search process would take a long time.  Therefore an option to search and replace only under a specific path would be desired.


  • There is no undo.
  • There is no previous version of a document. The xml of the document is modified. We can’t make a new version because there could be an editable version with other changes.