use getmatchingterms instead of getqueryterms for highlighting etc. in preview
This commit is contained in:
parent
1bcdf8515e
commit
72dec21fe5
@ -502,7 +502,7 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
|
|||||||
bool highlightTerms = fdoc.text.length() < 1000 *1024;
|
bool highlightTerms = fdoc.text.length() < 1000 *1024;
|
||||||
string firstTerm;
|
string firstTerm;
|
||||||
list<string> terms;
|
list<string> terms;
|
||||||
rcldb->getQueryTerms(terms);
|
rcldb->getMatchTerms(idoc, terms);
|
||||||
if (highlightTerms) {
|
if (highlightTerms) {
|
||||||
progress.setLabelText(tr("Creating preview text"));
|
progress.setLabelText(tr("Creating preview text"));
|
||||||
ToRichThread rthr(fdoc.text, terms, firstTerm, richTxt);
|
ToRichThread rthr(fdoc.text, terms, firstTerm, richTxt);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: rclmain.cpp,v 1.25 2006-04-26 11:29:10 dockes Exp $ (C) 2005 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: rclmain.cpp,v 1.26 2006-04-27 06:12:10 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -442,7 +442,7 @@ void RclMain::startPreview(int docnum)
|
|||||||
// (which is different because it's format is explicit richtext
|
// (which is different because it's format is explicit richtext
|
||||||
// instead of auto as for preview, needed because it's built by
|
// instead of auto as for preview, needed because it's built by
|
||||||
// fragments?).
|
// fragments?).
|
||||||
static const char* punct = " \t()<>\"'[]{}!^*,";
|
static const char* punct = " \t()<>\"'[]{}!^*,\n\r";
|
||||||
void RclMain::ssearchAddTerm(QString term)
|
void RclMain::ssearchAddTerm(QString term)
|
||||||
{
|
{
|
||||||
string t = (const char *)term.utf8();
|
string t = (const char *)term.utf8();
|
||||||
@ -542,7 +542,8 @@ void RclMain::docExpand(int docnum)
|
|||||||
return;
|
return;
|
||||||
list<string> terms;
|
list<string> terms;
|
||||||
terms = rcldb->expand(doc);
|
terms = rcldb->expand(doc);
|
||||||
QString text = sSearch->queryText->text();
|
// Do we keep the original query. I think we'd better not.
|
||||||
|
QString text;// = sSearch->queryText->text();
|
||||||
for (list<string>::iterator it = terms.begin(); it != terms.end(); it++) {
|
for (list<string>::iterator it = terms.begin(); it != terms.end(); it++) {
|
||||||
text += QString::fromLatin1(" \"") +
|
text += QString::fromLatin1(" \"") +
|
||||||
QString::fromUtf8((*it).c_str()) + QString::fromLatin1("\"");
|
QString::fromUtf8((*it).c_str()) + QString::fromLatin1("\"");
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.72 2006-04-25 09:59:12 dockes Exp $ (C) 2004 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.73 2006-04-27 06:12:10 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -1089,9 +1089,34 @@ bool Db::getQueryTerms(list<string>& terms)
|
|||||||
|
|
||||||
terms.clear();
|
terms.clear();
|
||||||
Xapian::TermIterator it;
|
Xapian::TermIterator it;
|
||||||
for (it = m_ndb->query.get_terms_begin(); it != m_ndb->query.get_terms_end();
|
try {
|
||||||
it++) {
|
for (it = m_ndb->query.get_terms_begin();
|
||||||
terms.push_back(*it);
|
it != m_ndb->query.get_terms_end(); it++) {
|
||||||
|
terms.push_back(*it);
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Db::getMatchTerms(const Doc& doc, list<string>& terms)
|
||||||
|
{
|
||||||
|
if (!m_ndb || !m_ndb->enquire) {
|
||||||
|
LOGERR(("Db::getMatchTerms: no query opened\n"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
terms.clear();
|
||||||
|
Xapian::TermIterator it;
|
||||||
|
Xapian::docid id = Xapian::docid(doc.xdocid);
|
||||||
|
try {
|
||||||
|
for (it=m_ndb->enquire->get_matching_terms_begin(id);
|
||||||
|
it != m_ndb->enquire->get_matching_terms_end(id); it++) {
|
||||||
|
terms.push_back(*it);
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1319,11 +1344,17 @@ list<string> Db::expand(const Doc &doc)
|
|||||||
}
|
}
|
||||||
Xapian::RSet rset;
|
Xapian::RSet rset;
|
||||||
rset.add_document(Xapian::docid(doc.xdocid));
|
rset.add_document(Xapian::docid(doc.xdocid));
|
||||||
Xapian::ESet eset = m_ndb->enquire->get_eset(10, rset);
|
// We don't exclude the original query terms.
|
||||||
|
Xapian::ESet eset = m_ndb->enquire->get_eset(20, rset, false);
|
||||||
LOGDEB(("ESet terms:\n"));
|
LOGDEB(("ESet terms:\n"));
|
||||||
|
// We filter out the special terms
|
||||||
for (Xapian::ESetIterator it = eset.begin(); it != eset.end(); it++) {
|
for (Xapian::ESetIterator it = eset.begin(); it != eset.end(); it++) {
|
||||||
LOGDEB((" [%s]\n", (*it).c_str()));
|
LOGDEB((" [%s]\n", (*it).c_str()));
|
||||||
|
if ((*it).empty() || ((*it).at(0)>='A' && (*it).at(0)<='Z'))
|
||||||
|
continue;
|
||||||
res.push_back(*it);
|
res.push_back(*it);
|
||||||
|
if (res.size() >= 10)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef _DB_H_INCLUDED_
|
#ifndef _DB_H_INCLUDED_
|
||||||
#define _DB_H_INCLUDED_
|
#define _DB_H_INCLUDED_
|
||||||
/* @(#$Id: rcldb.h,v 1.34 2006-04-22 06:27:37 dockes Exp $ (C) 2004 J.F.Dockes */
|
/* @(#$Id: rcldb.h,v 1.35 2006-04-27 06:12:10 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
@ -137,6 +137,7 @@ class Db {
|
|||||||
bool setQuery(AdvSearchData &q, int opts = QO_NONE,
|
bool setQuery(AdvSearchData &q, int opts = QO_NONE,
|
||||||
const string& stemlang = "english");
|
const string& stemlang = "english");
|
||||||
bool getQueryTerms(list<string>& terms);
|
bool getQueryTerms(list<string>& terms);
|
||||||
|
bool getMatchTerms(const Doc& doc, list<string>& terms);
|
||||||
|
|
||||||
// Return a list of database terms that begin with the input string
|
// Return a list of database terms that begin with the input string
|
||||||
// Stem expansion is performed if lang is not empty
|
// Stem expansion is performed if lang is not empty
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user