~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/migrations/versions/027_use_ngrams.py

  • Committer: Tarmac
  • Author(s): Reed O'Brien
  • Date: 2014-05-20 14:46:39 UTC
  • mfrom: (511.1.6 es-migration)
  • Revision ID: tarmac-20140520144639-2wypg2q2m2qwvjch
This makes the ngram work migrate cleanly. Fixes: https://bugs.launchpad.net/bugs/1314239.

Approved by Juju Gui Bot, Brad Crittenden.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# use ngrams
 
2
import logging
 
3
 
 
4
from charmworld.models import CharmSource
 
5
 
 
6
from charmworld.search import (
 
7
    IndexMissing,
 
8
    update,
 
9
)
 
10
 
 
11
 
 
12
def upgrade(db, index_client):
 
13
    """db is the pymongo db instance for our datastore. Charms are in db.charms
 
14
    for instance.
 
15
 
 
16
    index_client is the ElasticSearch client.
 
17
    """
 
18
    log = logging.getLogger('migration_027')
 
19
    log.warning('Starting')
 
20
    charm_source = CharmSource(db, index_client)
 
21
    try:
 
22
        index_client.delete_index()
 
23
        log.warning("deleted index")
 
24
    except IndexMissing:
 
25
        # It is already updated.
 
26
        pass
 
27
        log.warning("Index already deleted")
 
28
    update(index_client)
 
29
    cids = charm_source.sync_index()
 
30
    while True:
 
31
        try:
 
32
            next(cids)
 
33
        except StopIteration:
 
34
            break
 
35
    log.warning("Index updated")