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
+4
View File
@@ -762,6 +762,10 @@ 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;
try {
+4
View File
@@ -29,6 +29,7 @@
#include "rclconfig.h"
#include "utf8iter.h"
#include "textsplit.h"
#include "syngroups.h"
using std::string;
using std::vector;
@@ -480,6 +481,9 @@ private:
* 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;
// This is how long an abstract we keep or build from beginning of
+26 -1
View File
@@ -235,7 +235,8 @@ bool Db::termMatch(int typ_sens, const string &lang, const string &_term,
}
} else {
// Expansion is STEM or NONE (which may still need case/diac exp)
// Expansion is STEM or NONE (which may still need synonyms
// and case/diac exp)
vector<string> lexp;
if (diac_sensitive && case_sensitive) {
@@ -273,6 +274,30 @@ bool Db::termMatch(int typ_sens, const string &lang, const string &_term,
}
LOGDEB(("ExpTerm: stem exp-> %s\n", stringsToString(exp1).c_str()));
lexp.clear();
// 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()) {
LOGDEB(("ExpTerm: got syngroups\n"));
for (vector<string>::const_iterator it = exp1.begin();
it != exp1.end(); it++) {
vector<string> sg = m_syngroups.getgroup(*it);
if (!sg.empty()) {
LOGDEB(("ExpTerm: syns: %s -> %s\n",
it->c_str(), stringsToString(sg).c_str()));
lexp.insert(lexp.end(), sg.begin(), sg.end());
}
}
sort(lexp.begin(), lexp.end());
lexp.erase(unique(lexp.begin(), lexp.end()), lexp.end());
// Keep result in exp1 for next step
exp1.swap(lexp);
}
// Expand the resulting list for case (all stemdb content
// is lowercase)
lexp.clear();