GUI snippets window: add options for the max list length and for sorting the snippets by page number

This commit is contained in:
Jean-Francois Dockes
2019-07-21 19:09:51 +02:00
parent 049ba1e7e4
commit 736051fcd6
13 changed files with 290 additions and 224 deletions
+25 -9
View File
@@ -138,12 +138,14 @@ public:
if (maxtermcount && termcount++ > maxtermcount) {
LOGINF("Rclabsfromtext: stopping because maxtermcount reached: "<<
maxtermcount << endl);
retflags |= ABSRES_TRUNC;
return false;
}
// Also limit the number of fragments (just in case safety)
if (m_fragments.size() > maxtermcount / 100) {
LOGINF("Rclabsfromtext: stopping because maxfragments reached: "<<
maxtermcount/100 << endl);
retflags |= ABSRES_TRUNC;
return false;
}
// Remember recent past
@@ -326,6 +328,10 @@ public:
return;
}
int getretflags() {
return retflags;
}
private:
// Past terms because we need to go back for context before a hit
@@ -364,6 +370,7 @@ private:
unsigned int termcount{0};
unsigned int maxtermcount{0};
int retflags{0};
};
int Query::Native::abstractFromText(
@@ -375,7 +382,8 @@ int Query::Native::abstractFromText(
int ctxwords,
unsigned int maxtotaloccs,
vector<Snippet>& vabs,
Chrono& chron
Chrono& chron,
bool sortbypage
)
{
(void)chron;
@@ -423,13 +431,21 @@ int Query::Native::abstractFromText(
// Sort the fragments by decreasing weight
const vector<MatchFragment>& res1 = splitter.getFragments();
vector<MatchFragment> result(res1.begin(), res1.end());
std::sort(result.begin(), result.end(),
[](const MatchFragment& a,
const MatchFragment& b) -> bool {
return a.coef > b.coef;
}
);
if (sortbypage) {
std::sort(result.begin(), result.end(),
[](const MatchFragment& a,
const MatchFragment& b) -> bool {
return a.hitpos < b.hitpos;
}
);
} else {
std::sort(result.begin(), result.end(),
[](const MatchFragment& a,
const MatchFragment& b) -> bool {
return a.coef > b.coef;
}
);
}
vector<int> vpbreaks;
ndb->getPagePositions(docid, vpbreaks);
@@ -464,7 +480,7 @@ int Query::Native::abstractFromText(
if (count++ >= maxtotaloccs)
break;
}
return ABSRES_OK;
return ABSRES_OK | splitter.getretflags();
}
}
+5 -4
View File
@@ -623,11 +623,12 @@ int Query::Native::abstractFromIndex(
// @param[out] vabs the abstract is returned as a vector of snippets.
int Query::Native::makeAbstract(Xapian::docid docid,
vector<Snippet>& vabs,
int imaxoccs, int ictxwords)
int imaxoccs, int ictxwords, bool sortbypage)
{
chron.restart();
LOGABS("makeAbstract: docid " << docid << " imaxoccs " <<
imaxoccs << " ictxwords " << ictxwords << "\n");
LOGDEB("makeAbstract: docid " << docid << " imaxoccs " <<
imaxoccs << " ictxwords " << ictxwords << " sort by page " <<
sortbypage << "\n");
// The (unprefixed) terms matched by this document
vector<string> matchedTerms;
@@ -675,7 +676,7 @@ int Query::Native::makeAbstract(Xapian::docid docid,
if (ndb->m_storetext) {
return abstractFromText(ndb, docid, matchedTerms, byQ,
totalweight, ctxwords, maxtotaloccs, vabs,
chron);
chron, sortbypage);
} else {
return abstractFromIndex(ndb, docid, matchedTerms, byQ,
totalweight, ctxwords, maxtotaloccs, vabs,
+2 -2
View File
@@ -267,7 +267,7 @@ bool Query::getQueryTerms(vector<string>& terms)
}
int Query::makeDocAbstract(const Doc &doc, vector<Snippet>& abstract,
int maxoccs, int ctxwords)
int maxoccs, int ctxwords, bool sortbypage)
{
LOGDEB("makeDocAbstract: maxoccs " << maxoccs << " ctxwords " <<
ctxwords << "\n");
@@ -276,7 +276,7 @@ int Query::makeDocAbstract(const Doc &doc, vector<Snippet>& abstract,
return ABSRES_ERROR;
}
int ret = ABSRES_ERROR;
XAPTRY(ret = m_nq->makeAbstract(doc.xdocid, abstract, maxoccs, ctxwords),
XAPTRY(ret = m_nq->makeAbstract(doc.xdocid, abstract, maxoccs, ctxwords, sortbypage),
m_db->m_ndb->xrdb, m_reason);
if (!m_reason.empty()) {
LOGDEB("makeDocAbstract: makeAbstract: reason: " << m_reason << "\n");
+1 -1
View File
@@ -107,7 +107,7 @@ public:
bool makeDocAbstract(const Doc &doc, std::vector<std::string>& abstract);
// Returned as a vector of pair<page,snippet> page is 0 if unknown
int makeDocAbstract(const Doc &doc, std::vector<Snippet>& abst,
int maxoccs= -1, int ctxwords = -1);
int maxoccs= -1, int ctxwords = -1, bool sortbypage=false);
/** Retrieve page number for first match for "significant" query term
* @param term returns the chosen term */
int getFirstMatchPage(const Doc &doc, std::string& term);
+3 -2
View File
@@ -55,7 +55,7 @@ public:
/** Return a list of terms which matched for a specific result document */
bool getMatchTerms(unsigned long xdocid, std::vector<std::string>& terms);
int makeAbstract(Xapian::docid id, std::vector<Snippet>&,
int maxoccs = -1, int ctxwords = -1);
int maxoccs, int ctxwords, bool sortbypage);
int getFirstMatchPage(Xapian::docid docid, std::string& term);
void setDbWideQTermsFreqs();
double qualityTerms(Xapian::docid docid,
@@ -109,7 +109,8 @@ public:
int ctxwords,
unsigned int maxtotaloccs,
vector<Snippet>& vabs,
Chrono& chron
Chrono& chron,
bool sortbypage
);
};