Facetted searches
-----------------

This tests the integration of Solr's facetted searches into Plone.  We'll
use a testbrowser to check the correct display of facets.  First we need to
activate Solr support and reindex the site's content:

  >>> self.folder.setTitle('My folder')
  >>> self.activateAndReindex()

The search form should contain default settings for facets to be shown:

  >>> self.setRoles(('Manager',))
  >>> browser = self.getBrowser()
  >>> browser.open('http://nohost/plone/')
  >>> browser.contents
  '...<input type="hidden" name="facet.field"...value="portal_type" />...'

Without search results there's also no information about facets, of course:

  >>> browser.getControl('Search Site').value = 'foo'
  >>> browser.getForm(name='searchform').submit()
  >>> browser.url
  'http://nohost/plone/search?...&facet.field=portal_type...'
  >>> browser.contents
  '...Search results...
   ...No results were found...'
  >>> 'searchfacets' in browser.contents
  False

Let's try again with some results:

  >>> browser.goBack()
  >>> browser.getControl('Search Site').value = 'news'
  >>> browser.getForm(name='searchform').submit()
  >>> browser.url
  'http://nohost/plone/search?...&facet.field=portal_type...'
  >>> browser.contents
  '...Search results...2 items matching...
   ...portal-searchfacets...
   ...Content type...
   ...Folder...1...
   ...Collection...1...
   ...Site News...'

In fact, information for multiple facets should be displayed:

  >>> browser.goBack()
  >>> browser.getControl('Search Site').value = 'news'
  >>> browser.getForm(name='searchform').submit()
  >>> browser.url
  'http://nohost/plone/search?...&facet.field=portal_type...&facet.field=review_state...'
  >>> browser.contents
  '...Search results...2 items matching...
   ...portal-searchfacets...
   ...Content type...
   ...Folder...1...
   ...Collection...1...
   ...Review state...
   ...published...2...
   ...Site News...'

Clicking on of the facets should restrict the search:

  >>> browser.getLink('Collection').click()
  >>> browser.url
  'http://nohost/plone/search?...&fq=portal_type%3A%22Collection%22...'
  >>> 'facet.field=portal_type' in browser.url
  False
  >>> browser.contents
  '...Search results...1 items matching...
   ...portal-searchfacets...
   ...Content type...Collection...&otimes;...
   ...Review state...
   ...published...1...
   ...Site News...'

There should be a link to remove the selected facet, but no other details:

  >>> browser.getLink('⊗').url
  'http://nohost/plone/search?...&facet.field=portal_type...'
  >>> 'Folder' in browser.contents
  False

But the other facet should still be browsable:

  >>> browser.getLink('published').click()
  >>> browser.url
  'http://nohost/plone/search?...fq=portal_type%3A%22Collection%22...fq=review_state%3A%22published%22...'
  >>> 'facet.field=' in browser.url
  False
  >>> browser.contents
  '...Search results...1 items matching...
   ...portal-searchfacets...
   ...Content type...Collection...&otimes;...
   ...Review state...published...&otimes;...
   ...Site News...'

Removing a previously selected facet should extend the search again:

  >>> browser.getLink('⊗').click()
  >>> browser.url
  'http://nohost/plone/search?...&facet.field=portal_type...'
  >>> 'fq=portal_type' in browser.url
  False
  >>> 'fq=review_state' in browser.url
  True
  >>> browser.contents
  '...Search results...2 items matching...
   ...portal-searchfacets...
   ...Review state...published...&otimes;...
   ...Content type...
   ...Folder...1...
   ...Collection...1...
   ...Site News...'

Using the search boxes, both the standard one as well as the other, which is
embedded into the results page, should provide facet information and preserve
the already selected facets:

  >>> browser.getForm(name='searchform', index=0).submit()
  >>> browser.contents
  '...Search results...2 items matching...
   ...portal-searchfacets...
   ...Review state...published...&otimes;...
   ...Content type...
   ...Folder...1...
   ...Collection...1...
   ...Site News...'

  >>> browser.getForm(name='searchform', index=1).submit()
  >>> browser.contents
  '...Search results...2 items matching...
   ...portal-searchfacets...
   ...Review state...published...&otimes;...
   ...Content type...
   ...Folder...1...
   ...Collection...1...
   ...Site News...'

The already selected facets should of course be displayed in case there were
no search results, so the filters can be removed by the user.  So while at
first no results will be shown, they should appear after removing the facet
selection for "review_state":

  >>> form = browser.getForm(name='searchform', index=0)
  >>> form.getControl('Search Site').value = 'my'
  >>> form.submit()
  >>> browser.contents
  '...No results were found...'
  >>> browser.getLink('⊗').click()
  >>> browser.contents
  '...Search results...1 items matching...
   ...My folder...'
