Merging search results

If you have several Movable Type blogs hosted on the same server, and you want search to return results for all blogs, by default you end up with two sets of search results.


Myself, I wanted the two sets of results merged into one numbered list, no matter if the search result was from the blog I keep my help files in, or if it was my main blog. And I wanted a friendly help message when the search returned no results.
Using the “Switch plugin”:http://virtuelvis.com/archives/2003/03/mtswitch I modified my search templates to get the result I wanted.
h3. Global header
In the normal Search template in Movable Type, this header resides inside the @@ container, so it is written out once for every blog. Instead, we put this outside any search result header:
bc.

Search for

h3. The “No results” headers
The first part of the template is for when we have zero results returned, and it will write out a brief explanation and some general suggestions.
To achieve this, the first case in the switch matches when the value of @@ is zero:
bc.

Sorry, but your search for

did not find any documents. Suggestions:

  • Use fewer keywords.
  • Try synonyms.
  • Search in both comments and entries.
  • Check spelling.


h3. Search results header when there are results
If we on the other hand have more than zero results, we write out a different header. The header simply prints the number of results, and starts an ordered list. The Switch block is also terminated:
bc.

Your search returned
results.



    h3. Search results
    The search results themselves are quite simple. Just stick the search result itself inside a list element:
    bc.






h3. End result
The complete end result looks like this:
bc..

Sorry, but your search for

did not find any documents. Suggestions:

  • Use fewer keywords.
  • Try synonyms.
  • Search in both comments and entries.
  • Check spelling.


Your search returned
results.








p. That’s all there is to it, really. Just replace the above snippet with whatever was inside your old @@ and you’ll have a neat, numbered list of search results.

Comments are closed.