4 #include <apt-pkg/cachefile.h>
5 #include <apt-pkg/cacheset.h>
6 #include <apt-pkg/cmndline.h>
7 #include <apt-pkg/pkgrecords.h>
8 #include <apt-pkg/policy.h>
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>
16 #include <apt-private/private-cacheset.h>
17 #include <apt-private/private-output.h>
18 #include <apt-private/private-search.h>
30 bool FullTextSearch(CommandLine
&CmdL
) /*{{{*/
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
))
39 const char **patterns
;
40 patterns
= CmdL
.FileList
+ 1;
42 std::map
<std::string
, std::string
> output_map
;
43 std::map
<std::string
, std::string
>::const_iterator K
;
45 LocalitySortedVersionSet bag
;
46 OpTextProgress
progress(*_config
);
47 progress
.OverallProgress(0, 100, 50, _("Sorting"));
48 GetLocalitySortedVersionSet(CacheFile
, bag
, progress
);
49 LocalitySortedVersionSet::iterator V
= bag
.begin();
51 progress
.OverallProgress(50, 100, 50, _("Full Text Search"));
52 progress
.SubProgress(bag
.size());
54 for ( ;V
!= bag
.end(); ++V
)
57 progress
.Progress(Done
);
61 pkgCache::DescIterator Desc
= V
.TranslatedDescription();
62 pkgRecords::Parser
&parser
= records
.Lookup(Desc
.FileList());
64 bool all_found
= true;
65 for(i
=0; patterns
[i
] != NULL
; ++i
)
67 // FIXME: use regexp instead of simple find()
68 const char *pattern
= patterns
[i
];
70 strstr(V
.ParentPkg().Name(), pattern
) != NULL
||
71 parser
.ShortDesc().find(pattern
) != std::string::npos
||
72 parser
.LongDesc().find(pattern
) != std::string::npos
);
76 std::stringstream outs
;
77 ListSingleVersion(CacheFile
, records
, V
, outs
);
78 output_map
.insert(std::make_pair
<std::string
, std::string
>(
79 V
.ParentPkg().Name(), outs
.str()));
84 // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
85 // output the sorted map
86 for (K
= output_map
.begin(); K
!= output_map
.end(); ++K
)
87 std::cout
<< (*K
).second
<< std::endl
;