cleanup docseq, arrange things so that we can page reslist past the initial result count estimate if there are more
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.22 2007-01-13 15:21:41 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.23 2007-01-19 10:32:39 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -67,6 +67,8 @@ using std::pair;
|
||||
#include "ssearch_w.h"
|
||||
#include "execmd.h"
|
||||
#include "internfile.h"
|
||||
#include "docseqdb.h"
|
||||
#include "docseqhist.h"
|
||||
|
||||
#include "rclmain_w.h"
|
||||
#include "moc_rclmain_w.cpp"
|
||||
@@ -825,11 +827,15 @@ void RclMain::startManual()
|
||||
// Search for document 'like' the selected one.
|
||||
void RclMain::docExpand(int docnum)
|
||||
{
|
||||
if (!rcldb)
|
||||
return;
|
||||
Rcl::Doc doc;
|
||||
if (!resList->getDoc(docnum, doc))
|
||||
return;
|
||||
list<string> terms;
|
||||
terms = rcldb->expand(doc);
|
||||
if (terms.empty())
|
||||
return;
|
||||
// Do we keep the original query. I think we'd better not.
|
||||
// rcldb->expand is set to keep the original query terms instead.
|
||||
QString text;// = sSearch->queryText->currentText();
|
||||
|
||||
+119
-123
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: reslist.cpp,v 1.19 2007-01-12 09:01:11 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: reslist.cpp,v 1.20 2007-01-19 10:32:39 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
@@ -125,16 +125,20 @@ int ResList::parnumfromdocnum(int docnum)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Return doc from current or adjacent result pages
|
||||
// Return doc from current or adjacent result pages. We can get called
|
||||
// for a document not in the current page if the user browses through
|
||||
// results inside a result window (with shift-arrow). This can only
|
||||
// result in a one-page change.
|
||||
bool ResList::getDoc(int docnum, Rcl::Doc &doc)
|
||||
{
|
||||
LOGDEB(("ResList::getDoc: docnum %d m_winfirst %d\n", docnum, m_winfirst));
|
||||
if (docnum < 0)
|
||||
return false;
|
||||
// Is docnum in current page ? Then all Ok
|
||||
if (docnum >= int(m_winfirst) &&
|
||||
docnum < int(m_winfirst + m_curDocs.size())) {
|
||||
doc = m_curDocs[docnum - m_winfirst];
|
||||
goto found;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Else we accept to page down or up but not further
|
||||
@@ -148,12 +152,9 @@ bool ResList::getDoc(int docnum, Rcl::Doc &doc)
|
||||
if (docnum >= int(m_winfirst) &&
|
||||
docnum < int(m_winfirst + m_curDocs.size())) {
|
||||
doc = m_curDocs[docnum - m_winfirst];
|
||||
goto found;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
found:
|
||||
return true;
|
||||
}
|
||||
|
||||
void ResList::keyPressEvent(QKeyEvent * e)
|
||||
@@ -249,6 +250,7 @@ static string displayableBytes(long size)
|
||||
// Fill up result list window with next screen of hits
|
||||
void ResList::resultPageNext()
|
||||
{
|
||||
// This checks that the RefCntr pseudo-pointer is not holding a null.
|
||||
if (m_docSource.getcnt() == 0)
|
||||
return;
|
||||
|
||||
@@ -258,91 +260,118 @@ void ResList::resultPageNext()
|
||||
LOGDEB(("resultPageNext: rescnt %d, winfirst %d\n", resCnt,
|
||||
m_winfirst));
|
||||
|
||||
// If we are already on the last page, nothing to do:
|
||||
if (m_winfirst >= 0 &&
|
||||
(m_winfirst + prefs.respagesize > resCnt)) {
|
||||
emit nextPageAvailable(false);
|
||||
return;
|
||||
}
|
||||
|
||||
bool hasPrev = false;
|
||||
if (m_winfirst < 0) {
|
||||
m_winfirst = 0;
|
||||
} else {
|
||||
hasPrev = true;
|
||||
m_winfirst += prefs.respagesize;
|
||||
}
|
||||
if (m_winfirst)
|
||||
hasPrev = true;
|
||||
emit prevPageAvailable(hasPrev);
|
||||
|
||||
bool gotone = false;
|
||||
// Get the next page of results.
|
||||
vector<ResListEntry> respage;
|
||||
int pagelen = m_docSource->getSeqSlice(m_winfirst,
|
||||
prefs.respagesize, respage);
|
||||
|
||||
// If page was truncated, there is no next
|
||||
bool hasNext = pagelen == prefs.respagesize;
|
||||
emit nextPageAvailable(hasNext);
|
||||
|
||||
if (pagelen <= 0) {
|
||||
// No results ? This can only happen on the first page or if the
|
||||
// actual result list size is a multiple of the page pref (else
|
||||
// there would have been no Next on the last page)
|
||||
if (m_winfirst) {
|
||||
// Have already results. Let them show, just disable the
|
||||
// Next button. We'd need to remove the Next link from the page
|
||||
// too.
|
||||
// Restore the m_winfirst value
|
||||
m_winfirst -= prefs.respagesize;
|
||||
return;
|
||||
}
|
||||
clear();
|
||||
QString chunk = "<qt><head></head><body><p>";
|
||||
chunk += "<p><font size=+1><b>";
|
||||
chunk += QString::fromUtf8(m_docSource->title().c_str());
|
||||
chunk += "</b></font><br>";
|
||||
chunk += "<a href=\"H-1\">";
|
||||
chunk += tr("Show query details");
|
||||
chunk += "</a><br>";
|
||||
append(chunk);
|
||||
append(tr("<p><b>No results found</b><br>"));
|
||||
if (m_winfirst < 0)
|
||||
m_winfirst = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
clear();
|
||||
|
||||
int last = MIN(resCnt - m_winfirst, prefs.respagesize);
|
||||
|
||||
m_curDocs.clear();
|
||||
|
||||
// Query term colorization
|
||||
QStyleSheetItem *item =
|
||||
new QStyleSheetItem(styleSheet(), "termtag" );
|
||||
QStyleSheetItem *item = new QStyleSheetItem(styleSheet(), "termtag" );
|
||||
item->setColor("blue");
|
||||
// item->setFontWeight(QFont::Bold);
|
||||
|
||||
// Result paragraph format
|
||||
string sformat = string(prefs.reslistformat.utf8());
|
||||
LOGDEB(("resultPageNext: format: [%s]\n", sformat.c_str()));
|
||||
|
||||
// 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
|
||||
// error-prone to compute the paragraph numbers in parallel). We
|
||||
// would like to disable updates while we're doing this, but
|
||||
// couldn't find a way to make it work, the widget seems to become
|
||||
// confused if appended while updates are disabled
|
||||
// Display list header
|
||||
// We could use a <title> but the textedit doesnt display
|
||||
// it prominently
|
||||
// Note: have to append text in chunks that make sense
|
||||
// html-wise. If we break things up to much, the editor
|
||||
// gets confused. Hence the use of the 'chunk' text
|
||||
// accumulator
|
||||
// Also note that there can be results beyond the estimated resCnt.
|
||||
QString chunk = "<qt><head></head><body><p>";
|
||||
|
||||
chunk += "<font size=+1><b>";
|
||||
chunk += QString::fromUtf8(m_docSource->title().c_str());
|
||||
chunk += ".</b></font>";
|
||||
|
||||
chunk += " ";
|
||||
|
||||
if (m_winfirst + pagelen < resCnt) {
|
||||
chunk +=
|
||||
tr("Documents <b>%1-%2</b> out of at least <b>%3</b> for ")
|
||||
.arg(m_winfirst+1)
|
||||
.arg(m_winfirst+pagelen)
|
||||
.arg(resCnt);
|
||||
} else {
|
||||
chunk += tr("Documents <b>%1-%2</b> for ")
|
||||
.arg(m_winfirst+1)
|
||||
.arg(m_winfirst+pagelen);
|
||||
}
|
||||
|
||||
chunk += "<a href=\"H-1\">";
|
||||
chunk += tr("(show query)");
|
||||
chunk += "</a>";
|
||||
|
||||
append(chunk);
|
||||
|
||||
// Insert results in result list window. We have to actually send
|
||||
// the text to the widget (instead of setting the whole at the
|
||||
// end), because we need the paragraph number each time we add a
|
||||
// result paragraph (its diffult and error-prone to compute the
|
||||
// paragraph numbers in parallel). We would like to disable
|
||||
// updates while we're doing this, but couldn't find a way to make
|
||||
// it work, the widget seems to become confused if appended while
|
||||
// updates are disabled
|
||||
// setUpdatesEnabled(false);
|
||||
for (int i = 0; i < last; i++) {
|
||||
string sh;
|
||||
Rcl::Doc doc;
|
||||
int percent;
|
||||
if (!m_docSource->getDoc(m_winfirst + i, doc, &percent, &sh)) {
|
||||
// Error or end of docs, stop.
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < pagelen; i++) {
|
||||
|
||||
int &percent(respage[i].percent);
|
||||
Rcl::Doc &doc(respage[i].doc);
|
||||
string& sh(respage[i].subHeader);
|
||||
|
||||
if (percent == -1) {
|
||||
percent = 0;
|
||||
// Document not available, maybe other further, will go on.
|
||||
doc.abstract = string(tr("Unavailable document").utf8());
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
// Display list header
|
||||
// We could use a <title> but the textedit doesnt display
|
||||
// it prominently
|
||||
// Note: have to append text in chunks that make sense
|
||||
// html-wise. If we break things up to much, the editor
|
||||
// gets confused. Hence the use of the 'chunk' text
|
||||
// accumulator
|
||||
QString chunk = "<qt><head></head><body><p>";
|
||||
|
||||
chunk += "<font size=+1><b>";
|
||||
chunk += QString::fromUtf8(m_docSource->title().c_str());
|
||||
chunk += ".</b></font>";
|
||||
|
||||
chunk += " ";
|
||||
|
||||
chunk += tr("Documents <b>%1-%2</b> out of <b>%3</b> for ")
|
||||
.arg(m_winfirst+1)
|
||||
.arg(m_winfirst+last)
|
||||
.arg(resCnt);
|
||||
|
||||
chunk += "<a href=\"H-1\">";
|
||||
chunk += tr("(show query)");
|
||||
chunk += "</a>";
|
||||
|
||||
append(chunk);
|
||||
}
|
||||
|
||||
gotone = true;
|
||||
|
||||
// Determine icon to display if any
|
||||
string img_name;
|
||||
if (prefs.showicons) {
|
||||
@@ -373,7 +402,7 @@ void ResList::resultPageNext()
|
||||
|
||||
// Result number
|
||||
char numbuf[20];
|
||||
int docnumforlinks = m_winfirst+1+i;
|
||||
int docnumforlinks = m_winfirst + 1 + i;
|
||||
sprintf(numbuf, "%d", docnumforlinks);
|
||||
|
||||
// Document date: either doc or file modification time
|
||||
@@ -405,26 +434,16 @@ void ResList::resultPageNext()
|
||||
sizebuf = displayableBytes(fsize);
|
||||
}
|
||||
|
||||
// Abstract. The docsequence should deal with this as we don't
|
||||
// know if a query is open or if we're displaying
|
||||
// history. OTOH, if the docsequence does it, we're going to
|
||||
// generate a lot of unneeded abstracts for sorted sequences
|
||||
// (for all the queried for but undisplayed entries)
|
||||
string richabst;
|
||||
string abstract;
|
||||
LOGDEB2(("Abstract: clcnt %d prfs.build %d syntabs %d prfs.repl %d\n",
|
||||
m_searchData->clauseCount(), prefs.queryBuildAbstract,
|
||||
doc.syntabs, prefs.queryReplaceAbstract));
|
||||
if (m_searchData->clauseCount() > 0 && prefs.queryBuildAbstract &&
|
||||
if (prefs.queryBuildAbstract &&
|
||||
(doc.syntabs || prefs.queryReplaceAbstract)) {
|
||||
rcldb->makeDocAbstract(doc, abstract);
|
||||
if (abstract.empty())
|
||||
abstract = doc.abstract;
|
||||
abstract = m_docSource->getAbstract(doc);
|
||||
} else {
|
||||
abstract = doc.abstract;
|
||||
}
|
||||
plaintorich(abstract, richabst, m_searchData, true);
|
||||
|
||||
string richabst;
|
||||
plaintorich(abstract, richabst, m_searchData, true);
|
||||
|
||||
// Links;
|
||||
string linksbuf;
|
||||
@@ -439,7 +458,7 @@ void ResList::resultPageNext()
|
||||
linksbuf += string("<a href=") + vlbuf + ">" + "Edit" + "</a>";
|
||||
}
|
||||
|
||||
// Concatenate chunks to build the result list paragraph:
|
||||
// Build the result list paragraph:
|
||||
string result;
|
||||
|
||||
// Subheader: this is used by history
|
||||
@@ -481,47 +500,27 @@ void ResList::resultPageNext()
|
||||
m_curDocs.push_back(doc);
|
||||
}
|
||||
|
||||
bool hasNext = false;
|
||||
if (m_winfirst >= 0 && m_winfirst + prefs.respagesize < resCnt) {
|
||||
hasNext = true;
|
||||
}
|
||||
|
||||
if (gotone) {
|
||||
QString chunk = "<p align=\"center\">";
|
||||
if (hasPrev || hasNext) {
|
||||
if (hasPrev) {
|
||||
chunk += "<a href=\"p-1\"><b>";
|
||||
chunk += tr("Previous");
|
||||
chunk += "</b></a> ";
|
||||
}
|
||||
if (hasNext) {
|
||||
chunk += "<a href=\"n-1\"><b>";
|
||||
chunk += tr("Next");
|
||||
chunk += "</b></a>";
|
||||
}
|
||||
chunk += "</p>\n";
|
||||
append(chunk);
|
||||
// Footer
|
||||
chunk = "<p align=\"center\">";
|
||||
if (hasPrev || hasNext) {
|
||||
if (hasPrev) {
|
||||
chunk += "<a href=\"p-1\"><b>";
|
||||
chunk += tr("Previous");
|
||||
chunk += "</b></a> ";
|
||||
}
|
||||
append("</body></qt>");
|
||||
ensureCursorVisible();
|
||||
} else {
|
||||
// Restore first in win parameter that we shouln't have incremented
|
||||
QString chunk = "<p><font size=+1><b>";
|
||||
chunk += QString::fromUtf8(m_docSource->title().c_str());
|
||||
chunk += "</b></font><br>";
|
||||
chunk += "<a href=\"H-1\">";
|
||||
chunk += tr("Show query details");
|
||||
chunk += "</a><br>";
|
||||
if (hasNext) {
|
||||
chunk += "<a href=\"n-1\"><b>";
|
||||
chunk += tr("Next");
|
||||
chunk += "</b></a>";
|
||||
}
|
||||
chunk += "</p>\n";
|
||||
append(chunk);
|
||||
append(tr("<p><b>No results found</b><br>"));
|
||||
m_winfirst -= prefs.respagesize;
|
||||
if (m_winfirst < 0)
|
||||
m_winfirst = -1;
|
||||
hasNext = false;
|
||||
}
|
||||
append("</body></qt>");
|
||||
|
||||
// Possibly color paragraph of current preview if any
|
||||
previewExposed(m_curPvDoc);
|
||||
emit nextPageAvailable(hasNext);
|
||||
ensureCursorVisible();
|
||||
}
|
||||
|
||||
// Single click in result list use this for document selection, if no
|
||||
@@ -678,10 +677,7 @@ void ResList::menuCopyURL()
|
||||
}
|
||||
void ResList::menuExpand()
|
||||
{
|
||||
Rcl::Doc doc;
|
||||
if (rcldb && getDoc(m_popDoc, doc)) {
|
||||
emit docExpand(m_popDoc);
|
||||
}
|
||||
emit docExpand(m_popDoc);
|
||||
}
|
||||
|
||||
QString ResList::getDescription()
|
||||
|
||||
+45
-21
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: ssearch_w.cpp,v 1.17 2006-12-19 12:11:21 dockes Exp $ (C) 2006 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: ssearch_w.cpp,v 1.18 2007-01-19 10:32:39 dockes Exp $ (C) 2006 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -34,14 +34,18 @@ static char rcsid[] = "@(#$Id: ssearch_w.cpp,v 1.17 2006-12-19 12:11:21 dockes E
|
||||
#include "ssearch_w.h"
|
||||
#include "refcntr.h"
|
||||
#include "textsplit.h"
|
||||
#include "wasatorcl.h"
|
||||
|
||||
enum SSearchType {SST_ANY = 0, SST_ALL = 1, SST_FNM = 2};
|
||||
enum SSearchType {SST_ANY = 0, SST_ALL = 1, SST_FNM = 2, SST_LANG};
|
||||
|
||||
void SSearch::init()
|
||||
{
|
||||
// See enum above and keep in order !
|
||||
searchTypCMB->insertItem(tr("Any term"));
|
||||
searchTypCMB->insertItem(tr("All terms"));
|
||||
searchTypCMB->insertItem(tr("File name"));
|
||||
searchTypCMB->insertItem(tr("Query language"));
|
||||
|
||||
queryText->insertStringList(prefs.ssearchHistory);
|
||||
queryText->setEditText("");
|
||||
connect(queryText->lineEdit(), SIGNAL(returnPressed()),
|
||||
@@ -76,27 +80,44 @@ void SSearch::startSimpleSearch()
|
||||
string u8 = (const char *)queryText->currentText().utf8();
|
||||
LOGDEB(("SSearch::startSimpleSearch: [%s]\n", u8.c_str()));
|
||||
|
||||
RefCntr<Rcl::SearchData> sdata(new Rcl::SearchData(Rcl::SCLT_OR));
|
||||
SSearchType tp = (SSearchType)searchTypCMB->currentItem();
|
||||
Rcl::SearchData *sdata = 0;
|
||||
|
||||
if (prefs.ssearchAutoPhrase && (tp == SST_ANY || tp == SST_ALL) &&
|
||||
u8.find_first_of("\"") == string::npos &&
|
||||
TextSplit::countWords(u8) > 1) {
|
||||
sdata->addClause(new Rcl::SearchDataClauseDist(Rcl::SCLT_PHRASE,
|
||||
u8, 0));
|
||||
}
|
||||
if (tp == SST_LANG) {
|
||||
string reason;
|
||||
sdata = wasaStringToRcl(u8, reason);
|
||||
if (sdata == 0) {
|
||||
QMessageBox::warning(0, "Recoll", tr("Bad query string") +
|
||||
QString::fromAscii(reason.c_str()));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sdata = new Rcl::SearchData(Rcl::SCLT_OR);
|
||||
if (sdata == 0) {
|
||||
QMessageBox::warning(0, "Recoll", tr("Out of memory"));
|
||||
return;
|
||||
}
|
||||
|
||||
switch (tp) {
|
||||
case SST_ANY:
|
||||
default:
|
||||
sdata->addClause(new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR, u8));
|
||||
break;
|
||||
case SST_ALL:
|
||||
sdata->addClause(new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND, u8));
|
||||
break;
|
||||
case SST_FNM:
|
||||
sdata->addClause(new Rcl::SearchDataClauseFilename(u8));
|
||||
break;
|
||||
// Maybe add automatic phrase?
|
||||
if (prefs.ssearchAutoPhrase && (tp == SST_ANY || tp == SST_ALL) &&
|
||||
u8.find_first_of("\"") == string::npos &&
|
||||
TextSplit::countWords(u8) > 1) {
|
||||
sdata->addClause(new Rcl::SearchDataClauseDist(Rcl::SCLT_PHRASE,
|
||||
u8, 0));
|
||||
}
|
||||
|
||||
switch (tp) {
|
||||
case SST_ANY:
|
||||
default:
|
||||
sdata->addClause(new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR,u8));
|
||||
break;
|
||||
case SST_ALL:
|
||||
sdata->addClause(new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND,u8));
|
||||
break;
|
||||
case SST_FNM:
|
||||
sdata->addClause(new Rcl::SearchDataClauseFilename(u8));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Search terms history
|
||||
@@ -135,7 +156,10 @@ void SSearch::startSimpleSearch()
|
||||
for (int index = 0; index < queryText->count(); index++) {
|
||||
prefs.ssearchHistory.push_back(queryText->text(index));
|
||||
}
|
||||
emit startSearch(sdata);
|
||||
|
||||
|
||||
RefCntr<Rcl::SearchData> rsdata(sdata);
|
||||
emit startSearch(rsdata);
|
||||
}
|
||||
|
||||
void SSearch::setAnyTermMode()
|
||||
|
||||
Reference in New Issue
Block a user