Site Search
-----------

This tests the Solr-based replacement for Plone's site search feature.  We'll
use a testbrowser to created an object and then search for it.  First we need
to activate Solr support and reindex the site's content, though:

  >>> self.activateAndReindex()

  >>> self.setRoles(('Manager',))
  >>> browser = self.getBrowser()
  >>> browser.open('http://nohost/plone/')
  >>> browser.getLink('Page').click()
  >>> browser.getControl('Title').value = 'Foo'
  >>> browser.getControl('Save').click()
  >>> browser.url
  'http://nohost/plone/foo'
  >>> browser.contents
  '...Info...Changes saved...
   ...Foo...This item does not have any body text...'

  >>> browser.getControl('Search Site').value = 'Foo'
  >>> browser.getForm(name='searchform').submit()
  >>> browser.contents
  '...Search results...1...items matching your search terms...
   ...http://nohost/plone/foo...Foo...'
  >>> browser.getLink('Foo')
  <Link text='Foo' url='http://nohost/plone/foo'>

Some content items, for example files and image, don't have an associated
workflow state.  Hence they cannot provide data for a `review_state` index
as well.  However, Plone's search results listing template (`search.pt`)
contains the string expression "state-${result/review_state}", and the TAL
engine will attempt to traverse `result` in case dictionary and attribute
lookups for `review_state` weren't successful.  Let's make sure this
behaviour won't break things:

  >>> portal.invokeFactory('File', id='file', title='my first file')
  'file'
  >>> browser.open('http://nohost/plone/')
  >>> browser.getControl('Search Site').value = 'my first file'
  >>> browser.getForm(name='searchform').submit()
  >>> browser.contents
  '...Search results...1...items matching your search terms...
   ...http://nohost/plone/file...my first file...'


404 Responses
-------------

We also test that searching for suggestions when a page hasn't been found,
a.k.a. a 404 response, still works:

  >>> browser.handleErrors = False    # this is not debug code in this case...
  >>> browser.open('http://nohost/plone/welcome')
  Traceback (most recent call last):
  ...
  NotFound: ...
    ...We're sorry, but that page doesn't exist...
    ...You might have been looking for...
    ...href="http://nohost/plone/"...Plone site...
    ...href="http://nohost/plone/front-page/"...Welcome to Plone...

Suggestions are searched for using parts of the non-existent url, starting
from the end.  If the search doesn't yield any results, the next part is
considered and so on, until at the end, an empty string is passed in as the
search term.  This however breaks searching with Solr and needs to be fixed.
An easy way to make sure no results are ever returned is to clear the index:

  >>> maintenance = portal.unrestrictedTraverse('@@solr-maintenance')
  >>> maintenance.clear()
  'solr index cleared.'
  >>> browser.open('http://nohost/plone/welcome')
  Traceback (most recent call last):
  ...
  NotFound: ...
    ...We're sorry, but that page doesn't exist...
    ...You might have been looking for...

