Ticket #284: writer.py

File writer.py, 763 bytes (added by Richard Boulton, 16 years ago)

Re-implementation of writer.pl in python

Line 
1#!/usr/bin/env python
2
3import xapian
4import os
5import random
6
7os.environ['XAPIAN_FLUSH_THRESHOLD'] = "100000000"
8
9db = xapian.WritableDatabase('/tmp/test_index', xapian.DB_CREATE_OR_OPEN)
10
11some_data = 'one two three four five six seven eight nine ten'.split()
12
13for id in xrange(500000):
14 print id
15
16 if id % 50000 == 0:
17 print "flushing index"
18 db.flush()
19
20 value = ''
21 for num in xrange(10):
22 value += chr(65 + random.randint(0, 25))
23
24 doc = xapian.Document()
25 doc.add_term("Q%d" % id)
26 doc.add_term("XFOO" + some_data[random.randint(0, 9)])
27 doc.add_term("XBAR" + some_data[random.randint(0, 1)])
28
29 if db.term_exists("Q%d" % id):
30 db.replace_document("Q%d" % id, doc)
31 else:
32 db.add_document(doc)