Skip to content

Commit

Permalink
Merge branch 'master' into feature-1821-multilingual-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Feb 23, 2012
2 parents c6b4192 + 3f7e5f0 commit f7d2964
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 22 deletions.
4 changes: 3 additions & 1 deletion ckan/controllers/package.py
Expand Up @@ -239,12 +239,13 @@ def pager_url(q=None, page=None):
try:
c.fields = []
search_extras = {}
fq = ''
for (param, value) in request.params.items():
if not param in ['q', 'page'] \
and len(value) and not param.startswith('_'):
if not param.startswith('ext_'):
c.fields.append((param, value))
q += ' %s: "%s"' % (param, value)
fq += ' %s:"%s"' % (param, value)
else:
search_extras[param] = value

Expand All @@ -253,6 +254,7 @@ def pager_url(q=None, page=None):

data_dict = {
'q':q,
'fq':fq,
'facet.field':g.facets,
'rows':limit,
'start':(page-1)*limit,
Expand Down
6 changes: 6 additions & 0 deletions ckan/lib/activity.py
Expand Up @@ -92,6 +92,12 @@ def before_commit(self, session):
objects = object_cache[activity_type]
for obj in objects:
logger.debug("Looking at %s object %s" % (activity_type, obj))

if not hasattr(obj,"id"):
logger.debug("Object has no id, skipping...")
continue


if activity_type == "new" and obj.id in activities:
logger.debug("This object was already logged as a new "
"package")
Expand Down
3 changes: 2 additions & 1 deletion ckan/lib/i18n.py
Expand Up @@ -89,7 +89,8 @@ def get_available_locales():

def handle_request(request, tmpl_context):
''' Set the language for the request '''
lang = request.environ.get('CKAN_LANG', config['ckan.locale_default'])
lang = request.environ.get('CKAN_LANG',
config.get('ckan.locale_default', 'en'))
if lang != 'en':
i18n.set_lang(lang)
tmpl_context.language = lang
Expand Down
13 changes: 6 additions & 7 deletions ckan/lib/search/query.py
Expand Up @@ -282,13 +282,12 @@ def run(self, query):
# return results as json encoded string
query['wt'] = query.get('wt', 'json')

# query field weighting: disabled for now as solr 3.* is required for
# the 'edismax' query parser, our current Ubuntu version only has
# packages for 1.4
#
# query['defType'] = 'edismax'
# query['tie'] = '0.5'
# query['qf'] = query.get('qf', QUERY_FIELDS)
# If the query has a colon in it then consider it a fielded search and do use dismax.
if ':' not in query['q']:
query['defType'] = 'dismax'
query['tie'] = '0.1'
query['mm'] = '1'
query['qf'] = query.get('qf', QUERY_FIELDS)

conn = make_connection()
log.debug('Package query: %r' % query)
Expand Down
10 changes: 10 additions & 0 deletions ckan/logic/schema.py
Expand Up @@ -188,6 +188,16 @@ def default_group_schema():
'packages': {
"id": [not_empty, unicode, package_id_or_name_exists],
"__extras": [ignore]
},
'users': {
"name": [not_empty, unicode],
"capacity": [ignore_missing],
"__extras": [ignore]
},
'groups': {
"name": [not_empty, unicode],
"capacity": [ignore_missing],
"__extras": [ignore]
}
}
return schema
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/js_strings.html
Expand Up @@ -22,7 +22,7 @@
CKAN.Strings.failedToSave = "${_('Failed to save, possibly due to invalid data ')}";
CKAN.Strings.addDataset = "${_('Add Dataset')}";
CKAN.Strings.addGroup = "${_('Add Group')}";
CKAN.Strings.youHaveUnsavedChanges = "${_("You have unsaved changed. Make sure to click 'Save Changes' below before leaving this page.")}";
CKAN.Strings.youHaveUnsavedChanges = "${_("You have unsaved changes. Make sure to click 'Save Changes' below before leaving this page.")}";
CKAN.Strings.loading = "${_('Loading...')}";
CKAN.Strings.noNameBrackets = "${_('(no name)')}";
CKAN.Strings.deleteThisResourceQuestion = "${_('Delete the resource \'%name%\'?')}"
Expand Down
14 changes: 7 additions & 7 deletions ckan/templates/user/read.html
Expand Up @@ -21,6 +21,13 @@
<dl class="vcard">
<dt>Name</dt>
<dd>${c.user_dict['fullname'] or 'No name provided'}</dd>
<dt>Member since</dt>
<dd>${h.render_datetime(c.user_dict['created'])}</dd>
<py:if test="unicode(c.about_formatted)">
<dt>About</dt>
<dd>${c.about_formatted}</dd>
</py:if>
<py:if test="c.is_myself">
<dt>Email</dt>
<dd>
<py:if test="c.user_dict['email']">
Expand All @@ -30,13 +37,6 @@
No email
</py:if>
</dd>
<dt>Member since</dt>
<dd>${h.render_datetime(c.user_dict['created'])}</dd>
<py:if test="unicode(c.about_formatted)">
<dt>About</dt>
<dd>${c.about_formatted}</dd>
</py:if>
<py:if test="c.is_myself">
<!--checkpoint:is-myself-->
<dt>API Key</dt>
<dd>
Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/functional/test_search.py
Expand Up @@ -67,7 +67,7 @@ def test_2_title(self):

# multiple words
res = self.app.get('/dataset?q=Government%20Expenditure')
result = self._check_results(res, 1, 'uk-government-expenditure')
result = self._check_results(res, 5, 'uk-government-expenditure')

class TestSearch2(FunctionalTestCase, PylonsTestCase):#, TestPackageForm):

Expand Down
13 changes: 9 additions & 4 deletions ckan/tests/lib/test_solr_package_search.py
Expand Up @@ -92,13 +92,17 @@ def test_2_title(self):
assert self._pkg_names(result) == 'se-opengov', self._pkg_names(result)
# multiple words
result = search.query_for(model.Package).run({'q': u'Government Expenditure'})
assert self._pkg_names(result) == 'uk-government-expenditure', self._pkg_names(result)
# uk-government-expenditure is the best match but all other results should be retured
assert self._pkg_names(result).startswith('uk-government-expenditure'), self._pkg_names(result)
# se-opengov has only government in tags, all others hav it in title.
assert self._pkg_names(result).endswith('se-opengov'), self._pkg_names(result)
# multiple words wrong order
result = search.query_for(model.Package).run({'q': u'Expenditure Government'})
assert self._pkg_names(result) == 'uk-government-expenditure', self._pkg_names(result)
# multiple words, one doesn't match
assert self._pkg_names(result).startswith('uk-government-expenditure'), self._pkg_names(result)
assert self._pkg_names(result).endswith('se-opengov'), self._pkg_names(result)
# multiple words all should match government
result = search.query_for(model.Package).run({'q': u'Expenditure Government China'})
assert len(result['results']) == 0, self._pkg_names(result)
assert len(result['results']) == 5, self._pkg_names(result)

def test_3_licence(self):
# this should result, but it is here to check that at least it does not error
Expand Down Expand Up @@ -315,6 +319,7 @@ def test_overall(self):
check_search_results('annakarenina', 1, ['annakarenina'])
check_search_results('warandpeace', 1, ['warandpeace'])
check_search_results('', 2)

check_search_results('A Novel By Tolstoy', 1, ['annakarenina'])
check_search_results('title:Novel', 1, ['annakarenina'])
check_search_results('title:peace', 0)
Expand Down

0 comments on commit f7d2964

Please sign in to comment.