|
a/src/rcldb/stemdb.cpp |
|
b/src/rcldb/stemdb.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: stemdb.cpp,v 1.2 2006-05-02 09:49:06 dockes Exp $ (C) 2005 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: stemdb.cpp,v 1.3 2006-09-19 14:30:39 dockes Exp $ (C) 2005 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
|
4 |
|
5 |
/**
|
5 |
/**
|
6 |
* Management of the auxiliary databases listing stems and their expansion
|
6 |
* Management of the auxiliary databases listing stems and their expansion
|
7 |
* terms
|
7 |
* terms
|
|
... |
|
... |
166 |
derivs.push_back(it->second);
|
166 |
derivs.push_back(it->second);
|
167 |
// cerr << " " << it->second << endl;
|
167 |
// cerr << " " << it->second << endl;
|
168 |
} else {
|
168 |
} else {
|
169 |
// Changing stems
|
169 |
// Changing stems
|
170 |
++stemdiff;
|
170 |
++stemdiff;
|
171 |
if (derivs.size() == 1) {
|
171 |
// We need an entry even if there is only one derivative
|
172 |
// Exactly one term stems to this. Check for the case where
|
172 |
// so that it is possible to search by entering the stem
|
173 |
// the stem itself exists as a term. The code above would not
|
173 |
// even if it doesnt exist as a term
|
174 |
// have inserted anything in this case.
|
|
|
175 |
if (xdb.term_exists(stem))
|
|
|
176 |
derivs.push_back(stem);
|
|
|
177 |
}
|
|
|
178 |
if (derivs.size() > 1) {
|
174 |
if (derivs.size() >= 1) {
|
179 |
// Previous stem has multiple derivatives. Enter in db
|
175 |
// Previous stem has multiple derivatives. Enter in db
|
180 |
++stemmultiple;
|
176 |
++stemmultiple;
|
181 |
Xapian::Document newdocument;
|
177 |
Xapian::Document newdocument;
|
182 |
newdocument.add_term(stem);
|
178 |
newdocument.add_term(stem);
|
183 |
// The doc data is just parents=blank-separated-list
|
179 |
// The doc data is just parents=blank-separated-list
|
|
... |
|
... |
235 |
explist.push_back(term);
|
231 |
explist.push_back(term);
|
236 |
return explist;
|
232 |
return explist;
|
237 |
}
|
233 |
}
|
238 |
Xapian::Document doc = sdb.get_document(*did);
|
234 |
Xapian::Document doc = sdb.get_document(*did);
|
239 |
string data = doc.get_data();
|
235 |
string data = doc.get_data();
|
|
|
236 |
|
|
|
237 |
// Build expansion list from database data
|
240 |
// No need for a conftree, but we need to massage the data a little
|
238 |
// No need for a conftree, but we need to massage the data a little
|
241 |
string::size_type pos = data.find_first_of("=");
|
239 |
string::size_type pos = data.find_first_of("=");
|
242 |
++pos;
|
240 |
++pos;
|
243 |
string::size_type pos1 = data.find_last_of("\n");
|
241 |
string::size_type pos1 = data.find_last_of("\n");
|
244 |
if (pos == string::npos || pos1 == string::npos ||pos1 <= pos) { // ??
|
242 |
if (pos == string::npos || pos1 == string::npos ||pos1 <= pos) { // ??
|
245 |
explist.push_back(term);
|
243 |
explist.push_back(term);
|
246 |
return explist;
|
244 |
return explist;
|
247 |
}
|
245 |
}
|
248 |
stringToStrings(data.substr(pos, pos1-pos), explist);
|
246 |
stringToStrings(data.substr(pos, pos1-pos), explist);
|
|
|
247 |
|
|
|
248 |
// If the user term itself is not in the list, add it.
|
249 |
if (find(explist.begin(), explist.end(), term) == explist.end()) {
|
249 |
if (find(explist.begin(), explist.end(), term) == explist.end()) {
|
250 |
explist.push_back(term);
|
250 |
explist.push_back(term);
|
251 |
}
|
251 |
}
|
252 |
LOGDEB(("stemExpand: %s -> %s\n", stem.c_str(),
|
252 |
LOGDEB(("stemExpand: %s -> %s\n", stem.c_str(),
|
253 |
stringlistdisp(explist).c_str()));
|
253 |
stringlistdisp(explist).c_str()));
|