本文整理汇总了Python中solr.SolrConnection.optimize方法的典型用法代码示例。如果您正苦于以下问题:Python SolrConnection.optimize方法的具体用法?Python SolrConnection.optimize怎么用?Python SolrConnection.optimize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类solr.SolrConnection
的用法示例。
在下文中一共展示了SolrConnection.optimize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: solr_reindex
# 需要导入模块: from solr import SolrConnection [as 别名]
# 或者: from solr.SolrConnection import optimize [as 别名]
def solr_reindex (self):
"""
Reindex all entries. Used when switching to/from "private" status.
"""
solr_conn = SolrConnection(settings.SOLR_URL)
# Start by deleting 'em all
solr_conn.delete_query('user:%s' % self.user.id)
entries = Entry.objects.filter(user=self.user)
docs = []
# Arbitrary assignment of a constant, here.
SLICE_SIZE = 50
slices = [x for x in range(entries.count()) \
if x % SLICE_SIZE == 0]
for s in slices:
entry_slice = entries[s:s+SLICE_SIZE]
for entry in entry_slice:
docs.append(entry.solr_doc)
if len(docs) == SLICE_SIZE:
try:
solr_conn.add_many(docs)
except:
# should log appropriately, huh
pass
del(docs)
docs = []
# Don't miss the leftovers
solr_conn.add_many(docs)
solr_conn.commit()
solr_conn.optimize()
示例2: Command
# 需要导入模块: from solr import SolrConnection [as 别名]
# 或者: from solr.SolrConnection import optimize [as 别名]
class Command(BaseCommand):
user_option = optparse.make_option('--user',
action='store', dest='user',
help='name of user whose entries to purge')
option_list = BaseCommand.option_list + (user_option,)
help = "index all or user-specific entries in solr"
args = 'an optional username'
def handle(self, *args, **options):
self.solr = SolrConnection(SOLR_URL)
self.cursor = connection.cursor()
if options['user']:
print "indexing user"
self.index_entries(user=options['user'])
else:
print 'indexing everything'
self.index_entries()
print 'committing'
self.solr.commit()
print 'optimizing'
self.solr.optimize()
def index_entries(self, user=''):
counter = 0
entries = m.Entry.objects.all()
if user:
entries = entries.filter(user__username=user)
docs = []
print 'entry count:', entries.count()
SLICE_SIZE = MAX_DOCS_PER_ADD * COMMIT_FREQUENCY
slices = [x for x in range(entries.count()) \
if x % SLICE_SIZE == 0]
for s in slices:
print 'indexing %s to %s...' % (s, s+SLICE_SIZE)
entry_slice = entries[s:s+SLICE_SIZE]
for entry in entry_slice:
counter += 1
docs.append(entry.solr_doc)
if len(docs) == MAX_DOCS_PER_ADD:
try:
self.solr.add_many(docs)
except:
print 'BAD RECORD:', [d['id'] for d in docs]
del(docs)
docs = []
reset_queries()
if counter % (COMMIT_FREQUENCY * MAX_DOCS_PER_ADD) == 0:
print 'committing at count:', counter
self.solr.commit()
# Don't miss the leftovers
self.solr.add_many(docs)
示例3: handle
# 需要导入模块: from solr import SolrConnection [as 别名]
# 或者: from solr.SolrConnection import optimize [as 别名]
def handle(self, batch_location=None, *args, **options):
if len(args)!=0:
raise CommandError('Usage is purge_batch %s' % self.args)
loader = BatchLoader()
try:
log.info("purging batch %s", batch_location)
loader.purge_batch(batch_location)
if options['optimize']:
log.info("optimizing solr")
solr = SolrConnection(settings.SOLR)
solr.optimize()
log.info("optimizing MySQL OCR table")
cursor = connection.cursor()
cursor.execute("OPTIMIZE TABLE core_ocr")
log.info("finished optimizing")
except BatchLoaderException, e:
log.exception(e)
raise CommandError("unable to purge batch. check the purge_batch log for clues")