]> git.saurik.com Git - apt.git/blame - apt-private/private-search.cc
compile with absolute paths to allow lcov use
[apt.git] / apt-private / private-search.cc
CommitLineData
ee0167c4 1// Includes /*{{{*/
453b82a3
DK
2#include <config.h>
3
b9179170 4#include <apt-pkg/cachefile.h>
b9179170 5#include <apt-pkg/cacheset.h>
b9179170 6#include <apt-pkg/cmndline.h>
b9179170 7#include <apt-pkg/pkgrecords.h>
b9179170 8#include <apt-pkg/policy.h>
453b82a3
DK
9#include <apt-pkg/progress.h>
10#include <apt-pkg/cacheiterators.h>
11#include <apt-pkg/configuration.h>
12#include <apt-pkg/depcache.h>
13#include <apt-pkg/macros.h>
14#include <apt-pkg/pkgcache.h>
b9179170 15
453b82a3
DK
16#include <apt-private/private-cacheset.h>
17#include <apt-private/private-output.h>
18#include <apt-private/private-search.h>
19
20#include <string.h>
b9179170 21#include <iostream>
453b82a3 22#include <sstream>
b9179170 23#include <map>
453b82a3
DK
24#include <string>
25#include <utility>
b9179170 26
453b82a3 27#include <apti18n.h>
ee0167c4 28 /*}}}*/
b9179170 29
ee0167c4 30bool FullTextSearch(CommandLine &CmdL) /*{{{*/
b9179170
MV
31{
32 pkgCacheFile CacheFile;
33 pkgCache *Cache = CacheFile.GetPkgCache();
34 pkgDepCache::Policy *Plcy = CacheFile.GetPolicy();
35 pkgRecords records(CacheFile);
36 if (unlikely(Cache == NULL || Plcy == NULL))
37 return false;
38
39 const char **patterns;
40 patterns = CmdL.FileList + 1;
41
42 std::map<std::string, std::string> output_map;
43 std::map<std::string, std::string>::const_iterator K;
44
45 LocalitySortedVersionSet bag;
1bef0dd5 46 OpTextProgress progress(*_config);
b9179170
MV
47 progress.OverallProgress(0, 100, 50, _("Sorting"));
48 GetLocalitySortedVersionSet(CacheFile, bag, progress);
49 LocalitySortedVersionSet::iterator V = bag.begin();
50
51 progress.OverallProgress(50, 100, 50, _("Full Text Search"));
52 progress.SubProgress(bag.size());
53 int Done = 0;
9ce3cfc9 54 for ( ;V != bag.end(); ++V)
b9179170
MV
55 {
56 if (Done%500 == 0)
57 progress.Progress(Done);
9ce3cfc9 58 ++Done;
b9179170
MV
59
60 int i;
61 pkgCache::DescIterator Desc = V.TranslatedDescription();
62 pkgRecords::Parser &parser = records.Lookup(Desc.FileList());
63
64 bool all_found = true;
9ce3cfc9 65 for(i=0; patterns[i] != NULL; ++i)
b9179170
MV
66 {
67 // FIXME: use regexp instead of simple find()
68 const char *pattern = patterns[i];
69 all_found &= (
70 strstr(V.ParentPkg().Name(), pattern) != NULL ||
01837669
MV
71 strcasestr(parser.ShortDesc().c_str(), pattern) != NULL ||
72 strcasestr(parser.LongDesc().c_str(), pattern) != NULL);
73 // search patterns are AND by default so we can skip looking further
74 // on the first mismatch
75 if(all_found == false)
76 break;
b9179170
MV
77 }
78 if (all_found)
79 {
80 std::stringstream outs;
81 ListSingleVersion(CacheFile, records, V, outs);
82 output_map.insert(std::make_pair<std::string, std::string>(
83 V.ParentPkg().Name(), outs.str()));
84 }
85 }
86 progress.Done();
87
88 // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
89 // output the sorted map
9ce3cfc9 90 for (K = output_map.begin(); K != output_map.end(); ++K)
b9179170
MV
91 std::cout << (*K).second << std::endl;
92
93 return true;
94}
ee0167c4 95 /*}}}*/