arrange so that a default first indexing run for a given user runs a quick shallow pass, so that queries return some results quickly after indexing starts, avoiding user frustration
This commit is contained in:
+10
-3
@@ -178,7 +178,7 @@ bool FsIndexer::init()
|
||||
}
|
||||
|
||||
// Recursively index each directory in the topdirs:
|
||||
bool FsIndexer::index()
|
||||
bool FsIndexer::index(bool quickshallow)
|
||||
{
|
||||
Chrono chron;
|
||||
if (!init())
|
||||
@@ -193,6 +193,11 @@ bool FsIndexer::index()
|
||||
}
|
||||
|
||||
m_walker.setSkippedPaths(m_config->getSkippedPaths());
|
||||
if (quickshallow) {
|
||||
m_walker.setOpts(m_walker.getOpts() | FsTreeWalker::FtwSkipDotFiles);
|
||||
m_walker.setMaxDepth(2);
|
||||
}
|
||||
|
||||
for (vector<string>::const_iterator it = m_tdl.begin();
|
||||
it != m_tdl.end(); it++) {
|
||||
LOGDEB(("FsIndexer::index: Indexing %s into %s\n", it->c_str(),
|
||||
@@ -204,11 +209,13 @@ bool FsIndexer::index()
|
||||
|
||||
// Adjust the "follow symlinks" option
|
||||
bool follow;
|
||||
int opts = m_walker.getOpts();
|
||||
if (m_config->getConfParam("followLinks", &follow) && follow) {
|
||||
m_walker.setOpts(FsTreeWalker::FtwFollow);
|
||||
opts |= FsTreeWalker::FtwFollow;
|
||||
} else {
|
||||
m_walker.setOpts(FsTreeWalker::FtwOptNone);
|
||||
opts &= ~FsTreeWalker::FtwFollow;
|
||||
}
|
||||
m_walker.setOpts(opts);
|
||||
|
||||
int abslen;
|
||||
if (m_config->getConfParam("idxabsmlen", &abslen))
|
||||
|
||||
@@ -60,7 +60,7 @@ class FsIndexer : public FsTreeWalkerCB {
|
||||
* We open the database,
|
||||
* then call a file system walk for each top-level directory.
|
||||
*/
|
||||
bool index();
|
||||
bool index(bool quickshallow = 0);
|
||||
|
||||
/** Index a list of files. No db cleaning or stemdb updating */
|
||||
bool indexFiles(std::list<std::string> &files, ConfIndexer::IxFlag f =
|
||||
|
||||
@@ -50,6 +50,46 @@ ConfIndexer::~ConfIndexer()
|
||||
deleteZ(m_beagler);
|
||||
}
|
||||
|
||||
// Determine if this is likely the first time that the user runs
|
||||
// indexing. We don't look at the xapiandb as this may have been
|
||||
// explicitely removed for valid reasons, but at the indexing status
|
||||
// file, which should be unexistant-or-empty only before any indexing
|
||||
// has ever run
|
||||
bool ConfIndexer::runFirstIndexing()
|
||||
{
|
||||
// Indexing status file existing and not empty ?
|
||||
struct stat st;
|
||||
if (stat(m_config->getIdxStatusFile().c_str(), &st) == 0 &&
|
||||
st.st_size > 0) {
|
||||
LOGDEB0(("ConfIndexer::runFirstIndexing: no: status file not empty\n"));
|
||||
exit(1);
|
||||
return false;
|
||||
}
|
||||
// And only do this if the user has kept the default topdirs (~).
|
||||
vector<string>tdl = m_config->getTopdirs();
|
||||
if (tdl.size() != 1 || tdl[0].compare(path_canon(path_tildexpand("~")))) {
|
||||
LOGDEB0(("ConfIndexer::runFirstIndexing: no: not home only\n"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConfIndexer::firstFsIndexingSequence()
|
||||
{
|
||||
LOGDEB(("ConfIndexer::firstFsIndexingSequence\n"));
|
||||
deleteZ(m_fsindexer);
|
||||
m_fsindexer = new FsIndexer(m_config, &m_db, m_updater);
|
||||
if (!m_fsindexer) {
|
||||
return false;
|
||||
}
|
||||
int flushmb = m_db.getFlushMb();
|
||||
m_db.setFlushMb(2);
|
||||
m_fsindexer->index(true);
|
||||
m_db.doFlush();
|
||||
m_db.setFlushMb(flushmb);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConfIndexer::index(bool resetbefore, ixType typestorun)
|
||||
{
|
||||
Rcl::Db::OpenMode mode = resetbefore ? Rcl::Db::DbTrunc : Rcl::Db::DbUpd;
|
||||
@@ -61,6 +101,9 @@ bool ConfIndexer::index(bool resetbefore, ixType typestorun)
|
||||
|
||||
m_config->setKeyDir(cstr_null);
|
||||
if (typestorun & IxTFs) {
|
||||
if (runFirstIndexing()) {
|
||||
firstFsIndexingSequence();
|
||||
}
|
||||
deleteZ(m_fsindexer);
|
||||
m_fsindexer = new FsIndexer(m_config, &m_db, m_updater);
|
||||
if (!m_fsindexer || !m_fsindexer->index()) {
|
||||
|
||||
@@ -138,6 +138,13 @@ class ConfIndexer {
|
||||
BeagleQueueIndexer *m_beagler;
|
||||
DbIxStatusUpdater *m_updater;
|
||||
string m_reason;
|
||||
|
||||
// The first time we index, we do things a bit differently to
|
||||
// avoid user frustration (make at least some results available
|
||||
// fast by using several passes, the first ones to index common
|
||||
// interesting locations).
|
||||
bool runFirstIndexing();
|
||||
bool firstFsIndexingSequence();
|
||||
};
|
||||
|
||||
#endif /* _INDEXER_H_INCLUDED_ */
|
||||
|
||||
Reference in New Issue
Block a user