fnmatch() errors encountered with charset conversion errors on file names were treated as matches
This commit is contained in:
parent
e7eafe4ab4
commit
60b9845b83
4 changed files with 39 additions and 12 deletions
|
@ -168,10 +168,10 @@ bool Db::termMatch(int typ_sens, const string &lang, const string &_term,
|
||||||
stripped = o_index_stripchars;
|
stripped = o_index_stripchars;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LOGDEB(("Db::TermMatch: typ %s diacsens %d casesens %d lang [%s] term [%s] "
|
LOGDEB0(("Db::TermMatch: typ %s diacsens %d casesens %d lang [%s] term [%s]"
|
||||||
"max %d field [%s] stripped %d\n",
|
" max %d field [%s] stripped %d init res.size %u\n",
|
||||||
tmtptostr(matchtyp), diac_sensitive, case_sensitive, lang.c_str(),
|
tmtptostr(matchtyp), diac_sensitive, case_sensitive, lang.c_str(),
|
||||||
_term.c_str(), max, field.c_str(), stripped));
|
_term.c_str(), max, field.c_str(), stripped, res.entries.size()));
|
||||||
|
|
||||||
// If index is stripped, no case or diac expansion can be needed:
|
// If index is stripped, no case or diac expansion can be needed:
|
||||||
// for the processing inside this routine, everything looks like
|
// for the processing inside this routine, everything looks like
|
||||||
|
@ -224,7 +224,7 @@ bool Db::termMatch(int typ_sens, const string &lang, const string &_term,
|
||||||
it != exp.end(); it++) {
|
it != exp.end(); it++) {
|
||||||
idxTermMatch(ET_NONE, "", *it, res, max, field);
|
idxTermMatch(ET_NONE, "", *it, res, max, field);
|
||||||
}
|
}
|
||||||
// And also expand the original expresionn against the
|
// And also expand the original expression against the
|
||||||
// main index: for the common case where the expression
|
// main index: for the common case where the expression
|
||||||
// had no case/diac expansion (no entry in the exp db if
|
// had no case/diac expansion (no entry in the exp db if
|
||||||
// the original term is lowercase and without accents).
|
// the original term is lowercase and without accents).
|
||||||
|
@ -320,6 +320,10 @@ bool Db::idxTermMatch(int typ_sens, const string &lang, const string &root,
|
||||||
TermMatchResult& res, int max, const string& field)
|
TermMatchResult& res, int max, const string& field)
|
||||||
{
|
{
|
||||||
int typ = matchTypeTp(typ_sens);
|
int typ = matchTypeTp(typ_sens);
|
||||||
|
LOGDEB1(("Db::idxTermMatch: typ %s lang [%s] term [%s] "
|
||||||
|
"max %d field [%s] init res.size %u\n",
|
||||||
|
tmtptostr(typ), lang.c_str(), root.c_str(),
|
||||||
|
max, field.c_str(), res.entries.size()));
|
||||||
|
|
||||||
#ifndef RCL_INDEX_STRIPCHARS
|
#ifndef RCL_INDEX_STRIPCHARS
|
||||||
if (typ == ET_STEM) {
|
if (typ == ET_STEM) {
|
||||||
|
@ -380,6 +384,10 @@ bool Db::idxTermMatch(int typ_sens, const string &lang, const string &root,
|
||||||
if (matcher.isNotNull()) {
|
if (matcher.isNotNull()) {
|
||||||
es = matcher->baseprefixlen();
|
es = matcher->baseprefixlen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initial section: the part of the prefix+expr before the
|
||||||
|
// first wildcard character. We only scan the part of the
|
||||||
|
// index where this matches
|
||||||
string is;
|
string is;
|
||||||
switch (es) {
|
switch (es) {
|
||||||
case string::npos: is = prefix + root; break;
|
case string::npos: is = prefix + root; break;
|
||||||
|
@ -395,14 +403,23 @@ bool Db::idxTermMatch(int typ_sens, const string &lang, const string &root,
|
||||||
it.skip_to(is.c_str());
|
it.skip_to(is.c_str());
|
||||||
for (int rcnt = 0; it != xdb.allterms_end(); it++) {
|
for (int rcnt = 0; it != xdb.allterms_end(); it++) {
|
||||||
// If we're beyond the terms matching the initial
|
// If we're beyond the terms matching the initial
|
||||||
// string, end
|
// section, end
|
||||||
if (!is.empty() && (*it).find(is) != 0)
|
if (!is.empty() && (*it).find(is) != 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Else try to match the term. The matcher content
|
||||||
|
// is without prefix, so we remove this if any. We
|
||||||
|
// just checked that the index term did begin with
|
||||||
|
// the prefix.
|
||||||
string term;
|
string term;
|
||||||
if (!prefix.empty())
|
if (!prefix.empty()) {
|
||||||
term = (*it).substr(prefix.length());
|
term = (*it).substr(prefix.length());
|
||||||
else
|
} else {
|
||||||
|
if (has_prefix(*it)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
term = *it;
|
term = *it;
|
||||||
|
}
|
||||||
|
|
||||||
if (matcher.isNotNull() && !matcher->match(term))
|
if (matcher.isNotNull() && !matcher->match(term))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -622,7 +622,7 @@ bool SearchDataClauseSimple::expandTerm(Rcl::Db &db,
|
||||||
if (noexpansion) {
|
if (noexpansion) {
|
||||||
oexp.push_back(prefix + term);
|
oexp.push_back(prefix + term);
|
||||||
m_hldata.terms[term] = m_hldata.uterms.size() - 1;
|
m_hldata.terms[term] = m_hldata.uterms.size() - 1;
|
||||||
LOGDEB(("ExpandTerm: final: %s\n", stringsToString(oexp).c_str()));
|
LOGDEB(("ExpandTerm: noexpansion: final: %s\n", stringsToString(oexp).c_str()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ bool XapComputableSynFamMember::synKeyExpand(StrMatcher* inexp,
|
||||||
if (filter_exp.isNotNull()) {
|
if (filter_exp.isNotNull()) {
|
||||||
string term1 = (*filtertrans)(term);
|
string term1 = (*filtertrans)(term);
|
||||||
LOGDEB2((" Testing [%s] against [%s]\n",
|
LOGDEB2((" Testing [%s] against [%s]\n",
|
||||||
term1.c_str(), filter_exp.c_str()));
|
term1.c_str(), filter_exp->exp().c_str()));
|
||||||
if (!filter_exp->match(term1)) {
|
if (!filter_exp->match(term1)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,22 @@
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
#include "cstr.h"
|
#include "cstr.h"
|
||||||
|
#include "debuglog.h"
|
||||||
#include "strmatcher.h"
|
#include "strmatcher.h"
|
||||||
|
|
||||||
bool StrWildMatcher::match(const string& val) const
|
bool StrWildMatcher::match(const string& val) const
|
||||||
{
|
{
|
||||||
return fnmatch(m_sexp.c_str(), val.c_str(), 0) != FNM_NOMATCH;
|
LOGDEB2(("StrWildMatcher::match: [%s] against [%s]\n",
|
||||||
|
m_sexp.c_str(), val.c_str()));
|
||||||
|
int ret = fnmatch(m_sexp.c_str(), val.c_str(), FNM_NOESCAPE);
|
||||||
|
switch (ret) {
|
||||||
|
case 0: return true;
|
||||||
|
case FNM_NOMATCH: return false;
|
||||||
|
default:
|
||||||
|
LOGDEB0(("StrWildMatcher::match error: [%s] against [%s]\n",
|
||||||
|
m_sexp.c_str(), val.c_str()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string::size_type StrWildMatcher::baseprefixlen() const
|
string::size_type StrWildMatcher::baseprefixlen() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue