colorize search terms in abstracts

This commit is contained in:
dockes
2006-09-13 14:57:56 +00:00
parent b536c9c46c
commit 347fa3f962
5 changed files with 51 additions and 18 deletions
+6 -3
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.10 2006-02-07 09:44:33 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.11 2006-09-13 14:57:56 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@@ -83,7 +83,7 @@ class myTextSplitCB : public TextSplitCB {
// we return the first term encountered, and the caller will use the
// editor's find() function to position on it
bool plaintorich(const string& in, string& out, const list<string>& terms,
string *firstTerm)
string *firstTerm, bool noHeader)
{
Chrono chron;
LOGDEB(("plaintorich: terms: %s\n",
@@ -104,7 +104,10 @@ bool plaintorich(const string& in, string& out, const list<string>& terms,
LOGDEB(("plaintorich: split done %d mS\n", chron.millis()));
// Rich text output
out = "<qt><head><title></title></head><body><p>";
if (noHeader)
out = "";
else
out = "<qt><head><title></title></head><body><p>";
// Iterator for the list of input term positions. We use it to
// output highlight tags and to compute term positions in the
+6 -4
View File
@@ -16,7 +16,7 @@
*/
#ifndef _PLAINTORICH_H_INCLUDED_
#define _PLAINTORICH_H_INCLUDED_
/* @(#$Id: plaintorich.h,v 1.6 2006-02-07 09:44:33 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: plaintorich.h,v 1.7 2006-09-13 14:57:56 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
@@ -27,11 +27,13 @@
* colorize the query terms.
*
* @param in raw text out of internfile.
* @param terms list of query terms
* @param termoffsets output: character offsets where we find terms.
* @param out rich text output
* @param terms list of query terms. These are out of Rcl::Db and dumb
* @param firstTerm out: value of the first search term in text.
* @param noHeader if true don't output header (<qt><title>...)
*/
extern bool plaintorich(const string &in, string &out,
const list<string>& terms,
string* firstTerm);
string* firstTerm, bool noHeader = false);
#endif /* _PLAINTORICH_H_INCLUDED_ */
+13 -2
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rclreslist.cpp,v 1.18 2006-09-12 10:11:36 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: rclreslist.cpp,v 1.19 2006-09-13 14:57:56 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
#include <time.h>
@@ -22,6 +22,7 @@ static char rcsid[] = "@(#$Id: rclreslist.cpp,v 1.18 2006-09-12 10:11:36 dockes
#include "transcode.h"
#include "pathut.h"
#include "mimehandler.h"
#include "plaintorich.h"
#include "rclreslist.h"
#include "moc_rclreslist.cpp"
@@ -253,6 +254,14 @@ void RclResList::resultPageNext()
m_curDocs.clear();
// Query term colorization
QStyleSheetItem *item =
new QStyleSheetItem(styleSheet(), "termtag" );
item->setColor("blue");
// item->setFontWeight(QFont::Bold);
list<string> qTerms;
m_docsource->getTerms(qTerms);
// Insert results if any in result list window. We have to send
// the text to the widgets, because we need the paragraph number
// each time we add a result paragraph (its diffult and
@@ -357,7 +366,9 @@ void RclResList::resultPageNext()
}
// Abstract
string abst = escapeHtml(doc.abstract);
string abst;
plaintorich(doc.abstract, abst, qTerms, 0, true);
//string abst = escapeHtml(doc.abstract);
LOGDEB1(("Abstract: {%s}\n", abst.c_str()));
// Concatenate chunks to build the result list paragraph: