added method to Rcl::Query for retrieving ref to SearchData + misc rclquery cleanup
This commit is contained in:
parent
c6b90a0a78
commit
179d22f4ff
@ -72,6 +72,30 @@ static void noPrefixList(const vector<string>& in, vector<string>& out)
|
||||
out.resize(it - out.begin());
|
||||
}
|
||||
|
||||
bool Query::Native::getMatchTerms(unsigned long xdocid, vector<string>& terms)
|
||||
{
|
||||
if (!xenquire) {
|
||||
LOGERR(("Query::getMatchTerms: no query opened\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
terms.clear();
|
||||
Xapian::TermIterator it;
|
||||
Xapian::docid id = Xapian::docid(xdocid);
|
||||
|
||||
XAPTRY(terms.insert(terms.begin(),
|
||||
xenquire->get_matching_terms_begin(id),
|
||||
xenquire->get_matching_terms_end(id)),
|
||||
m_q->m_db->m_ndb->xrdb, m_q->m_reason);
|
||||
|
||||
if (!m_q->m_reason.empty()) {
|
||||
LOGERR(("getMatchTerms: xapian error: %s\n", m_q->m_reason.c_str()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Retrieve db-wide frequencies for the query terms and store them in
|
||||
// the query object. This is done at most once for a query, and the data is used
|
||||
// while computing abstracts for the different result documents.
|
||||
@ -237,7 +261,7 @@ int Query::Native::getFirstMatchPage(Xapian::docid docid, string& term)
|
||||
vector<string> terms;
|
||||
{
|
||||
vector<string> iterms;
|
||||
m_q->getMatchTerms(docid, iterms);
|
||||
getMatchTerms(docid, iterms);
|
||||
noPrefixList(iterms, terms);
|
||||
}
|
||||
if (terms.empty()) {
|
||||
@ -297,7 +321,7 @@ abstract_result Query::Native::makeAbstract(Xapian::docid docid,
|
||||
vector<string> matchedTerms;
|
||||
{
|
||||
vector<string> iterms;
|
||||
m_q->getMatchTerms(docid, iterms);
|
||||
getMatchTerms(docid, iterms);
|
||||
noPrefixList(iterms, matchedTerms);
|
||||
if (matchedTerms.empty()) {
|
||||
LOGDEB(("makeAbstract::Empty term list\n"));
|
||||
|
||||
@ -156,16 +156,6 @@ Query::~Query()
|
||||
}
|
||||
}
|
||||
|
||||
string Query::getReason() const
|
||||
{
|
||||
return m_reason;
|
||||
}
|
||||
|
||||
Db *Query::whatDb()
|
||||
{
|
||||
return m_db;
|
||||
}
|
||||
|
||||
void Query::setSortBy(const string& fld, bool ascending) {
|
||||
if (fld.empty()) {
|
||||
m_sortField.erase();
|
||||
@ -273,34 +263,6 @@ bool Query::getQueryTerms(vector<string>& terms)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Query::getMatchTerms(const Doc& doc, vector<string>& terms)
|
||||
{
|
||||
return getMatchTerms(doc.xdocid, terms);
|
||||
}
|
||||
bool Query::getMatchTerms(unsigned long xdocid, vector<string>& terms)
|
||||
{
|
||||
if (ISNULL(m_nq) || !m_nq->xenquire) {
|
||||
LOGERR(("Query::getMatchTerms: no query opened\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
terms.clear();
|
||||
Xapian::TermIterator it;
|
||||
Xapian::docid id = Xapian::docid(xdocid);
|
||||
|
||||
XAPTRY(terms.insert(terms.begin(),
|
||||
m_nq->xenquire->get_matching_terms_begin(id),
|
||||
m_nq->xenquire->get_matching_terms_end(id)),
|
||||
m_db->m_ndb->xrdb, m_reason);
|
||||
|
||||
if (!m_reason.empty()) {
|
||||
LOGERR(("getMatchTerms: xapian error: %s\n", m_reason.c_str()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
abstract_result Query::makeDocAbstract(Doc &doc,
|
||||
vector<Snippet>& abstract,
|
||||
int maxoccs, int ctxwords)
|
||||
@ -494,7 +456,6 @@ bool Query::getDoc(int xapi, Doc &doc)
|
||||
sprintf(buf, "%d", collapsecount);
|
||||
doc.meta[Rcl::Doc::keycc] = buf;
|
||||
|
||||
|
||||
// Parse xapian document's data and populate doc fields
|
||||
return m_db->m_ndb->dbDataToRclDoc(docid, data, doc);
|
||||
}
|
||||
|
||||
@ -62,20 +62,31 @@ public:
|
||||
*/
|
||||
class Query {
|
||||
public:
|
||||
/** The constructor only allocates memory */
|
||||
Query(Db *db);
|
||||
~Query();
|
||||
|
||||
/** Get explanation about last error */
|
||||
std::string getReason() const;
|
||||
std::string getReason() const
|
||||
{
|
||||
return m_reason;
|
||||
}
|
||||
|
||||
/** Choose sort order. Must be called before setQuery */
|
||||
void setSortBy(const std::string& fld, bool ascending = true);
|
||||
const std::string& getSortBy() const {return m_sortField;}
|
||||
bool getSortAscending() const {return m_sortAscending;}
|
||||
const std::string& getSortBy() const
|
||||
{
|
||||
return m_sortField;
|
||||
}
|
||||
bool getSortAscending() const
|
||||
{
|
||||
return m_sortAscending;
|
||||
}
|
||||
|
||||
/** Return or filter results with identical content checksum */
|
||||
void setCollapseDuplicates(bool on) {m_collapseDuplicates = on;}
|
||||
void setCollapseDuplicates(bool on)
|
||||
{
|
||||
m_collapseDuplicates = on;
|
||||
}
|
||||
|
||||
/** Accept data describing the search and query the index. This can
|
||||
* be called repeatedly on the same object which gets reinitialized each
|
||||
@ -92,27 +103,32 @@ class Query {
|
||||
/** Get possibly expanded list of query terms */
|
||||
bool getQueryTerms(std::vector<std::string>& terms);
|
||||
|
||||
/** Return a list of terms which matched for a specific result document */
|
||||
bool getMatchTerms(const Doc& doc, std::vector<std::string>& terms);
|
||||
bool getMatchTerms(unsigned long xdocid, std::vector<std::string>& terms);
|
||||
|
||||
/** Build synthetic abstract for document, extracting chunks relevant for
|
||||
* the input query. This uses index data only (no access to the file) */
|
||||
// Abstract return as one string
|
||||
// Abstract returned as one string
|
||||
bool makeDocAbstract(Doc &doc, std::string& abstract);
|
||||
// Returned as a snippets vector
|
||||
bool makeDocAbstract(Doc &doc, std::vector<std::string>& abstract);
|
||||
// Returned as a vector of pair<page,snippet> page is 0 if unknown
|
||||
abstract_result makeDocAbstract(Doc &doc, std::vector<Snippet>& abst,
|
||||
int maxoccs= -1, int ctxwords = -1);
|
||||
/** Retrieve detected page breaks positions */
|
||||
/** Retrieve page number for first match for term */
|
||||
int getFirstMatchPage(Doc &doc, std::string& term);
|
||||
|
||||
/** Retrieve a reference to the searchData we are using */
|
||||
RefCntr<SearchData> getSD()
|
||||
{
|
||||
return m_sd;
|
||||
}
|
||||
|
||||
/** Expand query to look for documents like the one passed in */
|
||||
std::vector<std::string> expand(const Doc &doc);
|
||||
|
||||
/** Return the Db we're set for */
|
||||
Db *whatDb();
|
||||
Db *whatDb() const
|
||||
{
|
||||
return m_db;
|
||||
}
|
||||
|
||||
/* make this public for access from embedded Db::Native */
|
||||
class Native;
|
||||
|
||||
@ -46,14 +46,19 @@ public:
|
||||
|
||||
Native(Query *q)
|
||||
: m_q(q), xenquire(0)
|
||||
{ }
|
||||
~Native() {
|
||||
{
|
||||
}
|
||||
~Native()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
void clear() {
|
||||
void clear()
|
||||
{
|
||||
delete xenquire; xenquire = 0;
|
||||
termfreqs.clear();
|
||||
}
|
||||
/** Return a list of terms which matched for a specific result document */
|
||||
bool getMatchTerms(unsigned long xdocid, std::vector<std::string>& terms);
|
||||
abstract_result makeAbstract(Xapian::docid id, vector<Snippet>&,
|
||||
int maxoccs = -1, int ctxwords = -1);
|
||||
int getFirstMatchPage(Xapian::docid docid, std::string& term);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user