[ckan-changes] commit/ckan: John Glover: [solr] Make search-index check paster command work with solr

Bitbucket commits-noreply at bitbucket.org
Thu Aug 25 15:43:54 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/e3e599fb3277/
changeset:   e3e599fb3277
branch:      feature-1275-solr-search
user:        John Glover
date:        2011-08-25 17:43:51
summary:     [solr] Make search-index check paster command work with solr
affected #:  2 files (639 bytes)

--- a/ckan/lib/search/__init__.py	Thu Aug 25 15:58:30 2011 +0100
+++ b/ckan/lib/search/__init__.py	Thu Aug 25 16:43:51 2011 +0100
@@ -104,12 +104,12 @@
 
 def check():
     from ckan import model
-    package_index = index_for(model.Package)
+    package_query = query_for(model.Package)
 
     log.debug("Checking packages search index...")
     pkgs_q = model.Session.query(model.Package).filter_by(state=model.State.ACTIVE)
     pkgs = set([pkg.id for pkg in pkgs_q])
-    indexed_pkgs = set(package_index.get_all_entity_ids())
+    indexed_pkgs = set(package_query.get_all_entity_ids(max_results=len(pkgs)))
     pkgs_not_indexed = pkgs - indexed_pkgs
     print 'Packages not indexed = %i out of %i' % (len(pkgs_not_indexed), len(pkgs))
     for pkg_id in pkgs_not_indexed:


--- a/ckan/lib/search/query.py	Thu Aug 25 15:58:30 2011 +0100
+++ b/ckan/lib/search/query.py	Thu Aug 25 16:43:51 2011 +0100
@@ -165,6 +165,12 @@
             else:
                 attr_name = self.options.ref_entity_with_attr
                 self.results = [getattr(entity, attr_name) for entity in self.results]
+
+    def get_all_entity_ids(self, max_results=1000):
+        """
+        Return a list of the IDs of all indexed packages.
+        """
+        return []
     
     def run(self, query=None, terms=[], fields={}, facet_by=[], options=None, **kwargs):
         if options is None:
@@ -266,6 +272,22 @@
 
 
 class PackageSearchQuery(SearchQuery):
+    def get_all_entity_ids(self, max_results=1000):
+        """
+        Return a list of the IDs of all indexed packages.
+        """
+        query = "*:*"
+        fq = "+site_id:\"%s\" " % config.get('ckan.site_id')
+        fq += "+state:active "
+
+        conn = make_connection()
+        try:
+            data = conn.query(query, fq=fq, rows=max_results, fields='id')
+        finally:
+            conn.close()
+
+        return [r.get('id') for r in data.results]
+
     def _run(self):
         fq = ""

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