fixed next/prev screen pb + pb with accents when matching in preview

This commit is contained in:
dockes 2005-02-08 11:59:09 +00:00
parent 4588803281
commit 3649eb415b
4 changed files with 88 additions and 36 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: textsplit.cpp,v 1.7 2005-02-08 10:56:13 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: textsplit.cpp,v 1.8 2005-02-08 11:59:08 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
#ifndef TEST_TEXTSPLIT
@ -295,13 +295,46 @@ static string teststring =
"\n"
;
static string thisprog;
static string usage =
" textsplit [opts] [filename]\n"
" -q: query mode\n"
" \n\n"
;
static void
Usage(void)
{
cerr << thisprog << ": usage:\n" << usage;
exit(1);
}
static int op_flags;
#define OPT_q 0x1
int main(int argc, char **argv)
{
thisprog = argv[0];
argc--; argv++;
while (argc > 0 && **argv == '-') {
(*argv)++;
if (!(**argv))
/* Cas du "adb - core" */
Usage();
while (**argv)
switch (*(*argv)++) {
case 'q': op_flags |= OPT_q; break;
default: Usage(); break;
}
argc--; argv++;
}
DebugLog::getdbl()->setloglevel(DEBDEB1);
DebugLog::setfilename("stderr");
mySplitterCB cb;
TextSplit splitter(&cb, true);
if (argc == 2) {
TextSplit splitter(&cb, (op_flags&OPT_q) ? true: false);
if (argc == 1) {
string data;
if (!file_to_string(argv[1], data))
exit(1);

View File

@ -32,6 +32,10 @@ using std::pair;
#include "textsplit.h"
#include "smallut.h"
#ifndef MIN
#define MIN(A,B) ((A) < (B) ? (A) : (B))
#endif
void RecollMain::fileExit()
{
LOGDEB1(("RecollMain: fileExit\n"));
@ -68,7 +72,9 @@ class myTextSplitCB : public TextSplitCB {
virtual bool takeword(const std::string& term, int, int bts, int bte) {
for (list<string>::const_iterator it = terms->begin();
it != terms->end(); it++) {
if (!stringlowercmp(*it, term)) {
string dumb = term;
Rcl::dumb_string(term, dumb);
if (!stringlowercmp(*it, dumb)) {
tboffs.push_back(pair<int, int>(bts, bte));
break;
}
@ -280,46 +286,53 @@ void RecollMain::clearqPB_clicked()
static const int respagesize = 10;
void RecollMain::listPrevPB_clicked()
{
if (reslist_winfirst <= 0)
return;
reslist_winfirst -= 2*respagesize;
listNextPB_clicked();
}
#ifndef MIN
#define MIN(A,B) ((A) < (B) ? (A) : (B))
#endif
// Fill up result list window with next screen of hits
void RecollMain::listNextPB_clicked()
{
LOGDEB1(("listNextPB_clicked: winfirst %d\n", reslist_winfirst));
if (!rcldb)
return;
int percent;
Rcl::Doc doc;
rcldb->getDoc(0, doc, &percent);
int resCnt = rcldb->getResCnt();
LOGDEB(("listNextPB_clicked: rescnt %d, winfirst %d\n", resCnt,
reslist_winfirst));
// If we are already on the last page, nothing to do:
if (reslist_winfirst >= 0 && (reslist_winfirst + respagesize > resCnt))
return;
if (reslist_winfirst < 0)
reslist_winfirst = 0;
else
reslist_winfirst += respagesize;
// Insert results if any in result list window
bool gotone = false;
for (int i = 0; i < respagesize; i++) {
Rcl::Doc doc;
reslistTE->clear();
previewTextEdit->clear();
int last = MIN(resCnt-reslist_winfirst, respagesize);
// Insert results if any in result list window
for (int i = 0; i < last; i++) {
doc.erase();
int percent;
if (i == 0) {
reslistTE->clear();
previewTextEdit->clear();
}
if (!rcldb->getDoc(reslist_winfirst + i, doc, &percent)) {
if (i == 0)
reslist_winfirst = -1;
break;
}
int resCnt = rcldb->getResCnt();
int last = MIN(resCnt, reslist_winfirst+respagesize);
if (i == 0) {
reslistTE->append("<qt><head></head><body><p>");
char line[80];
sprintf(line, "<p><b>Displaying results %d-%d out of %d</b><br>",
reslist_winfirst+1, last, resCnt);
reslist_winfirst+1, reslist_winfirst+last, resCnt);
reslistTE->append(line);
}
@ -365,7 +378,7 @@ void RecollMain::listNextPB_clicked()
// Restore first in win parameter that we shouln't have incremented
reslist_winfirst -= respagesize;
if (reslist_winfirst < 0)
reslist_winfirst = 0;
reslist_winfirst = -1;
}
}

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.21 2005-02-08 10:56:12 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.22 2005-02-08 11:59:08 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
#include <stdio.h>
#include <sys/stat.h>
@ -205,7 +205,7 @@ bool mySplitterCB::takeword(const std::string &term, int pos, int, int)
// for accents, and do it by hand for upper / lower. Note lowercasing is
// only for ascii letters anyway, so it's just A-Z -> a-z
// Removing crlfs is so that we can use the text in the document data fields.
bool dumb_string(const string &in, string &out)
bool Rcl::dumb_string(const string &in, string &out)
{
string inter;
out.erase();

View File

@ -1,10 +1,14 @@
#ifndef _DB_H_INCLUDED_
#define _DB_H_INCLUDED_
/* @(#$Id: rcldb.h,v 1.9 2005-02-07 13:17:47 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: rcldb.h,v 1.10 2005-02-08 11:59:08 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include <list>
#ifndef NO_NAMESPACES
using std::string;
#endif
// rcldb defines an interface for a 'real' text database. The current
// implementation uses xapian only, and xapian-related code is in rcldb.cpp
// If support was added for other backend, the xapian code would be moved in
@ -28,15 +32,15 @@ namespace Rcl {
class Doc {
public:
// This fields potentially go into the document data record
std::string url;
std::string mimetype;
std::string mtime; // Modification time as decimal ascii
std::string origcharset;
std::string title;
std::string keywords;
std::string abstract;
string url;
string mimetype;
string mtime; // Modification time as decimal ascii
string origcharset;
string title;
string keywords;
string abstract;
std::string text;
string text;
void erase() {
url.erase();
mimetype.erase();
@ -60,20 +64,20 @@ class Db {
Db();
~Db();
enum OpenMode {DbRO, DbUpd, DbTrunc};
bool open(const std::string &dbdir, OpenMode mode);
bool open(const string &dbdir, OpenMode mode);
bool close();
bool isopen();
// Update-related functions
bool add(const std::string &filename, const Doc &doc);
bool needUpdate(const std::string &filename, const struct stat *stp);
bool add(const string &filename, const Doc &doc);
bool needUpdate(const string &filename, const struct stat *stp);
bool purge();
// Query-related functions
// Parse query string and initialize query
bool setQuery(const std::string &q);
bool getQueryTerms(std::list<std::string>& terms);
bool setQuery(const string &q);
bool getQueryTerms(std::list<string>& terms);
// Get document at rank i. This is probably vastly inferior to the type
// of interface in Xapian, but we have to start with something simple
@ -83,6 +87,8 @@ class Db {
int getResCnt();
};
// Unaccent and lowercase data.
extern bool dumb_string(const string &in, string &out);
}