";
+ for (unsigned int i = 0; i < in.length() ; i++) {
+ if (in[i] == '\n') {
+ out += "
";
+ } else {
+ out += in[i];
+ }
+ if (i == 10) {
+ out += "";
+ }
+ if (i == 20) {
+ out += "";
+ }
+
+ }
+ return out;
+}
void RecollMain::resTextEdit_clicked( int par, int car )
{
fprintf(stderr, "Clicked at paragraph %d, char %d\n", par, car);
-}
+ Rcl::Doc doc;
+ doc.erase();
+ if (rcldb->getDoc(par, doc)) {
+
+ // Go to the file system to retrieve / convert the document text
+ // for preview:
-#include "qfontdialog.h"
+ // Look for appropriate handler
+ MimeHandlerFunc fun =
+ getMimeHandler(doc.mimetype, rclconfig->getMimeConf());
+ if (!fun) {
+ QMessageBox::warning(0, "Recoll",
+ QString("No mime handler for mime type ") +
+ doc.mimetype.c_str());
+ return;
+ }
-#define BS 200000
-void RecollMain::resTextEdit_returnPressed()
-{
- fprintf(stderr, "ReturnPressed()\n");
- resTextEdit->setFont( QFontDialog::getFont( 0, resTextEdit->font() ) );
- const char *fname = "utf8.txt";
- FILE *fp = fopen(fname, "r");
- if (fp) {
- char buf[BS];
- memset(buf,0, sizeof(buf));
- int n = fread(buf, 1, BS-1, fp);
- fclose(fp);
- QString str = QString::fromUtf8(buf, n);
- resTextEdit->setTextFormat(RichText);
- resTextEdit->setText(str);
+ string fn = doc.url.substr(6, string::npos);
+ Rcl::Doc fdoc;
+ if (!fun(rclconfig, fn, doc.mimetype, fdoc)) {
+ QMessageBox::warning(0, "Recoll",
+ QString("Failed to convert document for preview!\n") +
+ fn.c_str() + " mimetype " +
+ doc.mimetype.c_str());
+ return;
+ }
+
+ string rich = plaintorich(fdoc.text);
+
+#if 0
+ //Highlighting; pass a list of (search term, style name) to plaintorich
+ // and create the corresponding styles with different colors here
+ // We need to :
+ // - Break the query into terms : wait for the query analyzer
+ // - Break the text into words. This should use a version of
+ // textsplit with an option to keep the punctuation (see how to do
+ // this). We do want the same splitter code to be used here and
+ // when indexing.
+ QStyleSheetItem *item =
+ new QStyleSheetItem( previewTextEdit->styleSheet(), "mytag" );
+ item->setColor("red");
+ item->setFontWeight(QFont::Bold);
+#endif
+ QString str = QString::fromUtf8(rich.c_str(), rich.length());
+
+ previewTextEdit->setTextFormat(RichText);
+ previewTextEdit->setText(str);
}
-
+}
+
+void RecollMain::queryText_returnPressed()
+{
+ LOGDEB(("RecollMain::queryText_returnPressed()\n"));
+ resTextEdit->clear();
+ previewTextEdit->clear();
+
+ string rawq = queryText->text();
+ rcldb->setQuery(rawq);
+ Rcl::Doc doc;
+
+ // Insert results if any in result list window
+ QString result;
+ resTextEdit->append("");
+ for (int i = 0;; i++) {
+ doc.erase();
+ if (!rcldb->getDoc(i, doc))
+ break;
+ LOGDEB(("Url: %s\n", doc.url.c_str()));
+ LOGDEB(("Mimetype: \n", doc.mimetype.c_str()));
+ LOGDEB(("Mtime: \n", doc.mtime.c_str()));
+ LOGDEB(("Origcharset: \n", doc.origcharset.c_str()));
+ LOGDEB(("Title: \n", doc.title.c_str()));
+ LOGDEB(("Text: \n", doc.text.c_str()));
+ LOGDEB(("Keywords: \n", doc.keywords.c_str()));
+ LOGDEB(("Abstract: \n", doc.abstract.c_str()));
+
+ result = "" + doc.url + "
";
+ resTextEdit->append(result);
+ }
+ resTextEdit->append("");
+
+ // Display preview for 1st doc in list
+ resTextEdit_clicked(0, 0);
+}
+
+
+void RecollMain::Search_clicked()
+{
+ queryText_returnPressed();
}
diff --git a/src/query/qtry.cpp b/src/query/qtry.cpp
index 971dc0d0..994b3169 100644
--- a/src/query/qtry.cpp
+++ b/src/query/qtry.cpp
@@ -1,5 +1,5 @@
#ifndef lint
-static char rcsid[] = "@(#$Id: qtry.cpp,v 1.2 2005-01-25 14:37:21 dockes Exp $ (C) 2004 J.F.Dockes";
+static char rcsid[] = "@(#$Id: qtry.cpp,v 1.3 2005-01-26 11:47:27 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
// Tests with the query interface
@@ -62,20 +62,20 @@ int main(int argc, char **argv)
if (argc < 1)
Usage();
- RclConfig *config = new RclConfig;
+ RclConfig *rclconfig = new RclConfig;
- if (!config->ok())
+ if (!rclconfig->ok())
cerr << "Config could not be built" << endl;
string dbdir;
- if (config->getConfParam(string("dbdir"), dbdir) == 0) {
+ if (rclconfig->getConfParam(string("dbdir"), dbdir) == 0) {
cerr << "No database directory in configuration" << endl;
exit(1);
}
- Rcl::Db *db = new Rcl::Db;
+ Rcl::Db *rcldb = new Rcl::Db;
- if (!db->open(dbdir, Rcl::Db::DbRO)) {
+ if (!rcldb->open(dbdir, Rcl::Db::DbRO)) {
fprintf(stderr, "Could not open database\n");
exit(1);
}
@@ -84,12 +84,12 @@ int main(int argc, char **argv)
string query;
while (argc--)
query += string(*argv++) + " " ;
- db->setQuery(query);
+ rcldb->setQuery(query);
int i = 0;
Rcl::Doc doc;
for (i=0;;i++) {
doc.erase();
- if (!db->getDoc(i, doc))
+ if (!rcldb->getDoc(i, doc))
break;
cout << "Url: " << doc.url << endl;
@@ -107,7 +107,7 @@ int main(int argc, char **argv)
// Look for appropriate handler
MimeHandlerFunc fun = getMimeHandler(doc.mimetype,
- config->getMimeConf());
+ rclconfig->getMimeConf());
if (!fun) {
cout << "No mime handler !" << endl;
continue;
@@ -116,7 +116,7 @@ int main(int argc, char **argv)
cout << "Filename: " << fn << endl;
Rcl::Doc fdoc;
- if (!fun(config, fn, doc.mimetype, fdoc)) {
+ if (!fun(rclconfig, fn, doc.mimetype, fdoc)) {
cout << "Failed to convert/preview document!" << endl;
continue;
}
@@ -125,7 +125,7 @@ int main(int argc, char **argv)
transcode(fdoc.text, printable, "UTF-8", outencoding);
cout << printable << endl;
}
- delete db;
+ delete rcldb;
cerr << "Exiting" << endl;
exit(0);
}
diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp
index a6d1a3f0..d6466d75 100644
--- a/src/rcldb/rcldb.cpp
+++ b/src/rcldb/rcldb.cpp
@@ -1,5 +1,5 @@
#ifndef lint
-static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.7 2005-01-25 14:37:21 dockes Exp $ (C) 2004 J.F.Dockes";
+static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.8 2005-01-26 11:47:27 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
#include
@@ -201,6 +201,7 @@ bool dumb_string(const string &in, string &out)
bool Rcl::Db::add(const string &fn, const Rcl::Doc &doc)
{
+ LOGDEB(("Rcl::Db::add: fn %s\n", fn.c_str()));
if (pdata == 0)
return false;
Native *ndb = (Native *)pdata;
@@ -226,24 +227,29 @@ bool Rcl::Db::add(const string &fn, const Rcl::Doc &doc)
string noacc;
if (!unac_cpp(doc.title, noacc)) {
+ LOGERR(("Rcl::Db::add: unac failed\n"));
return false;
}
splitter.text_to_words(noacc);
+ LOGDEB(("Rcl::Db::add: doc split\n"));
splitData.basepos += splitData.curpos + 100;
if (!dumb_string(doc.text, noacc)) {
+ LOGERR(("Rcl::Db::add: dum_string failed\n"));
return false;
}
splitter.text_to_words(noacc);
splitData.basepos += splitData.curpos + 100;
if (!dumb_string(doc.keywords, noacc)) {
+ LOGERR(("Rcl::Db::add: dum_string failed\n"));
return false;
}
splitter.text_to_words(noacc);
splitData.basepos += splitData.curpos + 100;
if (!dumb_string(doc.abstract, noacc)) {
+ LOGERR(("Rcl::Db::add: dum_string failed\n"));
return false;
}
splitter.text_to_words(noacc);
@@ -263,20 +269,20 @@ bool Rcl::Db::add(const string &fn, const Rcl::Doc &doc)
#if 0
if (did < updated.size()) {
updated[did] = true;
- LOGDEB1(("%s updated\n", fnc));
+ LOGDEB(("%s updated\n", fnc));
} else {
- LOGDEB1(("%s added\n", fnc));
+ LOGDEB(("%s added\n", fnc));
}
#endif
} catch (...) {
// FIXME: is this ever actually needed?
ndb->wdb.add_document(newdocument);
- LOGDEB1(("%s added (failed re-seek for duplicate).\n", fnc));
+ LOGDEB(("%s added (failed re-seek for duplicate).\n", fnc));
}
} else {
try {
ndb->wdb.add_document(newdocument);
- LOGDEB1(("%s added\n", fnc));
+ LOGDEB(("%s added\n", fnc));
} catch (...) {
LOGERR(("%s : Got exception while adding doc\n", fnc));
return false;
diff --git a/src/utils/Makefile b/src/utils/Makefile
index 1c0ae9bf..0697fd95 100644
--- a/src/utils/Makefile
+++ b/src/utils/Makefile
@@ -3,7 +3,7 @@ CXXFLAGS = -I.
BIGLIB = ../lib/librcl.a
-PROGS = trfstreewalk trpathut execmd transcode
+PROGS = trfstreewalk trpathut execmd transcode trmimeparse
all: $(PROGS)
FSTREEWALK_OBJS= trfstreewalk.o fstreewalk.o pathut.o
@@ -30,5 +30,13 @@ transcode : $(TRANSCODE_OBJS)
trtranscode.o : ../utils/transcode.cpp
$(CXX) $(CXXFLAGS) -DTEST_TRANSCODE -c -o trtranscode.o \
transcode.cpp
+
+MIMEPARSE_OBJS= trmimeparse.o $(BIGLIB)
+mimeparse : $(MIMEPARSE_OBJS)
+ $(CXX) $(CXXFLAGS) -o mimeparse $(MIMEPARSE_OBJS) \
+ -L/usr/local/lib -liconv
+trmimeparse.o : ../utils/mimeparse.cpp
+ $(CXX) $(CXXFLAGS) -DTEST_MIMEPARSE -c -o trmimeparse.o \
+ mimeparse.cpp
clean:
rm -f *.o $(PROGS)