-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_xapian.py
76 lines (66 loc) · 2.44 KB
/
test_xapian.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: UTF-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Import from the Standard Library
from optparse import OptionParser
from sys import exit
# Import xapian
import traceback
import xapian
class XapianTest(object):
def test(self, backend):
if backend == 'glass':
backend = xapian.DB_BACKEND_GLASS
elif backend == 'chert':
backend = xapian.DB_BACKEND_CHERT
else:
raise ValueError
catalog = xapian.WritableDatabase('catalog', backend)
catalog.begin_transaction(True)
for i in range(0, 5000):
print('Doc {0}'.format(i))
doc = xapian.Document()
for j in range(0, 5000):
doc.add_value(j, 'Value {0}'.format(j))
catalog.add_document(doc)
catalog.commit_transaction()
if i%50==0:
for documentID in range(1, catalog.get_doccount() + 1):
document = catalog.get_document(documentID)
value1 = document.get_value(0)
value2 = document.get_value(1)
#print 'Value doc {0} - {1}'.format(documentID, value1)
#print 'Value doc {0} - {1}'.format(documentID, value2)
catalog.commit()
catalog.begin_transaction(True)
if __name__ == '__main__':
# The command line parser
usage = '%prog [OPTIONS] backend'
version = '1.0'
description = 'Test xapian'
parser = OptionParser(usage, version=version, description=description)
# Parse arguments
options, args = parser.parse_args()
n_args = len(args)
if n_args != 1:
parser.error('Wrong number of arguments.')
else:
backend = args[0]
t = XapianTest()
try:
t.test(backend)
except:
print traceback.format_exc()
exit(1)
exit(0)