r3269 - software/ui/src

Enrico Zini enrico at alioth.debian.org
Sat Jul 7 11:02:40 UTC 2007


Author: enrico
Date: 2007-07-07 11:02:39 +0000 (Sat, 07 Jul 2007)
New Revision: 3269

Modified:
   software/ui/src/Engine.cpp
   software/ui/src/Engine.h
Log:
Use a MatchDecider to filter items before the xapian result count kicks in

Modified: software/ui/src/Engine.cpp
===================================================================
--- software/ui/src/Engine.cpp	2007-07-07 06:08:42 UTC (rev 3268)
+++ software/ui/src/Engine.cpp	2007-07-07 11:02:39 UTC (rev 3269)
@@ -26,6 +26,31 @@
 using namespace ept::apt;
 using namespace ept::debtags;
 
+struct EngineMatchDecider : public Xapian::MatchDecider
+{
+	Engine& e;
+	EngineMatchDecider(Engine& e) : e(e) {}
+
+	virtual bool operator()(const Xapian::Document &doc) const
+	{
+		// Filter out results that apt doesn't know
+		if (!e.apt().isValid(doc.get_data()))
+			return false;
+
+		// Finally filter by installed state if requested
+		Engine::State s = e.getInstalledFilter();
+		if (s != Engine::ANY)
+		{
+			PackageState state = e.apt().state(doc.get_data());
+			if (s == Engine::INSTALLED && !state.isInstalled())
+				return false;
+			if (s == Engine::NOTINSTALLED && state.isInstalled())
+				return false;
+		}
+		return true;
+	}
+};
+
 static Xapian::Query allGames(Vocabulary& voc)
 {
 	set<Tag> games = voc.tags("game");
@@ -89,6 +114,8 @@
 
 void Engine::recompute()
 {
+	EngineMatchDecider md(*this);
+
 	// Clear existing results
 	m_results.clear();
 	m_types.clear();
@@ -107,7 +134,7 @@
 		enquire.set_query(makeQuery());
 
 		// Get the 100 top matches
-		Xapian::MSet matches = enquire.get_mset(0, 100);
+		Xapian::MSet matches = enquire.get_mset(0, 100, 0, 0, &md);
 		for (Xapian::MSetIterator i = matches.begin(); i != matches.end(); ++i)
 		{
 			// Get all the game and interface tags in the result set
@@ -132,7 +159,7 @@
 		enquire.set_query(makeQuery());
 
 		// Get the 100 top matches
-		Xapian::MSet matches = enquire.get_mset(0, 100);
+		Xapian::MSet matches = enquire.get_mset(0, 100, 0, 0, &md);
 		for (Xapian::MSetIterator i = matches.begin(); i != matches.end(); ++i)
 		{
 			// Get all the game and interface tags in the result set
@@ -154,29 +181,17 @@
 	//cerr << "  filter query: " << enquire.get_query().get_description() << endl;
 
 	// Get the 100 top matches
-	Xapian::MSet matches = enquire.get_mset(0, 100);
+	Xapian::MSet matches = enquire.get_mset(0, 100, 0, 0, &md);
 	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
+		// FIXME: can be done adaptive, and can be done using set_cutoff in the
+		// enquire
 		//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];
@@ -204,6 +219,9 @@
 	if (m_res_max > m_max)
 		m_max = m_res_max;
 
+    if (m_filter_keywords.empty())
+		sort(m_results.begin(), m_results.end());
+
 	m_dirty = false;
 }
 

Modified: software/ui/src/Engine.h
===================================================================
--- software/ui/src/Engine.h	2007-07-07 06:08:42 UTC (rev 3268)
+++ software/ui/src/Engine.h	2007-07-07 11:02:39 UTC (rev 3269)
@@ -40,6 +40,10 @@
 	std::string name;
 	float popcon;
 	int relevance;
+	bool operator<(const Result& r) const
+	{
+		return name < r.name;
+	}
 };
 
 class Engine
@@ -142,6 +146,11 @@
 	 * Set the installed state filter
 	 */
 	void setInstalledFilter(Engine::State state = ANY);
+
+	/**
+	 * Get the current value of the installed filter
+	 */
+	Engine::State getInstalledFilter() const { return m_filter_state; }
 };
 
 // vim:set ts=4 sw=4:




More information about the Pkg-games-commits mailing list