From 088f1f9a9f83da660e28be0bd16581875a6e0ba9 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Wed, 16 Jul 2014 17:05:26 +0200 Subject: [PATCH] try out modification to use container file name for display, but not search, purposes when the subdocument file name is not set --- src/VERSION | 2 +- src/index/fsindexer.cpp | 10 +++++++--- src/rcldb/rcldb.cpp | 15 +++++++++++++++ src/rcldb/rcldoc.cpp | 1 + src/rcldb/rcldoc.h | 14 +++++++++++++- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/VERSION b/src/VERSION index 39893559..72c6d15d 100644 --- a/src/VERSION +++ b/src/VERSION @@ -1 +1 @@ -1.20.0 +1.20.0p1 diff --git a/src/index/fsindexer.cpp b/src/index/fsindexer.cpp index c77c9b61..a4319454 100644 --- a/src/index/fsindexer.cpp +++ b/src/index/fsindexer.cpp @@ -724,9 +724,13 @@ FsIndexer::processonefile(RclConfig *config, if (doc.url.empty()) doc.url = cstr_fileu + fn; const string *fnp = 0; - if (doc.ipath.empty() && - (!doc.peekmeta(Rcl::Doc::keyfn, &fnp) || fnp->empty())) - doc.meta[Rcl::Doc::keyfn] = utf8fn; + if (doc.ipath.empty()) { + if (!doc.peekmeta(Rcl::Doc::keyfn, &fnp) || fnp->empty()) + doc.meta[Rcl::Doc::keyfn] = utf8fn; + } else { + // subdoc: set container file name + doc.meta[Rcl::Doc::keytcfn] = utf8fn; + } char cbuf[100]; sprintf(cbuf, "%lld", (long long)stp->st_size); diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp index 39c846c7..d8ae9c80 100644 --- a/src/rcldb/rcldb.cpp +++ b/src/rcldb/rcldb.cpp @@ -1539,6 +1539,21 @@ bool Db::addOrUpdate(const string &udi, const string &parent_udi, Doc &doc) } } + // At this point, if the document "filename" field was empty, + // try to store the "container file name" value. This is done + // after indexing because we don't want search matches on + // this, but the filename is often useful for display + // purposes. + const string *fnp = 0; + if (!doc.peekmeta(Rcl::Doc::keyfn, &fnp) || fnp->empty()) { + if (doc.peekmeta(Rcl::Doc::keytcfn, &fnp) && !fnp->empty()) { + string value = + neutchars(truncate_to_word(*fnp, + m_idxMetaStoredLen), cstr_nc); + RECORD_APPEND(record, Rcl::Doc::keyfn, value); + } + } + // If empty pages (multiple break at same pos) were recorded, save // them (this is because we have no way to record them in the // Xapian list diff --git a/src/rcldb/rcldoc.cpp b/src/rcldb/rcldoc.cpp index f550c9f4..efcb4cc5 100644 --- a/src/rcldb/rcldoc.cpp +++ b/src/rcldb/rcldoc.cpp @@ -30,6 +30,7 @@ namespace Rcl { const string Doc::keyds("dbytes"); const string Doc::keyfmt("fmtime"); const string Doc::keyfn("filename"); + const string Doc::keytcfn("topcontainerfn"); const string Doc::keyfs("fbytes"); const string Doc::keyipt("ipath"); const string Doc::keykw("keywords"); diff --git a/src/rcldb/rcldoc.h b/src/rcldb/rcldoc.h index 34a6e658..d2288566 100644 --- a/src/rcldb/rcldoc.h +++ b/src/rcldb/rcldoc.h @@ -246,7 +246,19 @@ class Doc { // childurl. This is set when working with the parent of the result, to hold // the child of interest url, typically to highlight a directory entry static const string keychildurl; - static const string keyfn; // file name + // file name. This is set for filesystem-level containers or + // documents, and not inherited by subdocuments (which can get a + // keyfn anyway from, e.g, an attachment filename value). Subdocs + // used to inherit the file name, but this was undesirable (you + // usually don't want to see all subdocs when searching for the + // file name). Instead the container file name is now set in the + // document record but not indexed (see next entry). + static const string keyfn; + // Container file name. This is set for all subdocuments of a + // given top level container. It is not indexed by default but + // stored in the document record keyfn field if this is still + // empty when we create it, for display purposes. + static const string keytcfn; static const string keyipt; // ipath static const string keytp; // mime type static const string keyfmt; // file mtime