Skip to content

Commit

Permalink
[2402] search result speedup
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed May 18, 2012
1 parent 5cc6143 commit efbf1dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions ckan/lib/search/index.py
Expand Up @@ -98,6 +98,7 @@ def update_dict(self, pkg_dict):
def index_package(self, pkg_dict):
if pkg_dict is None:
return
pkg_dict['data_dict'] = json.dumps(pkg_dict)

# add to string field for sorting
title = pkg_dict.get('title')
Expand Down
17 changes: 13 additions & 4 deletions ckan/logic/action/get.py
@@ -1,5 +1,6 @@
import uuid
import logging
import json

from pylons import config
from pylons.i18n import _
Expand Down Expand Up @@ -805,7 +806,7 @@ def package_search(context, data_dict):
results = []
if not abort:
# return a list of package ids
data_dict['fl'] = 'id'
data_dict['fl'] = 'id data_dict'


# If this query hasn't come from a controller that has set this flag
Expand All @@ -822,6 +823,7 @@ def package_search(context, data_dict):

for package in query.results:
# get the package object
package, package_dict = package['id'], package.get('data_dict')
pkg_query = session.query(model.PackageRevision)\
.filter(model.PackageRevision.id == package)\
.filter(and_(
Expand All @@ -835,9 +837,16 @@ def package_search(context, data_dict):
if not pkg:
log.warning('package %s in index but not in database' % package)
continue

result_dict = model_dictize.package_dictize(pkg,context)
results.append(result_dict)
## use data in search index if there
if package_dict:
## the package_dict still needs translating when being viewed
package_dict = json.loads(package_dict)
if context.get('for_view'):
for item in plugins.PluginImplementations( plugins.IPackageController):
package_dict = item.before_view(package_dict)
results.append(package_dict)
else:
results.append(model_dictize.package_dictize(pkg,context))

count = query.count
facets = query.facets
Expand Down

0 comments on commit efbf1dc

Please sign in to comment.