|
a/src/rcldb/rcldb.cpp |
|
b/src/rcldb/rcldb.cpp |
|
... |
|
... |
255 |
{
|
255 |
{
|
256 |
int action = (mode == Db::DbUpd) ? Xapian::DB_CREATE_OR_OPEN :
|
256 |
int action = (mode == Db::DbUpd) ? Xapian::DB_CREATE_OR_OPEN :
|
257 |
Xapian::DB_CREATE_OR_OVERWRITE;
|
257 |
Xapian::DB_CREATE_OR_OVERWRITE;
|
258 |
|
258 |
|
259 |
#ifdef _WIN32
|
259 |
#ifdef _WIN32
|
260 |
// Xapian is quite bad at erasing partial db which can
|
260 |
// On Windows, Xapian is quite bad at erasing partial db which can
|
261 |
// occur because of open file deletion errors on
|
261 |
// occur because of open file deletion errors.
|
262 |
// Windows.
|
|
|
263 |
if (mode == DbTrunc) {
|
262 |
if (mode == DbTrunc) {
|
264 |
if (path_exists(path_cat(dir, "iamchert"))) {
|
263 |
if (path_exists(path_cat(dir, "iamchert"))) {
|
265 |
wipedir(dir);
|
264 |
wipedir(dir);
|
266 |
unlink(dir.c_str());
|
265 |
unlink(dir.c_str());
|
267 |
}
|
266 |
}
|
268 |
}
|
267 |
}
|
269 |
#endif
|
268 |
#endif
|
270 |
|
269 |
|
271 |
if (::access(dir.c_str(), 0) == 0) {
|
270 |
if (path_exists(dir)) {
|
272 |
// Existing index
|
271 |
// Existing index.
|
273 |
xwdb = Xapian::WritableDatabase(dir, action);
|
272 |
xwdb = Xapian::WritableDatabase(dir, action);
|
|
|
273 |
if (action == Xapian::DB_CREATE_OR_OVERWRITE ||
|
|
|
274 |
xwdb.get_doccount() == 0) {
|
|
|
275 |
// New or empty index. Set the "store text" option
|
|
|
276 |
// according to configuration. The metadata record will be
|
|
|
277 |
// written further down.
|
|
|
278 |
m_storetext = o_index_storedoctext;
|
|
|
279 |
LOGDEB("Db:: index " << (m_storetext?"stores":"does not store") <<
|
|
|
280 |
" document text\n");
|
|
|
281 |
} else {
|
|
|
282 |
// Existing non empty. Get the option from the index.
|
|
|
283 |
storesDocText(xwdb);
|
|
|
284 |
}
|
274 |
} else {
|
285 |
} else {
|
275 |
// New index. If possible, and depending on config, use a stub
|
286 |
// New index. If possible, and depending on config, use a stub
|
276 |
// to force using Chert. No sense in doing this if we are
|
287 |
// to force using Chert. No sense in doing this if we are
|
277 |
// storing the text anyway.
|
288 |
// storing the text anyway.
|
278 |
#if XAPIAN_AT_LEAST(1,3,0) && XAPIAN_HAS_CHERT_BACKEND
|
289 |
#if XAPIAN_AT_LEAST(1,3,0) && XAPIAN_HAS_CHERT_BACKEND
|
|
... |
|
... |
299 |
m_storetext = false;
|
310 |
m_storetext = false;
|
300 |
}
|
311 |
}
|
301 |
LOGINF("Rcl::Db::openWrite: new index will " << (m_storetext?"":"not ")
|
312 |
LOGINF("Rcl::Db::openWrite: new index will " << (m_storetext?"":"not ")
|
302 |
<< "store document text\n");
|
313 |
<< "store document text\n");
|
303 |
#else
|
314 |
#else
|
304 |
// Old Xapian (chert only) or newer (no chert). Use the
|
315 |
// Old Xapian (chert only) or much newer (no chert). Use the
|
305 |
// default index backend and let the user decide of the
|
316 |
// default index backend and let the user decide of the
|
306 |
// abstract generation method. The configured default is to
|
317 |
// abstract generation method. The configured default is to
|
307 |
// store the text.
|
318 |
// store the text.
|
308 |
xwdb = Xapian::WritableDatabase(dir, action);
|
319 |
xwdb = Xapian::WritableDatabase(dir, action);
|
309 |
m_storetext = o_index_storedoctext;
|
320 |
m_storetext = o_index_storedoctext;
|
310 |
#endif
|
321 |
#endif
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
// If the index is empty, write the data format version,
|
311 |
// Set the storetext value inside the index descriptor (new
|
325 |
// and the storetext option value inside the index descriptor (new
|
312 |
// with recoll 1.24, maybe we'll have other stuff to store in
|
326 |
// with recoll 1.24, maybe we'll have other stuff to store in
|
313 |
// there in the future).
|
327 |
// there in the future).
|
|
|
328 |
if (xwdb.get_doccount() == 0) {
|
314 |
string desc = string("storetext=") + (m_storetext ? "1" : "0") + "\n";
|
329 |
string desc = string("storetext=") + (m_storetext ? "1" : "0") + "\n";
|
315 |
xwdb.set_metadata(cstr_RCL_IDX_DESCRIPTOR_KEY, desc);
|
330 |
xwdb.set_metadata(cstr_RCL_IDX_DESCRIPTOR_KEY, desc);
|
316 |
}
|
|
|
317 |
|
|
|
318 |
// If the index is empty, write the data format version at once
|
|
|
319 |
// to avoid stupid error messages:
|
|
|
320 |
if (xwdb.get_doccount() == 0) {
|
|
|
321 |
xwdb.set_metadata(cstr_RCL_IDX_VERSION_KEY, cstr_RCL_IDX_VERSION);
|
331 |
xwdb.set_metadata(cstr_RCL_IDX_VERSION_KEY, cstr_RCL_IDX_VERSION);
|
322 |
}
|
332 |
}
|
323 |
|
333 |
|
324 |
m_iswritable = true;
|
334 |
m_iswritable = true;
|
325 |
|
335 |
|
326 |
#ifdef IDX_THREADS
|
336 |
#ifdef IDX_THREADS
|
327 |
maybeStartThreads();
|
337 |
maybeStartThreads();
|
328 |
#endif
|
338 |
#endif
|
329 |
}
|
339 |
}
|
330 |
|
340 |
|
331 |
void Db::Native::openRead(const string& dir)
|
341 |
void Db::Native::storesDocText(Xapian::Database& db)
|
332 |
{
|
342 |
{
|
333 |
m_iswritable = false;
|
|
|
334 |
xrdb = Xapian::Database(dir);
|
|
|
335 |
string desc = xrdb.get_metadata(cstr_RCL_IDX_DESCRIPTOR_KEY);
|
343 |
string desc = db.get_metadata(cstr_RCL_IDX_DESCRIPTOR_KEY);
|
336 |
ConfSimple cf(desc, 1);
|
344 |
ConfSimple cf(desc, 1);
|
337 |
string val;
|
345 |
string val;
|
338 |
m_storetext = false;
|
346 |
m_storetext = false;
|
339 |
if (cf.get("storetext", val) && stringToBool(val)) {
|
347 |
if (cf.get("storetext", val) && stringToBool(val)) {
|
340 |
m_storetext = true;
|
348 |
m_storetext = true;
|
341 |
}
|
349 |
}
|
342 |
LOGDEB("Db::openRead: index " << (m_storetext?"stores":"does not store") <<
|
350 |
LOGDEB("Db:: index " << (m_storetext?"stores":"does not store") <<
|
343 |
" document text\n");
|
351 |
" document text\n");
|
|
|
352 |
}
|
|
|
353 |
|
|
|
354 |
void Db::Native::openRead(const string& dir)
|
|
|
355 |
{
|
|
|
356 |
m_iswritable = false;
|
|
|
357 |
xrdb = Xapian::Database(dir);
|
|
|
358 |
storesDocText(xrdb);
|
344 |
}
|
359 |
}
|
345 |
|
360 |
|
346 |
/* See comment in class declaration: return all subdocuments of a
|
361 |
/* See comment in class declaration: return all subdocuments of a
|
347 |
* document given by its unique id. */
|
362 |
* document given by its unique id. */
|
348 |
bool Db::Native::subDocs(const string &udi, int idxi,
|
363 |
bool Db::Native::subDocs(const string &udi, int idxi,
|