2 #include <apt-pkg/error.h>
3 #include <apt-pkg/cachefile.h>
4 #include <apt-pkg/cachefilter.h>
5 #include <apt-pkg/cacheset.h>
6 #include <apt-pkg/init.h>
7 #include <apt-pkg/progress.h>
8 #include <apt-pkg/sourcelist.h>
9 #include <apt-pkg/cmndline.h>
10 #include <apt-pkg/strutl.h>
11 #include <apt-pkg/fileutl.h>
12 #include <apt-pkg/pkgrecords.h>
13 #include <apt-pkg/srcrecords.h>
14 #include <apt-pkg/version.h>
15 #include <apt-pkg/policy.h>
16 #include <apt-pkg/tagfile.h>
17 #include <apt-pkg/algorithms.h>
18 #include <apt-pkg/sptr.h>
19 #include <apt-pkg/pkgsystem.h>
20 #include <apt-pkg/indexfile.h>
21 #include <apt-pkg/metaindex.h>
36 #include "private-search.h"
37 #include "private-cacheset.h"
40 bool FullTextSearch(CommandLine
&CmdL
) /*{{{*/
42 pkgCacheFile CacheFile
;
43 pkgCache
*Cache
= CacheFile
.GetPkgCache();
44 pkgDepCache::Policy
*Plcy
= CacheFile
.GetPolicy();
45 pkgRecords
records(CacheFile
);
46 if (unlikely(Cache
== NULL
|| Plcy
== NULL
))
49 const char **patterns
;
50 patterns
= CmdL
.FileList
+ 1;
52 std::map
<std::string
, std::string
> output_map
;
53 std::map
<std::string
, std::string
>::const_iterator K
;
55 LocalitySortedVersionSet bag
;
56 OpTextProgress progress
;
57 progress
.OverallProgress(0, 100, 50, _("Sorting"));
58 GetLocalitySortedVersionSet(CacheFile
, bag
, progress
);
59 LocalitySortedVersionSet::iterator V
= bag
.begin();
61 progress
.OverallProgress(50, 100, 50, _("Full Text Search"));
62 progress
.SubProgress(bag
.size());
64 for ( ;V
!= bag
.end(); V
++)
67 progress
.Progress(Done
);
71 pkgCache::DescIterator Desc
= V
.TranslatedDescription();
72 pkgRecords::Parser
&parser
= records
.Lookup(Desc
.FileList());
74 bool all_found
= true;
75 for(i
=0; patterns
[i
] != NULL
; i
++)
77 // FIXME: use regexp instead of simple find()
78 const char *pattern
= patterns
[i
];
80 strstr(V
.ParentPkg().Name(), pattern
) != NULL
||
81 parser
.ShortDesc().find(pattern
) != std::string::npos
||
82 parser
.LongDesc().find(pattern
) != std::string::npos
);
86 std::stringstream outs
;
87 ListSingleVersion(CacheFile
, records
, V
, outs
);
88 output_map
.insert(std::make_pair
<std::string
, std::string
>(
89 V
.ParentPkg().Name(), outs
.str()));
94 // FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
95 // output the sorted map
96 for (K
= output_map
.begin(); K
!= output_map
.end(); K
++)
97 std::cout
<< (*K
).second
<< std::endl
;