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

Bitbucket commits-noreply at bitbucket.org
Tue Sep 27 00:15:09 UTC 2011


3 new changesets in ckan:

http://bitbucket.org/okfn/ckan/changeset/b54956b5c959/
changeset:   b54956b5c959
branch:      feature-1361-simplesearch
user:        rgrp
date:        2011-09-27 01:59:32
summary:     [search][m]: (refs #1361) add support for 'simple' search (crude search using local database, no solr, no fulltext).

* NB: no tests yet (do we need them?)
* lib/search/common.py, lib/search/index.py: ensure we import of use solr stuff when needed for solr
* lib/search/sql.py: new simple search using pure sql
* lib/config/deployment.ini_tmpl: new ckan.simple_search option
* lib/search/__init__.py: check for ckan.simple_search option and if so use sql
affected #:  5 files (-1 bytes)

--- a/ckan/config/deployment.ini_tmpl	Mon Sep 26 17:08:17 2011 +0100
+++ b/ckan/config/deployment.ini_tmpl	Tue Sep 27 00:59:32 2011 +0100
@@ -122,6 +122,11 @@
 ## NOTE this is mutually exclusive with ckan.async_notifier
 ckan.build_search_index_synchronously = true
 
+## Perform search just using database (rather than use e.g. solr).
+## In this setup search is crude and limited .e.g no full-text search, no faceting ...
+## However, very useful for getting up and running quickly with CKAN 
+# ckan.simple_search = 1
+
 ## Title of site (using in several places including templates and <title> tag
 ckan.site_title = CKAN
 


--- a/ckan/lib/search/__init__.py	Mon Sep 26 17:08:17 2011 +0100
+++ b/ckan/lib/search/__init__.py	Tue Sep 27 00:59:32 2011 +0100
@@ -1,4 +1,6 @@
 import logging
+from pylons import config
+
 from ckan import model
 from ckan.model import DomainObjectOperation
 from ckan.plugins import SingletonPlugin, implements, IDomainObjectModification
@@ -9,6 +11,8 @@
 
 log = logging.getLogger(__name__)
 
+SIMPLE_SEARCH = config.get('ckan.simple_search', False)
+
 DEFAULT_OPTIONS = {
     'limit': 20,
     'offset': 0,
@@ -31,6 +35,11 @@
     'package': PackageSearchQuery
 }
 
+if SIMPLE_SEARCH:
+    import sql as sql
+    _INDICES['package'] = NoopSearchIndex
+    _QUERIES['package'] = sql.PackageSearchQuery
+
 def _normalize_type(_type):
     if isinstance(_type, model.DomainObject):
         _type = _type.__class__


--- a/ckan/lib/search/common.py	Mon Sep 26 17:08:17 2011 +0100
+++ b/ckan/lib/search/common.py	Tue Sep 27 00:59:32 2011 +0100
@@ -1,5 +1,4 @@
 from pylons import config
-from solr import SolrConnection
 import logging
 log = logging.getLogger(__name__)
 
@@ -26,6 +25,7 @@
     return True
 
 def make_connection():
+    from solr import SolrConnection
     if solr_user is not None and solr_password is not None:
         return SolrConnection(solr_url, http_user=solr_user, http_pass=solr_password)
     else:


--- a/ckan/lib/search/index.py	Mon Sep 26 17:08:17 2011 +0100
+++ b/ckan/lib/search/index.py	Tue Sep 27 00:59:32 2011 +0100
@@ -4,7 +4,6 @@
 import itertools
 
 from pylons import config
-from solr import SolrException
 
 from common import SearchIndexError, make_connection
 


--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ckan/lib/search/sql.py	Tue Sep 27 00:59:32 2011 +0100
@@ -0,0 +1,40 @@
+from sqlalchemy import or_, and_
+from ckan.lib.search.query import SearchQuery
+import ckan.model as model
+
+class PackageSearchQuery(SearchQuery):
+    def get_all_entity_ids(self, max_results=100):
+        """
+        Return a list of the IDs of all indexed packages.
+        """
+        # could make this a pure sql query which would be much more efficient!
+        q = model.Session.query(model.Package).filter_by(state='active').limit(max_results)
+
+        return [r.id for r in q]
+
+    def run(self, query):
+        assert isinstance(query, dict)
+        # no support for faceting atm
+        self.facets = {}
+        limit = min(1000, int(query.get('rows', 10)))
+        
+        q = query.get('q')
+        ourq = model.Session.query(model.Package.id).filter_by(state='active')
+
+        def makelike(field):
+            _attr = getattr(model.Package, field)
+            return _attr.ilike('%' + term + '%')
+        if q and not (q == '""' or q == "''"):
+            terms = q.split()
+            # TODO: tags ...?
+            fields = ['name', 'title', 'notes']
+            for term in terms:
+                args = [makelike(field) for field in fields]
+                subq = or_(*args)
+                ourq = ourq.filter(subq)
+        self.count = ourq.count()
+        ourq = ourq.limit(limit)
+        self.results = [r[0] for r in ourq.all()]
+
+        return {'results': self.results, 'count': self.count}
+


http://bitbucket.org/okfn/ckan/changeset/073e027dabc4/
changeset:   073e027dabc4
branch:      feature-1361-simplesearch
user:        rgrp
date:        2011-09-27 02:03:38
summary:     [close-branch][xs]: believe this branch is done even though no tests as simple search is a feature just for devs and experimentation.
affected #:  0 files (-1 bytes)

http://bitbucket.org/okfn/ckan/changeset/cb641a5151df/
changeset:   cb641a5151df
user:        rgrp
date:        2011-09-27 02:05:03
summary:     [merge,from-branch][s]: merge completed feature branch for #1361.
affected #:  5 files (-1 bytes)

--- a/ckan/config/deployment.ini_tmpl	Mon Sep 26 17:08:17 2011 +0100
+++ b/ckan/config/deployment.ini_tmpl	Tue Sep 27 01:05:03 2011 +0100
@@ -122,6 +122,11 @@
 ## NOTE this is mutually exclusive with ckan.async_notifier
 ckan.build_search_index_synchronously = true
 
+## Perform search just using database (rather than use e.g. solr).
+## In this setup search is crude and limited .e.g no full-text search, no faceting ...
+## However, very useful for getting up and running quickly with CKAN 
+# ckan.simple_search = 1
+
 ## Title of site (using in several places including templates and <title> tag
 ckan.site_title = CKAN
 


--- a/ckan/lib/search/__init__.py	Mon Sep 26 17:08:17 2011 +0100
+++ b/ckan/lib/search/__init__.py	Tue Sep 27 01:05:03 2011 +0100
@@ -1,4 +1,6 @@
 import logging
+from pylons import config
+
 from ckan import model
 from ckan.model import DomainObjectOperation
 from ckan.plugins import SingletonPlugin, implements, IDomainObjectModification
@@ -9,6 +11,8 @@
 
 log = logging.getLogger(__name__)
 
+SIMPLE_SEARCH = config.get('ckan.simple_search', False)
+
 DEFAULT_OPTIONS = {
     'limit': 20,
     'offset': 0,
@@ -31,6 +35,11 @@
     'package': PackageSearchQuery
 }
 
+if SIMPLE_SEARCH:
+    import sql as sql
+    _INDICES['package'] = NoopSearchIndex
+    _QUERIES['package'] = sql.PackageSearchQuery
+
 def _normalize_type(_type):
     if isinstance(_type, model.DomainObject):
         _type = _type.__class__


--- a/ckan/lib/search/common.py	Mon Sep 26 17:08:17 2011 +0100
+++ b/ckan/lib/search/common.py	Tue Sep 27 01:05:03 2011 +0100
@@ -1,5 +1,4 @@
 from pylons import config
-from solr import SolrConnection
 import logging
 log = logging.getLogger(__name__)
 
@@ -26,6 +25,7 @@
     return True
 
 def make_connection():
+    from solr import SolrConnection
     if solr_user is not None and solr_password is not None:
         return SolrConnection(solr_url, http_user=solr_user, http_pass=solr_password)
     else:


--- a/ckan/lib/search/index.py	Mon Sep 26 17:08:17 2011 +0100
+++ b/ckan/lib/search/index.py	Tue Sep 27 01:05:03 2011 +0100
@@ -4,7 +4,6 @@
 import itertools
 
 from pylons import config
-from solr import SolrException
 
 from common import SearchIndexError, make_connection
 


--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ckan/lib/search/sql.py	Tue Sep 27 01:05:03 2011 +0100
@@ -0,0 +1,40 @@
+from sqlalchemy import or_, and_
+from ckan.lib.search.query import SearchQuery
+import ckan.model as model
+
+class PackageSearchQuery(SearchQuery):
+    def get_all_entity_ids(self, max_results=100):
+        """
+        Return a list of the IDs of all indexed packages.
+        """
+        # could make this a pure sql query which would be much more efficient!
+        q = model.Session.query(model.Package).filter_by(state='active').limit(max_results)
+
+        return [r.id for r in q]
+
+    def run(self, query):
+        assert isinstance(query, dict)
+        # no support for faceting atm
+        self.facets = {}
+        limit = min(1000, int(query.get('rows', 10)))
+        
+        q = query.get('q')
+        ourq = model.Session.query(model.Package.id).filter_by(state='active')
+
+        def makelike(field):
+            _attr = getattr(model.Package, field)
+            return _attr.ilike('%' + term + '%')
+        if q and not (q == '""' or q == "''"):
+            terms = q.split()
+            # TODO: tags ...?
+            fields = ['name', 'title', 'notes']
+            for term in terms:
+                args = [makelike(field) for field in fields]
+                subq = or_(*args)
+                ourq = ourq.filter(subq)
+        self.count = ourq.count()
+        ourq = ourq.limit(limit)
+        self.results = [r[0] for r in ourq.all()]
+
+        return {'results': self.results, 'count': self.count}
+

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