[ckan-changes] commit/ckan: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Wed Aug 31 14:16:10 UTC 2011


2 new changesets in ckan:

http://bitbucket.org/okfn/ckan/changeset/28ba84c03641/
changeset:   28ba84c03641
branch:      feature-1275-solr-search
user:        John Glover
date:        2011-08-31 15:50:39
summary:     [solr] [1277] Bug fix: return package IDs if using API v2
affected #:  2 files (237 bytes)

--- a/ckan/controllers/api.py	Wed Aug 31 14:22:23 2011 +0100
+++ b/ckan/controllers/api.py	Wed Aug 31 14:50:39 2011 +0100
@@ -403,6 +403,11 @@
                 return self._finish_bad_request(
                     gettext('Could not read parameters: %r' % e))
 
+            # if using API v2, default to returning the package ID if
+            # no field list is specified
+            if register == 'package' and not params.get('fl'):
+                params['fl'] = 'id' if ver == '2' else 'name'
+
             try:
                 if register == 'resource': 
                     query = query_for(model.Resource)


--- a/ckan/lib/search/query.py	Wed Aug 31 14:22:23 2011 +0100
+++ b/ckan/lib/search/query.py	Wed Aug 31 14:50:39 2011 +0100
@@ -338,10 +338,9 @@
             self.count = response.get('numFound', 0)
             self.results = response.get('docs', [])
 
-            # if just fetching the name, return a list of names instead
-            # of a dict
-            if query.get('fl') == 'name':
-                self.results = [r.get('name') for r in self.results]
+            # if just fetching the id or name, return a list instead of a dict
+            if query.get('fl') in ['id', 'name']:
+                self.results = [r.get(query.get('fl')) for r in self.results]
 
             self.facets = data['facet_counts'].get('facet_fields', {})
         except Exception, e:


http://bitbucket.org/okfn/ckan/changeset/67f8be61bcf1/
changeset:   67f8be61bcf1
branch:      feature-1275-solr-search
user:        John Glover
date:        2011-08-31 16:15:54
summary:     [solr] [1277] Bug fix: ckan query parser still needed for resource search
affected #:  1 file (1.2 KB)

--- a/ckan/controllers/api.py	Wed Aug 31 14:50:39 2011 +0100
+++ b/ckan/controllers/api.py	Wed Aug 31 15:15:54 2011 +0100
@@ -411,9 +411,35 @@
             try:
                 if register == 'resource': 
                     query = query_for(model.Resource)
+
+                    # resource search still uses ckan query parser
+                    options = QueryOptions()
+                    for k, v in params.items():
+                        if (k in DEFAULT_OPTIONS.keys()):
+                            options[k] = v
+                    options.update(params)
+                    options.username = c.user
+                    options.search_tags = False
+                    options.return_objects = False
+                    query_fields = MultiDict()
+                    for field, value in params.items():
+                        field = field.strip()
+                        if field in DEFAULT_OPTIONS.keys() or \
+                           field in IGNORE_FIELDS:
+                            continue
+                        values = [value]
+                        if isinstance(value, list):
+                            values = value
+                        for v in values:
+                            query_fields.add(field, v)
+
+                    results = query.run(
+                        query=params.get('q'), fields=query_fields, options=options
+                    )
                 else:
+                    # for package searches we can pass parameters straight to Solr
                     query = query_for(model.Package)
-                results = query.run(params)
+                    results = query.run(params)
                 return self._finish_ok(results)
             except SearchError, e:
                 log.exception(e)

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list