Skip to content

Commit

Permalink
Added options to change default search order
Browse files Browse the repository at this point in the history
  • Loading branch information
rodfersou committed Sep 12, 2016
1 parent 51a6c0d commit f6f88a5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Breaking changes:

New features:

- *add item here*
- Added options to change default search order.
[rodfersou]

Bug fixes:

Expand Down
22 changes: 22 additions & 0 deletions plone/app/controlpanel/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@

AnonAuthVocabulary = SimpleVocabulary(anon_auth_terms)

SortSearchResultsVocabulary = SimpleVocabulary(
[SimpleTerm(value=u'relevance', title=_(u'relevance')),
SimpleTerm(value=u'Date', title=_(u'date (newest first)')),
SimpleTerm(value=u'sortable_title', title=_(u'alphabetically'))])


class IBaseSearchSchema(Interface):

enable_livesearch = Bool(
Expand All @@ -50,6 +56,14 @@ class IBaseSearchSchema(Interface):
vocabulary="plone.app.vocabularies.ReallyUserFriendlyTypes")
)

sort_on = Choice(
title=_(u'label_sort_on', default=u'Sort on'),
description=_(u'Sort the default search on this index'),
vocabulary=SortSearchResultsVocabulary,
default=u'relevance',
required=True
)


class ISearchSchema(IBaseSearchSchema):
''' Base search form options '''
Expand Down Expand Up @@ -97,6 +111,14 @@ def set_types_not_searched(self, value):
types_not_searched = property(get_types_not_searched,
set_types_not_searched)

@property
def sort_on(self):
return self.context.sort_on

@sort_on.setter
def sort_on(self, value):
self.context._updateProperty('sort_on', value)


searchset = FormFieldsets(IBaseSearchSchema)
searchset.id = 'search'
Expand Down
4 changes: 4 additions & 0 deletions plone/app/controlpanel/tests/search.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Make some changes
>>> self.browser.getControl(name='form.enable_livesearch').value = False
>>> self.browser.getControl(name='form.types_not_searched').value = \
... ['Event', 'Document']
>>> self.browser.getControl(name='form.sort_on').value = ['Date']


Click the save button:
Expand Down Expand Up @@ -76,6 +77,9 @@ Make sure the changes have been applied correctly to the tool:
>>> 'File' in self.site_props.types_not_searched
True

>>> self.site_props.sort_on
u'Date'

So called 'bad types' are not listed in the search panel, but they
should still be listed in the site_properties as not searchable:

Expand Down

0 comments on commit f6f88a5

Please sign in to comment.