Skip to content

Commit

Permalink
Merge branch 'release-v1.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Murray committed Mar 15, 2012
2 parents 20e63d0 + 226ac14 commit 1cfaa3a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ckan/config/solr/schema-1.3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@

<field name="indexed_ts" type="date" indexed="true" stored="true" default="NOW" multiValued="false"/>

<!-- Copy the title field into titleString, and treat as a string
(rather than text type). This allows us to sort on the titleString -->
<field name="titleString" type="string" indexed="true" stored="false" />
<copyField source="title" dest="titleString"/>

<dynamicField name="extras_*" type="text" indexed="true" stored="true" multiValued="false"/>
<dynamicField name="*" type="string" indexed="true" stored="false"/>
</fields>
Expand Down
27 changes: 26 additions & 1 deletion ckan/controllers/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,30 @@ def remove_field(key, value):

c.remove_field = remove_field

sort_by = request.params.get('sort', None)
params_nosort = [(k, v) for k,v in params_nopage if k != 'sort']
def _sort_by(fields):
"""
Sort by the given list of fields.
Each entry in the list is a 2-tuple: (fieldname, sort_order)
eg - [('metadata_modified', 'desc'), ('name', 'asc')]
If fields is empty, then the default ordering is used.
"""
params = params_nosort[:]

if fields:
sort_string = ', '.join( '%s %s' % f for f in fields )
params.append(('sort', sort_string))
return search_url(params)
c.sort_by = _sort_by
if sort_by is None:
c.sort_by_fields = []
else:
c.sort_by_fields = [ field.split()[0] for field in sort_by.split(',') ]

def pager_url(q=None, page=None):
params = list(params_nopage)
params.append(('page', page))
Expand All @@ -129,7 +153,7 @@ def pager_url(q=None, page=None):
search_extras = {}
fq = ''
for (param, value) in request.params.items():
if not param in ['q', 'page'] \
if param not in ['q', 'page', 'sort'] \
and len(value) and not param.startswith('_'):
if not param.startswith('ext_'):
c.fields.append((param, value))
Expand All @@ -146,6 +170,7 @@ def pager_url(q=None, page=None):
'facet.field':g.facets,
'rows':limit,
'start':(page-1)*limit,
'sort': sort_by,
'extras':search_extras
}

Expand Down

0 comments on commit 1cfaa3a

Please sign in to comment.