1 # ====================================================================
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13 # ====================================================================
17 from bsddb.db import DBEnv, DB
18 from bsddb.db import \
19 DB_INIT_MPOOL, DB_INIT_LOCK, DB_INIT_TXN, DB_THREAD, DB_BTREE
21 # missing from python interface at the moment
22 DB_LOG_INMEMORY = 0x00020000
24 from lucene import DbDirectory, IndexSearcher, Term, TermQuery
27 class BerkeleyDbSearcher(object):
32 print "Usage: BerkeleyDbSearcher <index dir>"
38 env.set_flags(DB_LOG_INMEMORY, 1);
40 env.set_cachesize(0, 0x4000000, 1)
41 elif os.name == 'posix':
42 from commands import getstatusoutput
43 if getstatusoutput('uname') == (0, 'Linux'):
44 env.set_cachesize(0, 0x4000000, 1)
46 env.open(dbHome, (DB_THREAD |
47 DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN), 0)
54 txn = env.txn_begin(None)
55 index.open(filename = '__index__', dbtype = DB_BTREE,
56 flags = DB_THREAD, txn = txn)
57 blocks.open(filename = '__blocks__', dbtype = DB_BTREE,
58 flags = DB_THREAD, txn = txn)
69 txn = env.txn_begin(None)
70 directory = DbDirectory(txn, index, blocks, 0)
71 searcher = IndexSearcher(directory, True)
73 topDocs = searcher.search(TermQuery(Term("contents", "fox")), 50)
74 print topDocs.totalHits, "document(s) found"
88 main = classmethod(main)