forked from Sefaria/Sefaria-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_indexes.py
37 lines (32 loc) · 950 Bytes
/
convert_indexes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
from sefaria.model import *
from sefaria.system.database import db
from sefaria.clean import remove_old_counts
#Clear out counts
remove_old_counts()
db.vstate.remove({})
#Remove mongo indexes for Index.titleVariants
for x in ["titleVariants", "titleVariants_1"]:
try:
db.index.drop_index(x)
except:
pass
#Covert Indexes to new format
for indx in IndexSet():
if indx.is_commentary():
print "Skipping " + indx.title
continue
print indx.title
try:
indx.save()
except Exception as e:
print u"Caught exception: {}".format(e)
#Convert all existing Version counts to VersionState objects
for c in CountSet({"title": {"$exists": 1}}):
print c.title
try:
vs = VersionState(c.title)
vs.flags = getattr(c, "flags", {})
vs.save()
except Exception as e:
print "Couldn't modify version state {}: {}".format(c.title, e)