[ckan-changes] [okfn/ckan] 9c3b06: add views to search index

GitHub noreply at github.com
Fri Apr 13 09:23:02 UTC 2012


  Branch: refs/heads/enhancement-2251-tracking
  Home:   https://github.com/okfn/ckan
  Commit: 9c3b064e76ccae89eeedfff8dbeec86bcfb0a4c4
      https://github.com/okfn/ckan/commit/9c3b064e76ccae89eeedfff8dbeec86bcfb0a4c4
  Author: Toby <toby.junk at gmail.com>
  Date:   2012-04-13 (Fri, 13 Apr 2012)

  Changed paths:
    M ckan/config/solr/schema-1.3.xml
    M ckan/lib/helpers_clean.py
    M ckan/lib/search/index.py

  Log Message:
  -----------
  add views to search index


diff --git a/ckan/config/solr/schema-1.3.xml b/ckan/config/solr/schema-1.3.xml
index 21cf3d7..5a65a71 100644
--- a/ckan/config/solr/schema-1.3.xml
+++ b/ckan/config/solr/schema-1.3.xml
@@ -132,6 +132,7 @@
     <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="views" type="int" indexed="true" stored="false"/>
 
     <field name="metadata_created" type="date" indexed="true" stored="true" multiValued="false"/>
     <field name="metadata_modified" type="date" indexed="true" stored="true" multiValued="false"/>
diff --git a/ckan/lib/helpers_clean.py b/ckan/lib/helpers_clean.py
index 07ff864..476e098 100644
--- a/ckan/lib/helpers_clean.py
+++ b/ckan/lib/helpers_clean.py
@@ -58,6 +58,8 @@
            group_link,
            dump_json,
            auto_log_message,
+           tracking_count_package,
+           tracking_count_resource,
     # imported into ckan.lib.helpers
            literal,
            link_to,
diff --git a/ckan/lib/search/index.py b/ckan/lib/search/index.py
index 2599115..4768dcd 100644
--- a/ckan/lib/search/index.py
+++ b/ckan/lib/search/index.py
@@ -132,6 +132,18 @@ def index_package(self, pkg_dict):
 
         pkg_dict['groups'] = [group['name'] for group in groups]
 
+        # views
+        import ckan.model as model
+        sql = '''SELECT running_total
+                 FROM tracking_summary
+                 WHERE package_id='%s'
+                 ORDER BY date DESC LIMIT 1''' % pkg_dict['id']
+        result = model.Session.execute(sql).fetchall()
+        if result:
+            pkg_dict['views'] = result[0]['running_total']
+        else:
+            pkg_dict['views'] = 0
+
         # flatten the structure for indexing:
         for resource in pkg_dict.get('resources', []):
             for (okey, nkey) in [('description', 'res_description'),


================================================================



More information about the ckan-changes mailing list