~kamstrup/unity-lens-applications/include-gsettings-schema

« back to all changes in this revision

Viewing changes to src/unity-package-search.cc

  • Committer: Mikkel Kamstrup Erlandsen
  • Date: 2011-09-23 13:28:47 UTC
  • Revision ID: mikkel.kamstrup@gmail.com-20110923132847-507otkql00vtu7mo
More robust handling of errors from Xapian. Surround interactions with Xapian with broad catch clauses. More importantly allow the private method _pkginfo_from_document() to throw a Xapian::Error upwards so we can catch it later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
301
301
}
302
302
 
303
303
static UnityPackageInfo*
304
 
_pkginfo_from_document (Xapian::Document     doc)
 
304
_pkginfo_from_document (Xapian::Document     doc) throw (Xapian::Error)
305
305
 
306
306
{
307
307
  UnityPackageInfo *pkginfo = g_slice_new0 (UnityPackageInfo);
363
363
        break;
364
364
    }
365
365
  }
366
 
  catch (Xapian::QueryParserError e)
 
366
  catch (Xapian::Error e)
367
367
  {
368
 
    g_debug ("Error parsing query '%s': %s", search_string, e.get_msg().c_str());
 
368
    g_warning ("Error parsing query '%s': %s", search_string, e.get_msg().c_str());
369
369
    return g_slice_new0 (UnityPackageSearchResult);
370
370
  }
371
371
  //cout << "Performing query `" << query.get_description() << "'" << endl;
383
383
      searcher->enquire->set_sort_by_relevance ();
384
384
      break;
385
385
  }
386
 
 
387
 
  // Perform search
388
 
  max_hits = (max_hits != 0 ? max_hits : searcher->db->get_doccount ());
389
 
  searcher->enquire->set_query(query);
390
 
  Xapian::MSet matches =
391
 
    searcher->enquire->get_mset(0, max_hits);   
392
 
 
393
 
  // Retrieve the results, note that we build the result->results
394
 
  // list in reverse order and then reverse it before we return it
 
386
  
395
387
  result = g_slice_new0 (UnityPackageSearchResult);
396
 
  result->num_hits = matches.get_matches_estimated ();
397
 
  for (Xapian::MSetIterator i = matches.begin();
398
 
       i != matches.end();
399
 
       ++i)
400
 
    {
401
 
      try
402
 
        {
403
 
          Xapian::Document doc = i.get_document();
404
 
          UnityPackageInfo *pkginfo = _pkginfo_from_document (doc);
405
 
          result->results = g_slist_prepend (result->results, pkginfo);
406
 
        }
407
 
      catch (Xapian::Error e)
408
 
        {
409
 
          g_warning ("Unable to read document from result set: %s",
410
 
                     e.get_msg().c_str());
411
 
        }
412
 
    }
413
 
 
414
 
  result->results = g_slist_reverse (result->results);
 
388
  try
 
389
  {
 
390
    // Perform search
 
391
    max_hits = (max_hits != 0 ? max_hits : searcher->db->get_doccount ());
 
392
    searcher->enquire->set_query(query);
 
393
    Xapian::MSet matches =
 
394
      searcher->enquire->get_mset(0, max_hits); 
 
395
 
 
396
    // Retrieve the results, note that we build the result->results
 
397
    // list in reverse order and then reverse it before we return it
 
398
    result->num_hits = matches.get_matches_estimated ();
 
399
    for (Xapian::MSetIterator i = matches.begin();
 
400
         i != matches.end();
 
401
         ++i)
 
402
      {
 
403
        try
 
404
          {
 
405
            Xapian::Document doc = i.get_document();
 
406
            UnityPackageInfo *pkginfo = _pkginfo_from_document (doc);
 
407
            result->results = g_slist_prepend (result->results, pkginfo);
 
408
          }
 
409
        catch (Xapian::Error e)
 
410
          {
 
411
            g_warning ("Unable to read document from result set: %s",
 
412
                       e.get_msg().c_str());
 
413
          }
 
414
      }
 
415
 
 
416
    result->results = g_slist_reverse (result->results);
 
417
  }
 
418
  catch(const Xapian::Error e)
 
419
  {
 
420
    g_warning ("Error running query '%s': %s", search_string, e.get_msg().c_str());
 
421
  }
 
422
  
415
423
  return result;
416
424
}
417
425