Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/okfn/ckan
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Nov 28, 2011
2 parents 4e1fc44 + 05b675a commit de971e8
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ckan/config/schema.xml
Expand Up @@ -131,10 +131,10 @@
<field name="linked_from" type="text" indexed="true" stored="false" multiValued="true"/>
<field name="child_of" type="text" indexed="true" stored="false" multiValued="true"/>
<field name="parent_of" type="text" indexed="true" stored="false" multiValued="true"/>
<field name="extras_*" type="text" indexed="true" stored="false" multiValued="true"/>

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

<dynamicField name="extras_*" type="text" indexed="true" stored="true" multiValued="false"/>
<dynamicField name="*" type="string" indexed="true" stored="false"/>
</fields>

Expand Down
5 changes: 5 additions & 0 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -155,6 +155,11 @@ def package_dictize(pkg, context):
q = select([rel_rev]).where(rel_rev.c.object_package_id == pkg.id)
result = _execute_with_revision(q, rel_rev, context)
result_dict["relationships_as_object"] = obj_list_dictize(result, context)
#isopen
# Get an actual Package object, not a PackageRevision
pkg_object = model.Package.get(pkg.id)
result_dict['isopen'] = pkg_object.isopen if isinstance(pkg_object.isopen,bool) else pkg_object.isopen()

return result_dict

def group_dictize(group, context):
Expand Down
10 changes: 10 additions & 0 deletions ckan/lib/search/query.py
Expand Up @@ -280,6 +280,16 @@ def run(self, query):
self.count = response.get('numFound', 0)
self.results = response.get('docs', [])

# get any extras and add to 'extras' dict
for result in self.results:
extra_keys = filter(lambda x: x.startswith('extras_'), result.keys())
extras = {}
for extra_key in extra_keys:
value = result.pop(extra_key)
extras[extra_key[len('extras_'):]] = value
if extra_keys:
result['extras'] = extras

# 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]
Expand Down
15 changes: 10 additions & 5 deletions ckan/logic/action/get.py
Expand Up @@ -438,8 +438,12 @@ def group_package_show(context, data_dict):
query = query.order_by(model.package_revision_table.c.revision_timestamp.desc())
if limit:
query = query.limit(limit)
pack_rev = query.all()
return _package_list_with_resources(context, pack_rev)

result = []
for pkg_rev in query.all():
result.append(package_dictize(pkg_rev,context))

return result

def tag_show(context, data_dict):
'''Shows tag details'''
Expand All @@ -457,9 +461,11 @@ def tag_show(context, data_dict):
check_access('tag_show',context, data_dict)

tag_dict = tag_dictize(tag,context)

extended_packages = []
for package in tag_dict['packages']:
extended_packages.append(_extend_package_dict(package,context))
pkg = model.Package.get(package['id'])
extended_packages.append(package_dictize(pkg,context))

tag_dict['packages'] = extended_packages

Expand Down Expand Up @@ -682,8 +688,7 @@ def package_search(context, data_dict):
log.warning('package %s in index but not in database' % package)
continue

result_dict = table_dictize(pkg, context)
result_dict = _extend_package_dict(result_dict,context)
result_dict = package_dictize(pkg,context)
results.append(result_dict)

return {
Expand Down
1 change: 1 addition & 0 deletions ckan/model/package.py
Expand Up @@ -192,6 +192,7 @@ def as_dict(self, ref_package_by='name', ref_group_by='name'):
# Set 'license' in _dict to cater for old clients.
# Todo: Remove from Version 2?
_dict['license'] = self.license.title if self.license else _dict.get('license_id', '')
_dict['isopen'] = self.isopen()
tags = [tag.name for tag in self.tags]
tags.sort() # so it is determinable
_dict['tags'] = tags
Expand Down
1 change: 1 addition & 0 deletions ckan/tests/lib/test_dictization.py
Expand Up @@ -43,6 +43,7 @@ def setup_class(cls):
'name': u'roger',
'state': u'active',
'title': u"Roger's books"}],
'isopen': True,
'license_id': u'other-open',
'maintainer': None,
'maintainer_email': None,
Expand Down
19 changes: 9 additions & 10 deletions ckan/tests/lib/test_solr_package_search.py
Expand Up @@ -438,16 +438,15 @@ def test_0_basic(self):
self._do_search(u'bcd', 'b', 1)
self._do_search(u'"cde abc"', 'c', 1)

def test_1_partial_matches(self):
# TODO: solr is not currently set up to allow partial matches
# and extras are not saved as multivalued so these
# tests will fail. Make multivalued or remove these?
from ckan.tests import SkipTest
raise SkipTest

self._do_search(u'abc', ['a', 'c'], 2)
self._do_search(u'cde', 'c', 1)
self._do_search(u'abc cde', 'c', 1)
def test_1_extras_in_all_fields(self):
response = search.query_for(model.Package).run({'q': 'abc', 'fl': '*'})
assert response['count'] == 2

results = response['results']
for result in results:
assert 'extras' in result.keys(), result
assert 'department' in result['extras'], result['extras']
assert result['extras']['department'] in ['abc', 'cde abc'], result['extras']['department']

class TestRank(TestController):
@classmethod
Expand Down
@@ -1,5 +1,4 @@
from pylons import config
from ckan import plugins, model
from ckan import model
import ckan.lib.search as search
from ckan.tests import CreateTestData, setup_test_search_index
from test_solr_package_search import TestSearchOverall
Expand Down

0 comments on commit de971e8

Please sign in to comment.