Skip to content
This repository has been archived by the owner on Nov 26, 2019. It is now read-only.

Commit

Permalink
Merge pull request #14 from NaturalHistoryMuseum/ckanpackager_duplicates
Browse files Browse the repository at this point in the history
Allow the use of cursors in Solr searches
  • Loading branch information
jrdh authored Feb 28, 2018
2 parents 59075ff + 4b1f348 commit 6c647a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions ckanext/datasolr/lib/solr_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,14 @@ def fetch(self):
fields=fields,
total=total,
records=search.results,
# indicates that this response came from Solr, this is used by the ckanpackager
_backend='datasolr',
)

# if there is a next cursor mark in the Solr response, pass it on
if hasattr(search, 'nextCursorMark'):
response['next_cursor'] = search.nextCursorMark

requested_fields = [f['id'] for f in fields]
# Date fields are returned as python datetime objects
# So need to be converted into a string
Expand Down Expand Up @@ -161,6 +167,10 @@ def build_query(params, field_names):
solr_params['group'] = 'true'
solr_params['group_field'] = fields
solr_params['group_main'] = 'true'
# add cursor
cursor = params.get('cursor', None)
if cursor:
solr_params['cursorMark'] = cursor

# Add facets
facets = params.get('facets', [])
Expand Down
5 changes: 3 additions & 2 deletions ckanext/datasolr/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ def datasolr_search(self, context, data_dict, fields, query_dict):
facets_field_limit=data_dict.get('facets_field_limit'),
limit=data_dict.get('limit', 100),
sort=data_dict.get('sort'),
distinct=data_dict.get('distinct', False)
distinct=data_dict.get('distinct', False),
cursor=data_dict.get('cursor', None),
)
query_params['fields'] = data_dict.get('fields', [f['id'] for f in fields])
cursor = data_dict.get('cursor', None)
if cursor:
# Must be sorted on primary key
# TODO: We could get the primary field from the solr schema lookup
query_params['sort'] = [('_id', 'ASC')]
query_params['sort'] = '_id'
else:
# If we've specified a paging cursor, then we don't want to use the offset
query_params['offset'] = data_dict.get('offset', 0)
Expand Down

0 comments on commit 6c647a6

Please sign in to comment.