~ubuntu-branches/ubuntu/precise/unity-lens-applications/precise

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Didier Roche
  • Date: 2011-09-23 16:23:48 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: package-import@ubuntu.com-20110923162348-4tcxaredhrushpxf
Tags: 0.4.8-0ubuntu1
* New upstream release.
  - unity-applications-daemon crash in
    dee_shared_model_flush_revision_queue() (LP: #740561)
  - Apps Lens doesn't handle Software Center Index Corruption (LP: #762821)
  - Star rating filter in apps lens not respected (LP: #855324)
  - configure needs to test for xapian.h (LP: #736051)
  - Random available apps does not belong to selected category (LP: #857409)
* debian/control:
  - add libdb4.8-dev build-dep

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
 
438
446
   * check, but works well enough in practice */
439
447
  if (filter_query == NULL)
440
448
    {
 
449
      g_debug ("RANDOM");
441
450
      for (i = 0, n_unique = 0; i < n_apps*2, n_unique < n_apps; i++)
442
451
        {          
443
452
          Xapian::Document doc;
445
454
            {
446
455
              doc = searcher->db->get_document (
447
456
                             g_rand_int_range (searcher->random, 1, lastdocid));
 
457
                        UnityPackageInfo *pkginfo = _pkginfo_from_document (doc);
 
458
              if (g_hash_table_lookup_extended (unique, pkginfo->package_name, NULL, NULL))
 
459
                {
 
460
                  _free_package_info (pkginfo);
 
461
                }
 
462
              else
 
463
                {
 
464
                  g_hash_table_insert (unique, pkginfo->package_name, NULL);
 
465
                  result->results = g_slist_prepend (result->results, pkginfo);
 
466
                  n_unique++;
 
467
                }
448
468
            }
449
 
          catch (Xapian::DocNotFoundError e)
 
469
          catch (Xapian::Error e)
450
470
            {
 
471
              g_warning ("Error getting random apps: %s", e.get_msg().c_str());
451
472
              continue;
452
473
            }
453
 
          UnityPackageInfo *pkginfo = _pkginfo_from_document (doc);
454
 
          if (g_hash_table_lookup_extended (unique, pkginfo->package_name, NULL, NULL))
455
 
            {
456
 
              _free_package_info (pkginfo);
457
 
            }
458
 
          else
459
 
            {
460
 
              g_hash_table_insert (unique, pkginfo->package_name, NULL);
461
 
              result->results = g_slist_prepend (result->results, pkginfo);
462
 
              n_unique++;
463
 
            }
464
474
        }
465
475
    }
466
476
  else
467
477
    {
 
478
      g_debug ("FILTER %s", filter_query);
468
479
      Xapian::Query query;
469
480
      try
470
481
      {
471
482
        query = searcher->query_parser->parse_query (filter_query, QUERY_PARSER_FILTER_FLAGS);
 
483
        searcher->enquire->set_sort_by_relevance ();
 
484
        searcher->enquire->set_query(query);
 
485
        Xapian::MSet matches = searcher->enquire->get_mset(0, searcher->db->get_doccount ());
 
486
        for (i = 0, n_unique = 0; i < n_apps*4, n_unique < n_apps; i++)
 
487
          {
 
488
            docid = g_rand_int_range (searcher->random, 0, matches.size ());
 
489
            Xapian::MSetIterator iter = matches[docid];
 
490
            Xapian::Document doc = iter.get_document ();
 
491
            UnityPackageInfo *pkginfo = _pkginfo_from_document (doc);
 
492
            if (g_hash_table_lookup_extended (unique, pkginfo->package_name, NULL, NULL))
 
493
              {
 
494
                _free_package_info (pkginfo);
 
495
              }
 
496
            else
 
497
              {
 
498
                g_hash_table_insert (unique, pkginfo->package_name, NULL);
 
499
                result->results = g_slist_prepend (result->results, pkginfo);
 
500
                n_unique++;
 
501
              }
 
502
          }
472
503
      }
473
 
      catch (Xapian::QueryParserError e)
 
504
      catch (Xapian::Error e)
474
505
      {
475
 
        g_debug ("Error parsing filter query '%s': %s", filter_query, e.get_msg().c_str());
 
506
        g_debug ("Error getting random apps for query '%s': %s",
 
507
                 filter_query, e.get_msg().c_str());
476
508
        return g_slice_new0 (UnityPackageSearchResult);
477
509
      }
478
 
      searcher->enquire->set_sort_by_relevance ();
479
 
      searcher->enquire->set_query(query);
480
 
      Xapian::MSet matches = searcher->enquire->get_mset(0, searcher->db->get_doccount ());
481
 
      for (i = 0, n_unique = 0; i < n_apps*4, n_unique < n_apps; i++)
482
 
        {
483
 
          docid = g_rand_int_range (searcher->random, 0, matches.size ());
484
 
          Xapian::MSetIterator iter = matches[docid];
485
 
          Xapian::Document doc = iter.get_document ();
486
 
          UnityPackageInfo *pkginfo = _pkginfo_from_document (doc);
487
 
          if (g_hash_table_lookup_extended (unique, pkginfo->package_name, NULL, NULL))
488
 
            {
489
 
              _free_package_info (pkginfo);
490
 
            }
491
 
          else
492
 
            {
493
 
              g_hash_table_insert (unique, pkginfo->package_name, NULL);
494
 
              result->results = g_slist_prepend (result->results, pkginfo);
495
 
              n_unique++;
496
 
            }
497
 
        }
498
510
    }
499
511
 
500
512
  g_hash_table_unref (unique);