Implement single-term query-time synonyms

This commit is contained in:
Jean-Francois Dockes
2015-08-22 15:11:07 +02:00
parent 62f4f7bd81
commit d8e8ce6ee2
7 changed files with 92 additions and 41 deletions
+33 -31
View File
@@ -1144,21 +1144,44 @@ string RclConfig::getMimeIconPath(const string &mtype, const string &apptag)
return path_cat(iconpath, iconname) + ".png";
}
string RclConfig::getDbDir() const
// Return path defined by varname. May be absolute or relative to
// confdir, with default in confdir
string RclConfig::getConfdirPath(const char *varname, const char *dflt) const
{
string dbdir;
if (!getConfParam("dbdir", dbdir)) {
LOGERR(("RclConfig::getDbDir: no db directory in configuration\n"));
string result;
if (!getConfParam(varname, result)) {
result = path_cat(getConfDir(), dflt);
} else {
dbdir = path_tildexpand(dbdir);
result = path_tildexpand(result);
// If not an absolute path, compute relative to config dir
if (dbdir.at(0) != '/') {
LOGDEB1(("Dbdir not abs, catting with confdir\n"));
dbdir = path_cat(getConfDir(), dbdir);
if (result.at(0) != '/') {
result = path_cat(getConfDir(), result);
}
}
LOGDEB1(("RclConfig::getDbDir: dbdir: [%s]\n", dbdir.c_str()));
return path_canon(dbdir);
return path_canon(result);
}
string RclConfig::getDbDir() const
{
return getConfdirPath("dbdir", "xapiandb");
}
string RclConfig::getStopfile() const
{
return getConfdirPath("stoplistfile", "stoplist.txt");
}
string RclConfig::getSynGroupsFile() const
{
return getConfdirPath("syngroupsfile", "syngroups.txt");
}
// The index status file is fast changing, so it's possible to put it outside
// of the config directory (for ssds, not sure this is really useful).
string RclConfig::getIdxStatusFile() const
{
return getConfdirPath("idxstatusfile", "idxstatus.txt");
}
void RclConfig::urlrewrite(const string& dbdir, string& url) const
@@ -1213,32 +1236,11 @@ bool RclConfig::sourceChanged() const
return false;
}
string RclConfig::getStopfile() const
{
return path_cat(getConfDir(), "stoplist.txt");
}
string RclConfig::getPidfile() const
{
return path_cat(getConfDir(), "index.pid");
}
// The index status file is fast changing, so it's possible to put it outside
// of the config directory (for ssds, not sure this is really useful).
string RclConfig::getIdxStatusFile() const
{
string path;
if (!getConfParam("idxstatusfile", path)) {
return path_cat(getConfDir(), "idxstatus.txt");
} else {
path = path_tildexpand(path);
// If not an absolute path, compute relative to config dir
if (path.at(0) != '/') {
path = path_cat(getConfDir(), path);
}
return path_canon(path);
}
}
string RclConfig::getWebQueueDir() const
{
string webqueuedir;
+3
View File
@@ -171,10 +171,13 @@ class RclConfig {
* need for other status */
vector<string> getTopdirs() const;
string getConfdirPath(const char *varname, const char *dflt) const;
/** Get database directory */
string getDbDir() const;
/** Get stoplist file name */
string getStopfile() const;
/** Get synonym groups file name */
string getSynGroupsFile() const;
/** Get indexing pid file name */
string getPidfile() const;
/** Get indexing status file name */
+20 -8
View File
@@ -63,20 +63,29 @@ SynGroups::~SynGroups()
const int LL = 1024;
SynGroups::SynGroups(const string& fn)
SynGroups::SynGroups()
: m(new Internal)
{
}
bool SynGroups::setfile(const string& fn)
{
LOGDEB(("SynGroups::setfile(%s)\n", fn.c_str()));
if (!m) {
LOGERR(("SynGroups::SynGroups:: new Internal failed: no mem ?\n"));
return;
LOGERR(("SynGroups:setfile:: new Internal failed: no mem ?\n"));
return false;
}
// Don't set ok to true.
if (fn.empty())
return true;
ifstream input;
input.open(fn.c_str(), ios::in);
if (!input.is_open()) {
LOGERR(("SynGroups::SynGroups:: could not open %s errno %d\n",
LOGERR(("SynGroups:setfile:: could not open %s errno %d\n",
fn.c_str(), errno));
return;
return false;
}
char cline[LL];
@@ -91,7 +100,7 @@ SynGroups::SynGroups(const string& fn)
if (!input.good()) {
if (input.bad()) {
LOGDEB(("Parse: input.bad()\n"));
return;
return false;
}
// Must be eof ? But maybe we have a partial line which
// must be processed. This happens if the last line before
@@ -130,7 +139,7 @@ SynGroups::SynGroups(const string& fn)
vector<string> words;
if (!stringToStrings(line, words)) {
LOGERR(("SynGroups::SynGroups: %s: bad line %d: %s\n",
LOGERR(("SynGroups:setfile: %s: bad line %d: %s\n",
fn.c_str(), lnum, line.c_str()));
continue;
}
@@ -138,7 +147,7 @@ SynGroups::SynGroups(const string& fn)
if (words.empty())
continue;
if (words.size() == 1) {
LOGDEB(("SynGroups::SynGroups: single term group at line %d ??\n",
LOGDEB(("SynGroups:setfile: single term group at line %d ??\n",
lnum));
continue;
}
@@ -148,8 +157,11 @@ SynGroups::SynGroups(const string& fn)
it != words.end(); it++) {
m->terms[*it] = lnum;
}
LOGDEB(("SynGroups::setfile: group: [%s]\n",
stringsToString(m->groups[lnum]).c_str()));
}
m->ok = true;
return true;
}
vector<string> SynGroups::getgroup(const string& term)
+2 -1
View File
@@ -26,8 +26,9 @@
// in a group are equivalent.
class SynGroups {
public:
SynGroups(const std::string& fname);
SynGroups();
~SynGroups();
bool setfile(const std::string& fname);
std::vector<std::string> getgroup(const std::string& term);
bool ok();
private: