Skip to content

Commit

Permalink
Merge pull request #2645 from ckan/deniszgonjanin-search_index_rebuil…
Browse files Browse the repository at this point in the history
…d_progress

Deniszgonjanin search index rebuild progress
  • Loading branch information
David Read committed Sep 16, 2015
2 parents 599df45 + fd9bf89 commit 1414e76
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
23 changes: 14 additions & 9 deletions ckan/lib/cli.py
Expand Up @@ -402,14 +402,14 @@ class SearchIndexCommand(CkanCommand):
'''Creates a search index for all datasets
Usage:
search-index [-i] [-o] [-r] [-e] rebuild [dataset_name] - reindex dataset_name if given, if not then rebuild
full search index (all datasets)
search-index rebuild_fast - reindex using multiprocessing using all cores.
This acts in the same way as rubuild -r [EXPERIMENTAL]
search-index check - checks for datasets not indexed
search-index show DATASET_NAME - shows index of a dataset
search-index clear [dataset_name] - clears the search index for the provided dataset or
for the whole ckan instance
search-index [-i] [-o] [-r] [-e] [-q] rebuild [dataset_name] - reindex dataset_name if given, if not then rebuild
full search index (all datasets)
search-index rebuild_fast - reindex using multiprocessing using all cores.
This acts in the same way as rubuild -r [EXPERIMENTAL]
search-index check - checks for datasets not indexed
search-index show DATASET_NAME - shows index of a dataset
search-index clear [dataset_name] - clears the search index for the provided dataset or
for the whole ckan instance
'''

summary = __doc__.split('\n')[0]
Expand All @@ -432,6 +432,10 @@ def __init__(self, name):
action='store_true', default=False,
help='Refresh current index (does not clear the existing one)')

self.parser.add_option('-q', '--quiet', dest='quiet',
action='store_true', default=False,
help='Do not output index rebuild progress')

self.parser.add_option('-e', '--commit-each', dest='commit_each',
action='store_true', default=False, help=
'''Perform a commit after indexing each dataset. This ensures that changes are
Expand Down Expand Up @@ -474,7 +478,8 @@ def rebuild(self):
rebuild(only_missing=self.options.only_missing,
force=self.options.force,
refresh=self.options.refresh,
defer_commit=(not self.options.commit_each))
defer_commit=(not self.options.commit_each),
quiet=self.options.quiet)

if not self.options.commit_each:
commit()
Expand Down
12 changes: 10 additions & 2 deletions ckan/lib/search/__init__.py
Expand Up @@ -135,7 +135,8 @@ def notify(self, entity, operation):
log.warn("Discarded Sync. indexing for: %s" % entity)


def rebuild(package_id=None, only_missing=False, force=False, refresh=False, defer_commit=False, package_ids=None):
def rebuild(package_id=None, only_missing=False, force=False, refresh=False,
defer_commit=False, package_ids=None, quiet=False):
'''
Rebuilds the search index.
Expand Down Expand Up @@ -183,7 +184,14 @@ def rebuild(package_id=None, only_missing=False, force=False, refresh=False, def
if not refresh:
package_index.clear()

for pkg_id in package_ids:
total_packages = len(package_ids)
for counter, pkg_id in enumerate(package_ids):
if not quiet:
sys.stdout.write(
"\rIndexing dataset {0}/{1}".format(
counter +1, total_packages)
)
sys.stdout.flush()
try:
package_index.update_dict(
logic.get_action('package_show')(context,
Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/legacy/lib/test_cli.py
Expand Up @@ -80,7 +80,7 @@ def test_clear_and_rebuild_index(self):

# Rebuild index
self.search.args = ()
self.search.options = FakeOptions(only_missing=False,force=False,refresh=False,commit_each=False)
self.search.options = FakeOptions(only_missing=False, force=False, refresh=False, commit_each=False, quiet=False)
self.search.rebuild()
pkg_count = model.Session.query(model.Package).filter(model.Package.state==u'active').count()

Expand Down

0 comments on commit 1414e76

Please sign in to comment.