pbauer

Custom search forms for plone-sites

Sites with a lot of content profit hugely from custom searches. Until recently adding a custom search to a Plone-Site was cumbersome and nothing your average editor or site-admin could do.

Ever since Ross Patterson wrote collective.formcriteria all will be well.

Stop writing search forms for each and every special case by hand and start thinking of search-forms as content just like collections are custom search-results as content. Ross saved us a lot of hassle by extending these almost all-powerfull collections to create custom forms searching through the collections content. And as added value displaying the results in a much nicer and more useful way than the default search.  

Say, you want a searchfield in your site only to search through the press-releases of all your departments.

  • First add collective.formcriteria to your buildout and install it via quickinstaller.
  • Create a new collection "Press-Releases".
  • Select "summary view" as Form Results Layout in the edit-tab of your collection (thus giving you the added value of preview-images being shown if the searchable content type has a image-field, e.g. news-items).
  • Edit the collections criteria and add the contenttype "News Item" (or the folder where you put the press-releases if you don't use a special contenttype) as a criterion.
  • Use "relevance" to sort the results.
  • Add "Searchable text" as criterion without entering a text (if you choose to enter something it'll populate the search-field as default-value) and select this field to show as "Form Fields".

Your new collection now shows you all your news items. Yawn! But when you switch the display to "Search form" the content of your collection disappears and a new search field is shown. Nice!

I prefer search-forms in portlets: Create a "Search form portlet", connect it to your collection. Voilá: custom search - whereever you want it. And that was a only an easy example.

More goodness in the most recent version include:

  • The "Content"-tab now works just like with a folder, meaning you can use content-actions like copy, rename, change state and such for your search results even if they are in different folders. With that collective.formcriteria outperforms the default search in almost every aspect.
  • The new "export"-Action allows you to save the results to CSV. You can specify the used columns via in the collection's "Table Columns" fields.

For custom searches using operators such as OR or NOT you still need to write your own search-forms using AdvancedQuery (and possibly anthill.querytool). But an implementation of these operators using subcollections is already on the ToDo-List.

Get it here: http://pypi.python.org/pypi/collective.formcriteria/