3
3
MoinMoin - build xapian search engine's index
5
@copyright: 2006-2009 MoinMoin:ThomasWaldmann
5
@copyright: 2006 MoinMoin:ThomasWaldmann
6
6
@license: GNU GPL, see COPYING for details.
13
9
from MoinMoin.script import MoinScript
15
11
class IndexScript(MoinScript):
23
19
General syntax: moin [options] index build [build-options]
25
21
[options] usually should be:
26
--config-dir=/path/to/my/cfg/ --wiki-url=http://wiki.example.org/
22
--config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
28
24
[build-options] see below:
30
* You must run this script as the owner of the wiki files,
31
usually this is the web server user.
32
* You may add the build-option --files=files.lst to let the indexer
33
also consider the filesystem filenames contained in that file (one
34
filename per line). Search results from these files will be "found"
35
under a special pseudo page called FS (like File System).
36
Without this option, the indexer will just consider pages and attachments.
38
1. Conditionally (considering modification time) update the index:
39
moin ... index build --mode=update
41
2. Unconditionally add to the index:
42
moin ... index build --mode=add
44
3. Completely rebuild the index (1-stage):
45
moin ... index build --mode=rebuild
47
Note: until it has completely built the new index, the wiki will still
48
use the old index. After rebuild has completed, it kills the old index
49
and moves the new index into its place.
50
If the wiki uses the index at that moment, that might have unwanted side
51
effects. If you want to avoid that and you can accept a short downtime,
52
consider using this safer method:
54
Completely rebuild the index (2-stage):
55
# takes long, does not interfere with wiki searches:
56
moin ... index build --mode=buildnewindex
57
stop this moin wiki process(es)
58
# quick, replaces the old index with the new one:
59
moin ... index build --mode=usenewindex
60
start this moin wiki process(es)
25
0. You must run this script as owner of the wiki files, usually this is the
28
1. To add the files from '/files.lst' to the index
29
moin ... index build --files /files.lst --mode add
31
2. To update the index with the files from '/files.lst'
32
moin ... index build --files /files.lst --mode update
34
3. To rebuild the index with the files from '/files.lst'
35
moin ... index build --files /files.lst --mode rebuild
63
38
def __init__(self, argv, def_values):
69
44
self.parser.add_option(
70
45
"--mode", metavar="MODE", dest="mode",
71
help="either add (unconditionally add), update (conditional update), rebuild (complete 1-stage index rebuild)"
72
" or buildnewindex and usenewindex (complete 2-stage index rebuild)"
46
help="either add (unconditionally add to index), update (update an existing index) or rebuild (remove and add)"
75
49
def mainloop(self):
85
59
""" Xapian index build script class """
88
from MoinMoin.search.Xapian import XapianIndex
89
mode = self.options.mode
90
if mode in ('rebuild', 'buildnewindex'):
91
# rebuilding the DB into a new index directory, so the rebuild
92
# process does not interfere with the currently in-use DB
93
idx_mode, idx_name = 'add', 'index.new'
94
elif mode in ('add', 'update'):
96
idx_mode, idx_name = mode, 'index'
97
elif mode == 'usenewindex':
100
pass # XXX give error msg about invalid mode
102
if mode != 'usenewindex':
103
idx = XapianIndex(self.request, name=idx_name)
104
idx.indexPages(self.files, idx_mode)
106
if mode in ('rebuild', 'usenewindex'):
107
# 'rebuild' is still a bit dirty, because just killing old index will
108
# fail currently running searches. Thus, maybe do this in a time
109
# with litte wiki activity or better use 'buildnewindex' and
110
# 'usenewindex' (see above).
111
# XXX code here assumes that idx.db is a directory
112
# TODO improve this with xapian stub DBs
113
idx_old = XapianIndex(self.request, name='index').db
114
idx_new = XapianIndex(self.request, name='index.new').db
116
shutil.rmtree(idx_old)
118
if err.errno != errno.ENOENT: # ignore it if we have no current index
120
os.rename(idx_new, idx_old)
62
from MoinMoin.search.Xapian import Index
63
Index(self.request).indexPages(self.files, self.options.mode)