[ckan-changes] commit/ckan: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Mon Aug 22 16:20:25 UTC 2011
2 new changesets in ckan:
http://bitbucket.org/okfn/ckan/changeset/ce8e3e6aa93b/
changeset: ce8e3e6aa93b
branch: feature-1275-solr-search
user: John Glover
date: 2011-08-22 18:03:04
summary: [solr] Don't need to rebuild the solr search index in test_action, uses Postgres for tag searching.
affected #: 1 file (147 bytes)
--- a/ckan/tests/functional/api/test_action.py Mon Aug 22 16:50:27 2011 +0100
+++ b/ckan/tests/functional/api/test_action.py Mon Aug 22 17:03:04 2011 +0100
@@ -2,8 +2,6 @@
from pprint import pprint, pformat
from nose.tools import assert_equal
-from ckan import plugins
-import ckan.lib.search as search
from ckan.lib.create_test_data import CreateTestData
import ckan.model as model
from ckan.tests import WsgiAppCase
@@ -24,8 +22,6 @@
@classmethod
def setup_class(self):
- search.clear()
- plugins.load('synchronous_search')
CreateTestData.create()
self.sysadmin_user = model.User.get('testsysadmin')
self.normal_user = model.User.get('annafan')
@@ -33,7 +29,6 @@
@classmethod
def teardown_class(self):
model.repo.rebuild_db()
- search.clear()
def test_01_package_list(self):
postparams = '%s=1' % json.dumps({})
http://bitbucket.org/okfn/ckan/changeset/75708a32d1a5/
changeset: 75708a32d1a5
branch: feature-1275-solr-search
user: John Glover
date: 2011-08-22 18:20:06
summary: [solr] Fix resource search (postgres)
affected #: 2 files (197 bytes)
--- a/ckan/lib/search/__init__.py Mon Aug 22 17:03:04 2011 +0100
+++ b/ckan/lib/search/__init__.py Mon Aug 22 17:20:06 2011 +0100
@@ -5,7 +5,7 @@
from ckan.lib.dictization.model_dictize import package_to_api1
from common import SearchError
from index import PackageSearchIndex, NoopSearchIndex
-from query import TagSearchQuery, PackageSearchQuery, QueryOptions
+from query import TagSearchQuery, ResourceSearchQuery, PackageSearchQuery, QueryOptions
log = logging.getLogger(__name__)
@@ -29,6 +29,7 @@
_QUERIES = {
'tag': TagSearchQuery,
+ 'resource': ResourceSearchQuery,
'package': PackageSearchQuery
}
--- a/ckan/lib/search/query.py Mon Aug 22 17:03:04 2011 +0100
+++ b/ckan/lib/search/query.py Mon Aug 22 17:20:06 2011 +0100
@@ -1,3 +1,4 @@
+from sqlalchemy import or_
from pylons import config
from paste.util.multidict import MultiDict
from paste.deploy.converters import asbool
@@ -229,40 +230,39 @@
self._db_query(q)
-# class ResourceSqlSearchQuery(SqlSearchQuery):
-# """ Search for resources in plain SQL. """
+class ResourceSearchQuery(SearchQuery):
+ """ Search for resources in plain SQL. """
+ def _run(self):
+ q = model.Session.query(model.Resource) # TODO authz
+ if self.query.terms:
+ raise SearchError('Only field specific terms allowed in resource search.')
+ self.options.ref_entity_with_attr = 'id' # has no name
+ resource_fields = model.Resource.get_columns()
+ for field, terms in self.query.fields.items():
+ if isinstance(terms, basestring):
+ terms = terms.split()
+ if field not in resource_fields:
+ raise SearchError('Field "%s" not recognised in Resource search.' % field)
+ for term in terms:
+ model_attr = getattr(model.Resource, field)
+ if field == 'hash':
+ q = q.filter(model_attr.ilike(unicode(term) + '%'))
+ elif field in model.Resource.get_extra_columns():
+ model_attr = getattr(model.Resource, 'extras')
-# def _run(self):
-# q = model.Session.query(model.Resource) # TODO authz
-# if self.query.terms:
-# raise SearchError('Only field specific terms allowed in resource search.')
-# #self._check_options_specified_are_allowed('resource search', ['all_fields', 'offset', 'limit'])
-# self.options.ref_entity_with_attr = 'id' # has no name
-# resource_fields = model.Resource.get_columns()
-# for field, terms in self.query.fields.items():
-# if isinstance(terms, basestring):
-# terms = terms.split()
-# if field not in resource_fields:
-# raise SearchError('Field "%s" not recognised in Resource search.' % field)
-# for term in terms:
-# model_attr = getattr(model.Resource, field)
-# if field == 'hash':
-# q = q.filter(model_attr.ilike(unicode(term) + '%'))
-# elif field in model.Resource.get_extra_columns():
-# model_attr = getattr(model.Resource, 'extras')
-
-# like = or_(model_attr.ilike(u'''%%"%s": "%%%s%%",%%''' % (field, term)),
-# model_attr.ilike(u'''%%"%s": "%%%s%%"}''' % (field, term))
-# )
-# q = q.filter(like)
-# else:
-# q = q.filter(model_attr.ilike('%' + unicode(term) + '%'))
+ like = or_(
+ model_attr.ilike(u'''%%"%s": "%%%s%%",%%''' % (field, term)),
+ model_attr.ilike(u'''%%"%s": "%%%s%%"}''' % (field, term))
+ )
+ q = q.filter(like)
+ else:
+ q = q.filter(model_attr.ilike('%' + unicode(term) + '%'))
-# order_by = self.options.order_by
-# if order_by is not None:
-# if hasattr(model.Resource, order_by):
-# q = q.order_by(getattr(model.Resource, order_by))
-# self._db_query(q)
+ order_by = self.options.order_by
+ if order_by is not None:
+ if hasattr(model.Resource, order_by):
+ q = q.order_by(getattr(model.Resource, order_by))
+ self._db_query(q)
class PackageSearchQuery(SearchQuery):
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