[Debtags-commits] [svn] r1985 - in daemon: . src
Enrico Zini
enrico at costa.debian.org
Mon Oct 2 22:16:33 UTC 2006
Author: enrico
Date: Mon Oct 2 22:16:32 2006
New Revision: 1985
Modified:
daemon/ (props changed)
daemon/src/debtagsd.cpp
Log:
r3462 at viaza: enrico | 2006-10-02 22:56:16 +0200
Implemented SUGG to suggest tags for a package and PKG to get package data
Modified: daemon/src/debtagsd.cpp
==============================================================================
--- daemon/src/debtagsd.cpp (original)
+++ daemon/src/debtagsd.cpp Mon Oct 2 22:16:32 2006
@@ -195,10 +195,11 @@
}
/// Quick access to the short descriptions of every package
-class ShortDescs : public std::map<std::string, std::string>
+class Descs : public std::map<std::string, std::pair<std::string, std::string> >
{
+ std::pair<std::string, std::string> none;
public:
- ShortDescs(Config& cfg)
+ Descs(Config& cfg)
{
tagcoll::input::Stdio in(cfg.pkgdb);
DebDBParser parser(in);
@@ -207,25 +208,29 @@
{
size_t sd = rec["Description"].find("\n");
if (sd == string::npos)
- insert(make_pair(rec["Package"], rec["Description"]));
+ insert(make_pair(rec["Package"],
+ make_pair(rec["Description"], string())));
else
- insert(make_pair(rec["Package"], rec["Description"].substr(0, sd)));
+ insert(make_pair(rec["Package"],
+ make_pair(
+ rec["Description"].substr(0, sd),
+ rec["Description"].substr(sd+1))));
}
}
- std::string get(const std::string& pkg) const
+ bool has(const std::string& pkg) const
+ {
+ return find(pkg) != end();
+ }
+
+ const std::pair<std::string, std::string>& get(const std::string& pkg) const
{
const_iterator i = find(pkg);
if (i == end())
- return std::string();
+ return none;
else
return i->second;
}
-
- std::string operator()(const std::string& pkg) const
- {
- return get(pkg);
- }
};
/// The debtagsd daemon process
@@ -235,7 +240,7 @@
Config& cfg;
tagcoll::coll::Fast<std::string, std::string> coll;
- ShortDescs desc;
+ Descs desc;
FullTextSearch fts;
/// Output a package with its tags and description
@@ -252,7 +257,7 @@
conn.write(*i);
}
conn.write(" ");
- conn.write(desc(pkg));
+ conn.write(desc.get(pkg).first);
conn.write("\n");
}
@@ -342,6 +347,17 @@
else if (cmd == "SUGG")
{
// Output the list of suggested tags
+ // Currently done computing the subcollection with the packages
+ // that the full text search considers similar to the given one
+ std::vector<std::string> pkgs = fts.similar(line);
+ tagcoll::coll::Fast<string, string> subcoll;
+ for (vector<string>::const_iterator i = pkgs.begin(); i != pkgs.end(); ++i)
+ subcoll.insert(wibble::singleton(*i), coll.getTagsOfItem(*i));
+ vector<string> tags = subcoll.tagsInCardinalityOrder();
+ for (vector<string>::const_reverse_iterator i = tags.rbegin(); i != tags.rend(); ++i)
+ outputTag(*i, conn);
+
+#if 0
std::set<std::string> tags = coll.getTagsOfItem(line);
if (!tags.empty())
{
@@ -378,6 +394,16 @@
conn.write(*j + "\n");
}
}
+#endif
+ }
+ else if (cmd == "PKG")
+ {
+ if (desc.has(line))
+ {
+ outputPackage(line, conn);
+ conn.write(desc.get(line).second);
+ conn.write("\n");
+ }
}
else
conn.write("Command not recognized: " + cmd + "\n");
More information about the Debtags-commits
mailing list