r3013 - software/ui/src
Enrico Zini
enrico at alioth.debian.org
Wed Jun 20 12:09:20 UTC 2007
Author: enrico
Date: 2007-06-20 12:09:20 +0000 (Wed, 20 Jun 2007)
New Revision: 3013
Modified:
software/ui/src/Engine.cpp
software/ui/src/Engine.h
Log:
Engine compiles
Modified: software/ui/src/Engine.cpp
===================================================================
--- software/ui/src/Engine.cpp 2007-06-20 11:59:24 UTC (rev 3012)
+++ software/ui/src/Engine.cpp 2007-06-20 12:09:20 UTC (rev 3013)
@@ -21,9 +21,14 @@
#include "Engine.h"
using namespace std;
+using namespace ept::apt;
+using namespace ept::debtags;
void Engine::recompute()
{
+ // Clear existing results
+ m_results.clear();
+
Xapian::Query query;
Xapian::Query kwquery;
Xapian::Query typequery;
@@ -39,14 +44,22 @@
if (kwquery.empty())
if (typequery.empty())
if (ifacequery.empty())
- ;
+ {
+ // If there is no query, default to querying all games
+ set<Tag> games = voc().tags("game");
+ vector<string> terms;
+ for (set<Tag>::const_iterator i = games.begin();
+ i != games.end(); ++i)
+ terms.push_back("T" + i->fullname());
+ query = Xapian::Query(Xapian::Query::OP_OR, terms.begin(), terms.end());
+ }
else
query = ifacequery;
else
if (ifacequery.empty())
- query = tagquery;
+ query = typequery;
else
- query = Xapian::Query(Xapian::Query::OP_AND, ifacequery, tagquery);
+ query = Xapian::Query(Xapian::Query::OP_AND, ifacequery, typequery);
else
if (typequery.empty())
if (ifacequery.empty())
@@ -58,33 +71,55 @@
query = Xapian::Query(Xapian::Query::OP_AND, kwquery, typequery);
else
query = Xapian::Query(Xapian::Query::OP_AND, kwquery,
- Xapian::Query(Xapian::Query::OP_AND(typequery, ifacequery)));
+ Xapian::Query(Xapian::Query::OP_AND, typequery, ifacequery));
- if (query.empty())
- {
- // Query all games
- set<Tag> games = voc().tags("game");
- vector<string> terms;
- for (set<Tag>::const_iterator i = games.begin();
- i != games.end(); ++i)
- terms.push_back("T" + i->fullname());
- query = Xapian::Query(Xapian::Query::OP_OR, terms.begin(), terms.end());
- }
-
Xapian::Enquire enquire(m_textsearch.db());
+ // We always want programs, so always AND it here
enquire.set_query(Xapian::Query(Xapian::Query::OP_AND,
Xapian::Query("Trole::program"),
query));
+ // Get the 100 top matches
+ Xapian::MSet matches = enquire.get_mset(0, 100);
+ for (Xapian::MSetIterator i = matches.begin(); i != matches.end(); ++i)
+ {
+ // Filter out results that apt doesn't know
+ if (!m_apt.isValid(i.get_document().get_data()))
+ continue;
+
+ // Stop producing if the quality goes below a cutoff point
+ // FIXME: hardcoded value, but I can't see a reason to make it
+ // configurable yet
+ if (i.get_percent() < 40)
+ break;
+
+ // Finally filter by installed state if requested
+ if (m_filter_state != ANY)
+ {
+ PackageState state = m_apt.state(i.get_document().get_data());
+ if (m_filter_state == INSTALLED && !state.isInstalled())
+ continue;
+ if (m_filter_state == NOTINSTALLED && state.isInstalled())
+ continue;
+ }
+
+ Result res;
+ res.name = i.get_document().get_data();
+ res.popcon = m_popcon[res.name];
+ res.relevance = i.get_percent();
+
+ m_results.push_back(res);
+ }
+
m_dirty = false;
}
-std::vector<ept::debtags::Tag> Engine::types() const
+std::vector<ept::debtags::Tag> Engine::types()
{
if (m_dirty) recompute();
}
-std::vector<ept::debtags::Tag> Engine::interfaces() const
+std::vector<ept::debtags::Tag> Engine::interfaces()
{
if (m_dirty) recompute();
}
@@ -103,7 +138,7 @@
void Engine::setInterfaceFilter(const ept::debtags::Tag& tag)
{
- m_filter_interface = tag;
+ m_filter_iface = tag;
m_dirty = true;
}
Modified: software/ui/src/Engine.h
===================================================================
--- software/ui/src/Engine.h 2007-06-20 11:59:24 UTC (rev 3012)
+++ software/ui/src/Engine.h 2007-06-20 12:09:20 UTC (rev 3013)
@@ -43,7 +43,7 @@
class Engine
{
public:
- enum { ANY, INSTALLED, NOTINSTALLED } State;
+ enum State { ANY, INSTALLED, NOTINSTALLED };
protected:
/// Apt data provider
@@ -59,9 +59,9 @@
ept::popcon::Popcon m_popcon;
std::string m_filter_keywords;
- Tag m_filter_type;
- Tag m_filter_iface;
- State m_filter_state;
+ ept::debtags::Tag m_filter_type;
+ ept::debtags::Tag m_filter_iface;
+ Engine::State m_filter_state;
bool m_dirty;
@@ -79,7 +79,7 @@
ept::debtags::Debtags& debtags() { return m_debtags; }
/// Access the tag vocabulary
- ept::debtags::Vocabulary& voc() { return m_debtags->vocabulary(); }
+ ept::debtags::Vocabulary& voc() { return m_debtags.vocabulary(); }
/// Get the list of available game types
std::vector<ept::debtags::Tag> types();
@@ -114,7 +114,7 @@
/**
* Set the installed state filter
*/
- void setInstalledFilter(State state);
+ void setInstalledFilter(Engine::State state);
};
// vim:set ts=4 sw=4:
More information about the Pkg-games-commits
mailing list