fix queryBuildAbstract option functionality. Allow substituting %(fieldname) in reslist paragraph format

This commit is contained in:
dockes 2009-10-21 12:02:59 +00:00
parent 0cf33ede6b
commit fb2994ea74
8 changed files with 121 additions and 37 deletions

View File

@ -529,6 +529,9 @@ void RclMain::startSearch(RefCntr<Rcl::SearchData> sdata)
DocSequenceDb *src = DocSequenceDb *src =
new DocSequenceDb(RefCntr<Rcl::Query>(query), new DocSequenceDb(RefCntr<Rcl::Query>(query),
string(tr("Query results").utf8()), sdata); string(tr("Query results").utf8()), sdata);
src->setAbstractParams(prefs.queryBuildAbstract,
prefs.queryReplaceAbstract);
resList->setDocSource(RefCntr<DocSequence>(src)); resList->setDocSource(RefCntr<DocSequence>(src));
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }

View File

@ -27,7 +27,9 @@ static char rcsid[] = "@(#$Id: docseqdb.cpp,v 1.9 2008-11-13 10:57:46 dockes Exp
DocSequenceDb::DocSequenceDb(RefCntr<Rcl::Query> q, const string &t, DocSequenceDb::DocSequenceDb(RefCntr<Rcl::Query> q, const string &t,
RefCntr<Rcl::SearchData> sdata) RefCntr<Rcl::SearchData> sdata)
: DocSequence(t), m_q(q), m_sdata(sdata), m_fsdata(sdata), : DocSequence(t), m_q(q), m_sdata(sdata), m_fsdata(sdata),
m_rescnt(-1), m_filt(false) m_rescnt(-1), m_filt(false),
m_queryBuildAbstract(true),
m_queryReplaceAbstract(false)
{ {
} }
@ -66,7 +68,13 @@ string DocSequenceDb::getAbstract(Rcl::Doc &doc)
if (!m_q->whatDb()) if (!m_q->whatDb())
return doc.meta[Rcl::Doc::keyabs]; return doc.meta[Rcl::Doc::keyabs];
string abstract; string abstract;
m_q->whatDb()->makeDocAbstract(doc, m_q.getptr(), abstract);
if (m_queryBuildAbstract && (doc.syntabs || m_queryReplaceAbstract)) {
m_q->whatDb()->makeDocAbstract(doc, m_q.getptr(), abstract);
} else {
abstract = doc.meta[Rcl::Doc::keyabs];
}
return abstract.empty() ? doc.meta[Rcl::Doc::keyabs] : abstract; return abstract.empty() ? doc.meta[Rcl::Doc::keyabs] : abstract;
} }

View File

@ -43,12 +43,20 @@ class DocSequenceDb : public DocSequence {
virtual bool canSort() {return false;} virtual bool canSort() {return false;}
virtual bool setSortSpec(DocSeqSortSpec &sortspec); virtual bool setSortSpec(DocSeqSortSpec &sortspec);
virtual string title(); virtual string title();
virtual void setAbstractParams(bool qba, bool qra)
{
m_queryBuildAbstract = qba;
m_queryReplaceAbstract = qra;
}
private: private:
RefCntr<Rcl::Query> m_q; RefCntr<Rcl::Query> m_q;
RefCntr<Rcl::SearchData> m_sdata; RefCntr<Rcl::SearchData> m_sdata;
RefCntr<Rcl::SearchData> m_fsdata; // Filtered RefCntr<Rcl::SearchData> m_fsdata; // Filtered
int m_rescnt; int m_rescnt;
bool m_filt; bool m_filt;
bool m_queryBuildAbstract;
bool m_queryReplaceAbstract;
}; };
#endif /* _DOCSEQDB_H_INCLUDED_ */ #endif /* _DOCSEQDB_H_INCLUDED_ */

View File

@ -201,12 +201,8 @@ void ResListPager::displayPage()
sizebuf = displayableBytes(fsize); sizebuf = displayableBytes(fsize);
} }
string abstract; string abstract = m_docSource->getAbstract(doc);
if (m_queryBuildAbstract && (doc.syntabs || m_queryReplaceAbstract)) {
abstract = m_docSource->getAbstract(doc);
} else {
abstract = doc.meta[Rcl::Doc::keyabs];
}
// No need to call escapeHtml(), plaintorich handles it // No need to call escapeHtml(), plaintorich handles it
list<string> lr; list<string> lr;
m_hiliter->set_inputhtml(false); m_hiliter->set_inputhtml(false);
@ -237,20 +233,23 @@ void ResListPager::displayPage()
chunk += "<p>"; chunk += "<p>";
// Configurable stuff // Configurable stuff
map<char,string> subs; map<string,string> subs;
subs['A'] = !richabst.empty() ? richabst + "<br>" : ""; subs["A"] = !richabst.empty() ? richabst + "<br>" : "";
subs['D'] = datebuf; subs["D"] = datebuf;
subs['I'] = iconpath; subs["I"] = iconpath;
subs['i'] = doc.ipath; subs["i"] = doc.ipath;
subs['K'] = !doc.meta[Rcl::Doc::keykw].empty() ? subs["K"] = !doc.meta[Rcl::Doc::keykw].empty() ?
escapeHtml(doc.meta[Rcl::Doc::keykw]) + "<br>" : ""; escapeHtml(doc.meta[Rcl::Doc::keykw]) + "<br>" : "";
subs['L'] = linksbuf; subs["L"] = linksbuf;
subs['N'] = numbuf; subs["N"] = numbuf;
subs['M'] = doc.mimetype; subs["M"] = doc.mimetype;
subs['R'] = perbuf; subs["R"] = perbuf;
subs['S'] = sizebuf; subs["S"] = sizebuf;
subs['T'] = escapeHtml(doc.meta[Rcl::Doc::keytt]); subs["T"] = escapeHtml(doc.meta[Rcl::Doc::keytt]);
subs['U'] = url; subs["U"] = url;
// Let %(xx) access all metadata.
subs.insert(doc.meta.begin(), doc.meta.end());
string formatted; string formatted;
pcSubst(parFormat(), formatted, subs); pcSubst(parFormat(), formatted, subs);
@ -281,10 +280,13 @@ void ResListPager::displayPage()
append(chunk); append(chunk);
} }
// Default implementations for things that should be implemented by
// specializations
string ResListPager::nextUrl() string ResListPager::nextUrl()
{ {
return "n-1"; return "n-1";
} }
string ResListPager::prevUrl() string ResListPager::prevUrl()
{ {
return "p-1"; return "p-1";
@ -298,7 +300,6 @@ string ResListPager::iconPath(const string& mtype)
return iconpath; return iconpath;
} }
// Default implementations for things that should be re-implemented by our user.
bool ResListPager::append(const string& data) bool ResListPager::append(const string& data)
{ {
fprintf(stderr, "%s", data.c_str()); fprintf(stderr, "%s", data.c_str());

View File

@ -16,12 +16,6 @@ class PlainToRich;
class ResListPager { class ResListPager {
public: public:
ResListPager(int pagesize=10) : m_pagesize(pagesize) {initall();} ResListPager(int pagesize=10) : m_pagesize(pagesize) {initall();}
ResListPager(RefCntr<DocSequence> src, int pagesize)
: m_pagesize(pagesize)
{
initall();
m_docSource = src;
}
virtual ~ResListPager() {} virtual ~ResListPager() {}
void setHighLighter(PlainToRich *ptr) {m_hiliter = ptr;} void setHighLighter(PlainToRich *ptr) {m_hiliter = ptr;}
@ -79,8 +73,6 @@ private:
m_winfirst = -1; m_winfirst = -1;
m_hasNext = false; m_hasNext = false;
m_respage.clear(); m_respage.clear();
m_queryBuildAbstract = true;
m_queryReplaceAbstract = false;
m_hiliter = 0; m_hiliter = 0;
} }
@ -91,8 +83,6 @@ private:
bool m_hasNext; bool m_hasNext;
vector<ResListEntry> m_respage; vector<ResListEntry> m_respage;
bool m_queryBuildAbstract;
bool m_queryReplaceAbstract;
PlainToRich *m_hiliter; PlainToRich *m_hiliter;
}; };

View File

@ -72,12 +72,14 @@ trmimeparse.o : mimeparse.cpp
$(CXX) $(ALL_CXXFLAGS) -DTEST_MIMEPARSE -c -o trmimeparse.o \ $(CXX) $(ALL_CXXFLAGS) -DTEST_MIMEPARSE -c -o trmimeparse.o \
mimeparse.cpp mimeparse.cpp
SMALLUT_OBJS= trsmallut.o $(BIGLIB) SMALLUT_OBJS= trsmallut.o ../lib/smallut.o
smallut : $(SMALLUT_OBJS) smallut : $(SMALLUT_OBJS) smallut.h
$(CXX) $(ALL_CXXFLAGS) -o smallut $(SMALLUT_OBJS) $(LIBICONV) $(CXX) $(ALL_CXXFLAGS) -o smallut $(SMALLUT_OBJS) $(LIBICONV)
trsmallut.o : smallut.cpp trsmallut.o : smallut.cpp smallut.h
$(CXX) $(ALL_CXXFLAGS) -DTEST_SMALLUT -c -o trsmallut.o \ $(CXX) $(ALL_CXXFLAGS) -DTEST_SMALLUT -c -o trsmallut.o \
smallut.cpp smallut.cpp
../lib/smallut.o: smallut.cpp smallut.h
cd ../lib;make smallut.o
WIPEDIR_OBJS= trwipedir.o $(BIGLIB) WIPEDIR_OBJS= trwipedir.o $(BIGLIB)
wipedir : $(WIPEDIR_OBJS) wipedir : $(WIPEDIR_OBJS)

View File

@ -492,7 +492,8 @@ bool pcSubst(const string& in, string& out, map<char, string>& subs)
if ((tr = subs.find(*it)) != subs.end()) { if ((tr = subs.find(*it)) != subs.end()) {
out += tr->second; out += tr->second;
} else { } else {
out += *it; // We used to do "out += *it;" here but this does not make
// sense
} }
} else { } else {
out += *it; out += *it;
@ -501,6 +502,52 @@ bool pcSubst(const string& in, string& out, map<char, string>& subs)
return true; return true;
} }
bool pcSubst(const string& in, string& out, map<string, string>& subs)
{
out.erase();
string::size_type i;
for (i = 0; i < in.size(); i++) {
if (in[i] == '%') {
if (++i == in.size()) {
out += '%';
break;
}
if (in[i] == '%') {
out += '%';
continue;
}
string key = "";
if (in[i] == '(') {
if (++i == in.size()) {
out += string("%(");
break;
}
string::size_type j = in.find_first_of(")", i);
if (j == string::npos) {
// ??concatenate remaining part and stop
out += in.substr(i-2);
break;
}
key = in.substr(i, j-i);
i = j;
} else {
key = in[i];
}
map<string,string>::iterator tr;
if ((tr = subs.find(key)) != subs.end()) {
out += tr->second;
} else {
// Substitute to nothing, that's the reasonable thing to do
// instead of keeping the %(key)
// out += key.size()==1? key : string("(") + key + string(")");
}
} else {
out += in[i];
}
}
return true;
}
// Convert byte count into unit (KB/MB...) appropriate for display // Convert byte count into unit (KB/MB...) appropriate for display
string displayableBytes(long size) string displayableBytes(long size)
{ {
@ -712,11 +759,34 @@ int main(int argc, char **argv)
utf8truncate(testit, sz); utf8truncate(testit, sz);
cout << testit << endl; cout << testit << endl;
} }
#elif 1 #elif 0
std::string testit("ligne\ndeuxieme ligne\r3eme ligne\r\n"); std::string testit("ligne\ndeuxieme ligne\r3eme ligne\r\n");
cout << "[" << neutchars(testit, "\r\n") << "]" << endl; cout << "[" << neutchars(testit, "\r\n") << "]" << endl;
string i, o; string i, o;
cout << "neutchars(null) is [" << neutchars(i, "\r\n") << "]" << endl; cout << "neutchars(null) is [" << neutchars(i, "\r\n") << "]" << endl;
#elif 1
map<string, string> substs;
substs["a"] = "A_SUBST";
substs["title"] = "TITLE_SUBST";
string in = "a: %a title: %(title) pcpc: %% %";
string out;
pcSubst(in, out, substs);
cout << in << " => " << out << endl;
in = "unfinished: %(unfinished";
pcSubst(in, out, substs);
cout << in << " => " << out << endl;
in = "unfinished: %(";
pcSubst(in, out, substs);
cout << in << " => " << out << endl;
in = "empty: %()";
pcSubst(in, out, substs);
cout << in << " => " << out << endl;
substs.clear();
in = "a: %a title: %(title) pcpc: %% %";
pcSubst(in, out, substs);
cout << "After map clear: " << in << " => " << out << endl;
#endif #endif
} }

View File

@ -102,6 +102,8 @@ string breakIntoLines(const string& in, unsigned int ll = 100,
unsigned int maxlines= 50); unsigned int maxlines= 50);
/** Small utility to substitute printf-like percents cmds in a string */ /** Small utility to substitute printf-like percents cmds in a string */
bool pcSubst(const string& in, string& out, map<char, string>& subs); bool pcSubst(const string& in, string& out, map<char, string>& subs);
/** Substitute printf-like percents and also %(key) */
bool pcSubst(const string& in, string& out, map<string, string>& subs);
class Chrono { class Chrono {
public: public: