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