Fix deep search returning 0 results

This commit is contained in:
Gioacchino Mazzurco 2018-07-25 00:27:39 +02:00
parent 1bc518041c
commit b4dd89dd87
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
2 changed files with 22 additions and 3 deletions

View File

@ -41,6 +41,8 @@ struct DeepSearch
};
/**
* @param[in] maxResults maximum number of acceptable search results, 0 for
* no limits
* @return search results count
*/
static uint32_t search( const std::string& queryStr,
@ -49,8 +51,24 @@ struct DeepSearch
{
results.clear();
Xapian::Database db;
// Open the database we're going to search.
Xapian::Database db(dbPath());
try { db = Xapian::Database(dbPath()); }
catch(Xapian::DatabaseOpeningError e)
{
std::cerr << __PRETTY_FUNCTION__ << " " << e.get_msg()
<< ", probably nothing has been indexed yet."<< std::endl;
return 0;
}
catch(Xapian::DatabaseError e)
{
std::cerr << __PRETTY_FUNCTION__ << " " << e.get_msg()
<< " this is fishy, maybe " << dbPath()
<< " has been corrupted (deleting it may help in that "
<< "case without loosing data)" << std::endl;
return 0;
}
// Set up a QueryParser with a stemmer and suitable prefixes.
Xapian::QueryParser queryparser;
@ -68,7 +86,8 @@ struct DeepSearch
Xapian::Enquire enquire(db);
enquire.set_query(query);
Xapian::MSet mset = enquire.get_mset(0, maxResults);
Xapian::MSet mset = enquire.get_mset(
0, maxResults ? maxResults : db.get_doccount() );
for ( Xapian::MSetIterator m = mset.begin(); m != mset.end(); ++m )
{

View File

@ -5279,7 +5279,7 @@ bool RsGxsNetService::search( const std::string& substring,
#ifdef RS_DEEP_SEARCH
std::vector<DeepSearch::SearchResult> results;
DeepSearch::search(substring, results, 0);
DeepSearch::search(substring, results);
for(auto dsr : results)
{