r3028 - software/ui/src
Enrico Zini
enrico at alioth.debian.org
Wed Jun 20 18:36:09 UTC 2007
Author: enrico
Date: 2007-06-20 18:36:09 +0000 (Wed, 20 Jun 2007)
New Revision: 3028
Modified:
software/ui/src/Engine.cpp
software/ui/src/Engine.h
software/ui/src/games.cpp
Log:
Added stars
Modified: software/ui/src/Engine.cpp
===================================================================
--- software/ui/src/Engine.cpp 2007-06-20 18:27:13 UTC (rev 3027)
+++ software/ui/src/Engine.cpp 2007-06-20 18:36:09 UTC (rev 3028)
@@ -190,6 +190,35 @@
m_dirty = false;
}
+std::vector<Result> Engine::related(const std::string& name, int count) const
+{
+ Xapian::Enquire enquire(m_textsearch.db());
+
+ // Retrieve the document for the given package
+ enquire.set_query(Xapian::Query("pkg:"+name));
+ Xapian::MSet matches = enquire.get_mset(0, 1);
+ Xapian::MSetIterator mi = matches.begin();
+ if (mi == matches.end()) return std::vector<Result>();
+ Xapian::Document doc = mi.get_document();
+
+ // Retrieve the list of similar documents
+ enquire.set_query(Xapian::Query(Xapian::Query::OP_OR, doc.termlist_begin(), doc.termlist_end()));
+ matches = enquire.get_mset(0, count);
+ mi = matches.begin();
+ if (mi == matches.end()) return std::vector<Result>();
+ // Skip the first element, which is the package itself
+ vector<Result> results;
+ for (++mi; mi != matches.end(); ++mi)
+ {
+ Result res;
+ res.name = mi.get_document().get_data();
+ res.popcon = m_popcon[res.name];
+ res.relevance = mi.get_percent();
+ results.push_back(res);
+ }
+ return results;
+}
+
void Engine::setKeywordFilter(const std::string& keywords)
{
m_filter_keywords = keywords;
Modified: software/ui/src/Engine.h
===================================================================
--- software/ui/src/Engine.h 2007-06-20 18:27:13 UTC (rev 3027)
+++ software/ui/src/Engine.h 2007-06-20 18:36:09 UTC (rev 3028)
@@ -110,6 +110,9 @@
return m_results;
}
+ /// Get a list of packages similar to the given one
+ std::vector<Result> related(const std::string& name, int count = 10) const;
+
/// Get the maximum popcon score in the result set
float popconLocalMax() const { return m_res_max; }
Modified: software/ui/src/games.cpp
===================================================================
--- software/ui/src/games.cpp 2007-06-20 18:27:13 UTC (rev 3027)
+++ software/ui/src/games.cpp 2007-06-20 18:36:09 UTC (rev 3028)
@@ -38,6 +38,7 @@
#include <ept/apt/packagerecord.h>
#include <iostream>
+#include <cmath>
#ifdef USE_GETTEXT
#include <libintl.h>
@@ -183,7 +184,11 @@
{
PackageRecord rec(engine.apt().rawRecord(i->name));
char* userData = pkgString(rec.package());
- ui.ResultsBrowser->add((rec.package() + " - " + rec.shortDescription()).c_str(), userData);
+ string desc = rec.package() + " - " + rec.shortDescription() + " *";
+ int stars = (int)rintf(i->popcon * 4 / engine.popconLocalMax());
+ for (int j = 0; j < stars; ++j)
+ desc += '*';
+ ui.ResultsBrowser->add(desc.c_str(), userData);
// Relevance is 0 to 100
// Popcon is a weird floating point number (to be improved)
More information about the Pkg-games-commits
mailing list