rcldb syngroups: allow setting synonyms source after construction

This commit is contained in:
Jean-Francois Dockes 2015-11-21 12:48:09 +01:00
parent d115bcfaa2
commit 53f57e75c6
3 changed files with 18 additions and 12 deletions

View File

@ -764,9 +764,6 @@ bool Db::open(OpenMode mode, OpenError *error)
}
if (!m_config->getStopfile().empty())
m_stops.setFile(m_config->getStopfile());
// Synonyms are only used at query time for now
if (mode == DbRO)
m_syngroups.setfile(m_config->getSynGroupsFile());
string dir = m_config->getDbDir();
string ermsg;
@ -1241,6 +1238,11 @@ void Db::setAbstractParams(int idxtrunc, int syntlen, int syntctxlen)
m_synthAbsWordCtxLen = syntctxlen;
}
bool Db::setSynGroupsFile(const string& fn)
{
return m_syngroups.setfile(fn);
}
static const string cstr_nc("\n\r\x0c\\");
#define RECORD_APPEND(R, NM, VAL) {R += NM + "=" + VAL + "\n";}

View File

@ -456,6 +456,9 @@ class Db {
}
bool doFlush();
// Use empty fn for no synonyms
bool setSynGroupsFile(const std::string& fn);
/* This has to be public for access by embedded Query::Native */
Native *m_ndb;
private:
@ -477,13 +480,20 @@ private:
// First fs occup check ?
int m_occFirstCheck;
// Synonym groups. There is no strict reason that this has to be
// an Rcl::Db member, as it is only used when building each It
// could be a SearchData member, or even a parameter to
// Query::setQuery(). Otoh, building the syngroups structure from
// a file may be expensive and it's unlikely to change with every
// query, so it makes sense to cache it, and Rcl::Db is not a bad
// place for this.
SynGroups m_syngroups;
/***************
* Parameters cached out of the configuration files. Logically const
* after init */
// Stop terms: those don't get indexed.
StopList m_stops;
// Synonym groups
SynGroups m_syngroups;
// Truncation length for stored meta fields
int m_idxMetaStoredLen;

View File

@ -270,16 +270,10 @@ bool Db::termMatch(int typ_sens, const string &lang, const string &_term,
exp1.swap(lexp);
sort(lexp.begin(), lexp.end());
lexp.erase(unique(lexp.begin(), lexp.end()), lexp.end());
LOGDEB(("ExpTerm: stemexp: %s\n",
LOGDEB(("ExpTerm: stemexp: %s\n",
stringsToString(lexp).c_str()));
}
// Expand the result for synonyms. Note that doing it here
// means that multi-term synonyms will not work
// (e.g. stakhanovist -> "hard at work". We would have to
// separate the multi-word expansions for our caller to
// add them as phrases to the query. Not impossible, but
// let's keep it at single words for now.
if (m_syngroups.ok() && (typ_sens & ET_SYNEXP)) {
LOGDEB(("ExpTerm: got syngroups\n"));
vector<string> exp1(lexp);