r11044 - software/ui/src

Enrico Zini enrico at alioth.debian.org
Fri Jun 25 08:40:04 UTC 2010


Author: enrico
Date: 2010-06-25 08:39:55 +0000 (Fri, 25 Jun 2010)
New Revision: 11044

Modified:
   software/ui/src/Engine.cpp
   software/ui/src/Engine.h
   software/ui/src/filter.cpp
   software/ui/src/filter.h
   software/ui/src/goplay.cpp
   software/ui/src/pkgbrowser.cpp
Log:
Ported to libept1

Modified: software/ui/src/Engine.cpp
===================================================================
--- software/ui/src/Engine.cpp	2010-06-23 02:02:27 UTC (rev 11043)
+++ software/ui/src/Engine.cpp	2010-06-25 08:39:55 UTC (rev 11044)
@@ -20,14 +20,26 @@
 
 #include "Engine.h"
 
+#include <wibble/string.h>
+#include <wibble/regexp.h>
 #include <iostream>
 
 using namespace std;
+using namespace wibble;
 using namespace ept::apt;
 using namespace ept::debtags;
 
 Engine::Engine()
-	: m_filter_state(ANY), m_dirty(true), m_max(0) {}
+	: m_db(ept::axi::path_db()), m_stem("en"), m_filter_state(ANY), m_dirty(true), m_max(0)
+{
+	m_qp.set_default_op(Xapian::Query::OP_AND);
+        m_qp.set_database(m_db);
+        m_qp.set_stemmer(m_stem);
+        m_qp.set_stemming_strategy(Xapian::QueryParser::STEM_SOME);
+        m_qp.add_prefix("pkg", "XP");
+        m_qp.add_boolean_prefix("tag", "XT");
+        m_qp.add_boolean_prefix("sec", "XS");
+}
 
 struct EngineMatchDecider : public Xapian::MatchDecider
 {
@@ -56,11 +68,11 @@
 
 static Xapian::Query allGames(Vocabulary& voc, const std::string& facet="game")
 {
-	set<Tag> games = voc.tags(facet);
+	set<std::string> games = voc.tags(facet);
 	vector<string> terms;
-	for (set<Tag>::const_iterator i = games.begin();
+	for (set<std::string>::const_iterator i = games.begin();
 			i != games.end(); ++i)
-		terms.push_back("XT" + i->fullname());
+		terms.push_back("XT" + *i);
 	return Xapian::Query(Xapian::Query::OP_OR, terms.begin(), terms.end());
 }
 
@@ -72,11 +84,33 @@
 	Xapian::Query ifacequery;
 
 	if (!m_filter_keywords.empty())
-		kwquery = m_textsearch.makePartialORQuery(m_filter_keywords);
-	if (m_filter_type.valid())
-		typequery = Xapian::Query("XT"+m_filter_type.fullname());
-	if (m_filter_iface.valid())
-		ifacequery = Xapian::Query("XT"+m_filter_iface.fullname());
+	{
+		// Add prefixes to tag names
+		Splitter splitter("[ \t]*,[ \t]*", REG_EXTENDED);
+		vector<string> kw;
+		for (Splitter::const_iterator i = splitter.begin(m_filter_keywords);
+				i != splitter.end(); ++i)
+		{
+			if (m_vocabulary.hasTag(*i))
+				kw.push_back("tag:" + *i);
+			else
+				kw.push_back(*i);
+		}
+		bool do_partial = not (kw.size() == 1 and kw[0].size() < 3);
+
+		kwquery = m_qp.parse_query(str::join(kw.begin(), kw.end(), " "),
+				Xapian::QueryParser::FLAG_BOOLEAN |
+				Xapian::QueryParser::FLAG_LOVEHATE |
+				Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE |
+				Xapian::QueryParser::FLAG_WILDCARD |
+				(do_partial ? Xapian::QueryParser::FLAG_PARTIAL : 0) |
+				Xapian::QueryParser::FLAG_PURE_NOT |
+				Xapian::QueryParser::FLAG_SPELLING_CORRECTION);
+	}
+	if (!m_filter_type.empty())
+		typequery = Xapian::Query("XT"+m_filter_type);
+	if (!m_filter_iface.empty())
+		ifacequery = Xapian::Query("XT"+m_filter_iface);
 		
 	if (kwquery.empty())
 		if (typequery.empty())
@@ -126,12 +160,12 @@
 	//cerr << "Engine recompute:" << endl;
 
 	// Compute the types
-	if (m_filter_type.valid())
+	if (!m_filter_type.empty())
 	{
 		//cerr << "  filter type: " << m_filter_type.fullname() << endl;
-		Tag tmp = m_filter_type;
-		m_filter_type = Tag();
-		Xapian::Enquire enquire(m_textsearch.db());
+		std::string tmp = m_filter_type;
+		m_filter_type = std::string();
+		Xapian::Enquire enquire(m_db);
 		enquire.set_query(makeQuery());
 
 		// Get all the results out of Xapian
@@ -144,10 +178,10 @@
 			for (Xapian::MSetIterator i = matches.begin(); i != matches.end(); ++i)
 			{
 				// Get all the game and interface tags in the result set
-				set<Tag> tags = m_debtags.getTagsOfItem(i.get_document().get_data());
-				for (set<Tag>::const_iterator j = tags.begin();
+				set<std::string> tags = m_debtags.getTagsOfItem(i.get_document().get_data());
+				for (set<std::string>::const_iterator j = tags.begin();
 						j != tags.end(); ++j)
-					if (j->facet().name() == mainFacet)
+					if (voc::getfacet(*j) == mainFacet)
 						m_types.insert(*j);
 			}
 		}
@@ -157,12 +191,12 @@
 	}
 
 	// Compute the interfaces
-	if (m_filter_iface.valid())
+	if (!m_filter_iface.empty())
 	{
 		//cerr << "  filter iface: " << m_filter_iface.fullname() << endl;
-		Tag tmp = m_filter_iface;
-		m_filter_iface = Tag();
-		Xapian::Enquire enquire(m_textsearch.db());
+		std::string tmp = m_filter_iface;
+		m_filter_iface = std::string();
+		Xapian::Enquire enquire(m_db);
 		enquire.set_query(makeQuery());
 
 		// Get all the results out of Xapian
@@ -175,10 +209,10 @@
 			for (Xapian::MSetIterator i = matches.begin(); i != matches.end(); ++i)
 			{
 				// Get all the game and interface tags in the result set
-				set<Tag> tags = m_debtags.getTagsOfItem(i.get_document().get_data());
-				for (set<Tag>::const_iterator j = tags.begin();
+				set<std::string> tags = m_debtags.getTagsOfItem(i.get_document().get_data());
+				for (set<std::string>::const_iterator j = tags.begin();
 						j != tags.end(); ++j)
-					if (j->facet().name() == secondaryFacet)
+					if (voc::getfacet(*j) == secondaryFacet)
 						m_interfaces.insert(*j);
 			}
 		}
@@ -187,7 +221,7 @@
 		//cerr << "  no filter iface" << endl;
 	}
 
-	Xapian::Enquire enquire(m_textsearch.db());
+	Xapian::Enquire enquire(m_db);
 	enquire.set_query(makeQuery());
 
 	//cerr << "  filter query: " << enquire.get_query().get_description() << endl;
@@ -221,22 +255,22 @@
 
 			// Get all the game and interface tags in the result set
 			// only for type or filter when they are not set
-			if (!m_filter_type.valid() || !m_filter_iface.valid())
+			if (m_filter_type.empty() || m_filter_iface.empty())
 			{
-				set<Tag> tags = m_debtags.getTagsOfItem(res.name);
-				for (set<Tag>::const_iterator j = tags.begin();
+				set<std::string> tags = m_debtags.getTagsOfItem(res.name);
+				for (set<std::string>::const_iterator j = tags.begin();
 						j != tags.end(); ++j)
-					if (!m_filter_type.valid() && j->facet().name() == mainFacet)
+					if (m_filter_type.empty() && voc::getfacet(*j) == mainFacet)
 						m_types.insert(*j);
-					else if (!m_filter_iface.valid() && j->facet().name() == secondaryFacet)
+					else if (m_filter_iface.empty() && voc::getfacet(*j) == secondaryFacet)
 						m_interfaces.insert(*j);
 			}
 		}
 	}
 	// Always keep the currently selected items in the lists
-	if (m_filter_type.valid())
+	if (!m_filter_type.empty())
 		m_types.insert(m_filter_type);
-	if (m_filter_iface.valid())
+	if (!m_filter_iface.empty())
 		m_interfaces.insert(m_filter_iface);
 
 
@@ -251,7 +285,7 @@
 
 std::vector<Result> Engine::related(const std::string& name, int count) const
 {
-	Xapian::Enquire enquire(m_textsearch.db());
+	Xapian::Enquire enquire(m_db);
 	
 	// Retrieve the document for the given package
 	enquire.set_query(Xapian::Query("XP"+name));
@@ -284,13 +318,13 @@
 	m_dirty = true;
 }
 
-void Engine::setTypeFilter(const ept::debtags::Tag& tag)
+void Engine::setTypeFilter(const std::string& tag)
 {
 	m_filter_type = tag;
 	m_dirty = true;
 }
 
-void Engine::setInterfaceFilter(const ept::debtags::Tag& tag)
+void Engine::setInterfaceFilter(const std::string& tag)
 {
 	m_filter_iface = tag;
 	m_dirty = true;

Modified: software/ui/src/Engine.h
===================================================================
--- software/ui/src/Engine.h	2010-06-23 02:02:27 UTC (rev 11043)
+++ software/ui/src/Engine.h	2010-06-25 08:39:55 UTC (rev 11044)
@@ -23,7 +23,8 @@
 
 #include <ept/apt/apt.h>
 #include <ept/debtags/debtags.h>
-#include <ept/textsearch/textsearch.h>
+#include <ept/debtags/vocabulary.h>
+#include <ept/axi/axi.h>
 #include <ept/popcon/popcon.h>
 #include <string>
 #include <set>
@@ -58,22 +59,31 @@
 	/// Debtags data provider
 	ept::debtags::Debtags m_debtags;
 
+	/// Vocabulary data provider
+	ept::debtags::Vocabulary m_vocabulary;
+
 	/// Xapian data provider
-	ept::textsearch::TextSearch m_textsearch;
+	Xapian::Database m_db;
 
+	/// Xapian stemmer
+	Xapian::Stem m_stem;
+
+	/// Xapian query parser
+	Xapian::QueryParser m_qp;
+
 	/// Popcon scores
 	ept::popcon::Popcon m_popcon;
 
 	std::string m_filter_keywords;
-	ept::debtags::Tag m_filter_type;
-	ept::debtags::Tag m_filter_iface;
+	std::string m_filter_type;
+	std::string m_filter_iface;
 	Engine::State m_filter_state;
 
 	bool m_dirty;
 
 	std::vector<Result> m_results;
-	std::set<ept::debtags::Tag> m_types;
-	std::set<ept::debtags::Tag> m_interfaces;
+	std::set<std::string> m_types;
+	std::set<std::string> m_interfaces;
 
 	float m_max;
 	float m_res_max;
@@ -100,20 +110,20 @@
 	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_vocabulary; }
 
 	/// Access the popcon data source
 	ept::popcon::Popcon& popcon() { return m_popcon; }
 
 	/// Get the list of available game types
-	const std::set<ept::debtags::Tag>& types()
+	const std::set<std::string>& types()
 	{
 		if (m_dirty) recompute();
 		return m_types;
 	}
 
 	/// Get the list of available interfaces
-	const std::set<ept::debtags::Tag>& interfaces()
+	const std::set<std::string>& interfaces()
 	{
 		if (m_dirty) recompute();
 		return m_interfaces;
@@ -144,12 +154,12 @@
 	/**
 	 * Set the game type filter
 	 */
-	void setTypeFilter(const ept::debtags::Tag& tag = ept::debtags::Tag());
+	void setTypeFilter(const std::string& tag = std::string());
 
 	/**
 	 * Set the interface type filter
 	 */
-	void setInterfaceFilter(const ept::debtags::Tag& tag = ept::debtags::Tag());
+	void setInterfaceFilter(const std::string& tag = std::string());
 
 	/**
 	 * Set the installed state filter

Modified: software/ui/src/filter.cpp
===================================================================
--- software/ui/src/filter.cpp	2010-06-23 02:02:27 UTC (rev 11043)
+++ software/ui/src/filter.cpp	2010-06-25 08:39:55 UTC (rev 11044)
@@ -24,7 +24,6 @@
 #endif
 
 #include <string>
-#include <ept/debtags/tag.h>
 
 #define FACET_VIOLENCE "rating:violence"
 #define FACET_SEX "rating:sex"
@@ -155,14 +154,10 @@
 /* Find out the color of a single tag */
 int PackageFilter::TagValue(const Tag &tag)
 {
-	std::string name = tag.fullname();
-	//std::string facet_name = tag.facet().name();
-	//std::string tag_name = tag.name();
-
 	// The order is important
 	PackageFilter::ResultList *item = list;
 	while (item != NULL) {
-		if (tagdata.CheckTag(item, name))
+		if (tagdata.CheckTag(item, tag))
 			return item->type;
 		item = item->next;
 	}
@@ -179,11 +174,10 @@
 //	tagdata.PrintAll(std::cerr);
 
 	for (TagSet::const_iterator i = tags.begin(); i != tags.end(); ++i) {
-		std::string name = i->fullname();
 		//std::string facet_name = i->facet().name();
 		//std::string tag_name = i->name();
 //		std::cerr << "Add Tag: " << name << std::endl;
-		tagdata.SetTagIfExists(&t, name);
+		tagdata.SetTagIfExists(&t, *i);
 	}
 
 	// The order is important

Modified: software/ui/src/filter.h
===================================================================
--- software/ui/src/filter.h	2010-06-23 02:02:27 UTC (rev 11043)
+++ software/ui/src/filter.h	2010-06-25 08:39:55 UTC (rev 11044)
@@ -23,7 +23,6 @@
 
 #include <set>
 #include <iostream>
-#include <ept/debtags/tag.h>
 
 class PackageFilter
 {
@@ -39,8 +38,8 @@
 		Black,     // Mayday, mayday, the tag/package might be really dangerous!
 	} Type;
 
-	typedef ept::debtags::Tag Tag;
-	typedef std::set<Tag> TagSet;
+	typedef std::string Tag;
+	typedef std::set<std::string> TagSet;
 
 	int TagValue(const Tag &tag);
 	int TagsValue(const TagSet &tags);

Modified: software/ui/src/goplay.cpp
===================================================================
--- software/ui/src/goplay.cpp	2010-06-23 02:02:27 UTC (rev 11043)
+++ software/ui/src/goplay.cpp	2010-06-25 08:39:55 UTC (rev 11044)
@@ -91,16 +91,15 @@
 using namespace ept;
 using namespace ept::debtags;
 using namespace ept::apt;
-using namespace ept::textsearch;
 
-char* tagString(const Tag& tag)
+char* tagString(const std::string& tag)
 {
 	static map<string, char*> table;
-	map<string, char*>::iterator i = table.find(tag.fullname());
+	map<string, char*>::iterator i = table.find(tag);
 	if (i == table.end())
 	{
 		pair< map<string, char*>::iterator, bool > tmp =
-			table.insert(make_pair(tag.fullname(), strdup(tag.fullname().c_str())));
+			table.insert(make_pair(tag, strdup(tag.c_str())));
 		i = tmp.first;
 	}
 	return i->second;
@@ -128,18 +127,18 @@
 		cerr << "PKG " << pkg.package() << " - " << pkg.shortDescription() << endl;
 	}
 
-	const set<Tag>& ttags = engine.types();
-	for (set<Tag>::const_iterator i = ttags.begin();
+	const set<string>& ttags = engine.types();
+	for (set<string>::const_iterator i = ttags.begin();
 			i != ttags.end(); ++i)
 	{
-		cerr << "TTAG " << i->fullname() << endl;
+		cerr << "TTAG " << *i << endl;
 	}
 
-	const set<Tag>& ftags = engine.interfaces();
-	for (set<Tag>::const_iterator i = ftags.begin();
+	const set<string>& ftags = engine.interfaces();
+	for (set<string>::const_iterator i = ftags.begin();
 			i != ftags.end(); ++i)
 	{
-		cerr << "ITAG " << i->fullname() << endl;
+		cerr << "ITAG " << *i << endl;
 	}
 }
 
@@ -186,26 +185,30 @@
 
 	// FIXME: there are better ways to remember the previous item
 	
-	const set<Tag> types = engine.types();
+	const set<string> types = engine.types();
 	int newIdx = 0;
-	for (set<Tag>::const_iterator i = types.begin();
+	for (set<string>::const_iterator i = types.begin();
 			i != types.end(); ++i)
 	{
-		int idx = ui.TypeSelection->add(gettext(i->shortDescription().c_str()),
+		const voc::TagData* td = engine.voc().tagData(*i);
+		if (!td) continue;
+		int idx = ui.TypeSelection->add(gettext(td->shortDescription().c_str()),
 							0, NULL, tagString(*i), FL_NORMAL_LABEL);
-		if (i->fullname() == oldType)
+		if (*i == oldType)
 			newIdx = idx;
 	}
 	ui.TypeSelection->value(newIdx);
 	
-	const set<Tag> ifaces = engine.interfaces();
+	const set<std::string> ifaces = engine.interfaces();
 	newIdx = 0;
-	for (set<Tag>::const_iterator i = ifaces.begin();
+	for (set<std::string>::const_iterator i = ifaces.begin();
 			i != ifaces.end(); ++i)
 	{
-		int idx = ui.InterfaceSelection->add(gettext(i->shortDescription().c_str()),
+		const voc::TagData* td = engine.voc().tagData(*i);
+		if (!td) continue;
+		int idx = ui.InterfaceSelection->add(gettext(td->shortDescription().c_str()),
 							0, NULL, tagString(*i), FL_NORMAL_LABEL);
-		if (i->fullname() == oldIface)
+		if (*i == oldIface)
 			newIdx = idx;
 	}
 	ui.InterfaceSelection->value(newIdx);
@@ -223,7 +226,7 @@
 
 		Fl_Color bk(FL_WHITE);
 		Fl_Color fr(FL_BLACK);
-		set<Tag> tags = ui.engine->debtags().getTagsOfItem((const char *)rec.package().c_str());
+		set<std::string> tags = ui.engine->debtags().getTagsOfItem((const char *)rec.package().c_str());
 		switch (pkgfilter.TagsValue(tags))
 		{
 			case PackageFilter::Green:
@@ -265,8 +268,7 @@
 	//printf("CallBackTypeSelection\n");
 	//fflush(stdout);
 	GamesUI& ui = *static_cast<GamesUI*>(data);
-	Tag tag = ui.engine->voc().tagByName(ReadFlChoice(*choice));
-	ui.engine->setTypeFilter(tag);
+	ui.engine->setTypeFilter(ReadFlChoice(*choice));
 	UpdateUILists(ui);
 }
 
@@ -275,8 +277,7 @@
 	//printf("CallBackInterfaceSelection\n");
 	//fflush(stdout);
 	GamesUI& ui = *static_cast<GamesUI*>(data);
-	Tag tag = ui.engine->voc().tagByName(ReadFlChoice(*choice));
-	ui.engine->setInterfaceFilter(tag);
+	ui.engine->setInterfaceFilter(ReadFlChoice(*choice));
 	UpdateUILists(ui);
 }
 

Modified: software/ui/src/pkgbrowser.cpp
===================================================================
--- software/ui/src/pkgbrowser.cpp	2010-06-23 02:02:27 UTC (rev 11043)
+++ software/ui/src/pkgbrowser.cpp	2010-06-25 08:39:55 UTC (rev 11044)
@@ -66,7 +66,6 @@
 using namespace ept;
 using namespace ept::debtags;
 using namespace ept::apt;
-using namespace ept::textsearch;
 
 static const char legalchars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz at _?+-,.~/%&=:*#";
 
@@ -228,10 +227,14 @@
 			ui->DebTagsBrowser->column_widths(widths);
 			ui->DebTagsBrowser->add(_("@B12 at C7@b at .FACET\t at B12@C7 at b@.TAG"));
 
-			set<Tag> tags = ui->engine->debtags().getTagsOfItem((const char *)data);
+			set<std::string> tags = ui->engine->debtags().getTagsOfItem((const char *)data);
 			char *tag_txt = new char[512];
-			for (set<Tag>::const_iterator i = tags.begin(); i != tags.end(); ++i)
+			for (set<std::string>::const_iterator i = tags.begin(); i != tags.end(); ++i)
 			{
+				const voc::FacetData* fd = ui->engine->voc().facetData(voc::getfacet(*i));
+				const voc::TagData* td = ui->engine->voc().tagData(*i);
+				if (!fd || !td) continue;
+
 				// Available Colors: FL_BLACK, FL_BLUE, FL_CYAN, FL_DARK_BLUE,
 				// FL_DARK_CYAN, FL_DARK_GREEN FL_DARK_MAGENTA, FL_DARK_RED,
 				// FL_DARK_YELLOW, FL_GREEN, FL_MAGENTA, FL_RED, FL_WHITE, FL_YELLOW
@@ -253,9 +256,9 @@
 				}
 				snprintf(tag_txt, 512, "@B%d at C%d at .%s\t at B%d at C%d at .%s",
 					bk, fr,
-					gettext(i->facet().shortDescription().c_str()),
+					gettext(fd->shortDescription().c_str()),
 					bk, fr,
-					gettext(i->shortDescription().c_str())
+					gettext(td->shortDescription().c_str())
 				);
 				ui->DebTagsBrowser->add(tag_txt);
 			}




More information about the Pkg-games-commits mailing list