1 | #!/usr/bin/env python
|
---|
2 |
|
---|
3 | import xapian
|
---|
4 | import os
|
---|
5 | import random
|
---|
6 |
|
---|
7 | os.environ['XAPIAN_FLUSH_THRESHOLD'] = "100000000"
|
---|
8 |
|
---|
9 | db = xapian.WritableDatabase('/tmp/test_index', xapian.DB_CREATE_OR_OPEN)
|
---|
10 |
|
---|
11 | some_data = 'one two three four five six seven eight nine ten'.split()
|
---|
12 |
|
---|
13 | for 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)
|
---|