Fix deep search returning 0 results

This commit is contained in:
Gioacchino Mazzurco 2018-07-25 00:27:39 +02:00
parent 7128a04525
commit d2a62b03ee
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 * @return search results count
*/ */
static uint32_t search( const std::string& queryStr, static uint32_t search( const std::string& queryStr,
@ -49,8 +51,24 @@ struct DeepSearch
{ {
results.clear(); results.clear();
Xapian::Database db;
// Open the database we're going to search. // 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. // Set up a QueryParser with a stemmer and suitable prefixes.
Xapian::QueryParser queryparser; Xapian::QueryParser queryparser;
@ -68,7 +86,8 @@ struct DeepSearch
Xapian::Enquire enquire(db); Xapian::Enquire enquire(db);
enquire.set_query(query); 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 ) 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 #ifdef RS_DEEP_SEARCH
std::vector<DeepSearch::SearchResult> results; std::vector<DeepSearch::SearchResult> results;
DeepSearch::search(substring, results, 0); DeepSearch::search(substring, results);
for(auto dsr : results) for(auto dsr : results)
{ {