Package: goplay
Version: 0.5-1.1
Severity: wishlist
Tags: patch

Hello,

I've worked on a patch which reduces the dependency on libept in favour
of just using the Xapian index for accessing popcon.

This makes it easier for me to reduce the libept codebase in the future,
and it means that goplay can work without requiring download of the
popcon data.

Can we do an upload with this before jessie freezes?

Ciao,

Enrico

-- System Information:
Debian Release: jessie/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.10-3-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages goplay depends on:
ii  apt-xapian-index  0.46
ii  debtags           1.11
ii  libapt-pkg4.12    0.9.11.4
ii  libc6             2.17-93
ii  libept1.4.12      1.0.11
ii  libfltk1.1        1.1.10-16
ii  libgcc1           1:4.8.1-10
ii  libstdc++6        4.8.1-10
ii  libxapian22       1.2.15-2
ii  zlib1g            1:1.2.8.dfsg-1

Versions of packages goplay recommends:
ii  games-thumbnails  20120227

goplay suggests no packages.

-- no debconf information
>From 4eab891fac5fd57c9d4fdb924e2683bb3f432ba1 Mon Sep 17 00:00:00 2001
From: Enrico Zini <enr...@enricozini.org>
Date: Thu, 24 Oct 2013 20:09:19 +0200
Subject: [PATCH] Do not depend on ept::axi and ept::popcon

---
 README         | 22 +++++++---------------
 src/Engine.cpp | 42 ++++++++++++++++++++++++++++++++++++------
 src/Engine.h   | 14 +++++++-------
 src/goplay.cpp |  4 ++--
 4 files changed, 52 insertions(+), 30 deletions(-)

diff --git a/README b/README
index ea4553f..010500d 100644
--- a/README
+++ b/README
@@ -41,23 +41,15 @@ Building instructions
   ./configure
   make
 
-Running instructions
---------------------
+Troubleshooting
+---------------
 
-Before running the first time, you need to setup ept:
+ * Missing /var/lib/apt-xapian-index/index
 
-  apt-get install ept-cache
+If goplay complains that /var/lib/apt-xapian-index/index does not exist, it
+could be that you just installed apt-xapian-index and the index is still being
+built. Just run `update-apt-xapian-index' as root to rebuild the index or see
+the progress of a running indexer.
 
-Then run "ept-cache info" and follow the instructions.  It is usually something
-like this:
-
-  apt-get install debtags
-  debtags update
-  mkdir /var/lib/popcon/
-  cd /var/lib/popcon
-  wget http://popcon.debian.org/all-popcon-results.txt.gz
-  ept-cache reindex
-
-Then you can finally run ./goplay
 
 Enjoy!
diff --git a/src/Engine.cpp b/src/Engine.cpp
index 0ad9c81..a6e8e9f 100644
--- a/src/Engine.cpp
+++ b/src/Engine.cpp
@@ -1,7 +1,7 @@
 /*
  * Backend engine for game installer UI
  *
- * Copyright (C) 2003--2007  Enrico Zini <enr...@debian.org>
+ * Copyright (C) 2003--2013  Enrico Zini <enr...@debian.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@
 #include <wibble/string.h>
 #include <wibble/regexp.h>
 #include <iostream>
+#include <fstream>
 
 using namespace std;
 using namespace wibble;
@@ -30,7 +31,7 @@ using namespace ept::apt;
 using namespace ept::debtags;
 
 Engine::Engine()
-	: m_db(ept::axi::path_db()), m_stem("en"), m_filter_state(ANY), m_dirty(true), m_max(0)
+	: m_db("/var/lib/apt-xapian-index/index"), m_stem("en"), m_filter_state(ANY), m_dirty(true), m_max(0), m_popcon_validx(-1)
 {
 	m_qp.set_default_op(Xapian::Query::OP_AND);
         m_qp.set_database(m_db);
@@ -39,6 +40,25 @@ Engine::Engine()
         m_qp.add_prefix("pkg", "XP");
         m_qp.add_boolean_prefix("tag", "XT");
         m_qp.add_boolean_prefix("sec", "XS");
+
+        // Read the Xapian value index used for popcon data
+        std::ifstream in;
+        in.open("/var/lib/apt-xapian-index/values", ios::in);
+        if (!in.is_open() || in.fail())
+            m_popcon_validx = -1;
+        ERegexp match_line("^app-popcon[ \t]+([0-9]+)", 2);
+        string line;
+        while (true)
+        {
+            getline(in, line);
+            if (in.fail()) break;
+            if (in.eof()) break;
+            if (match_line.match(line))
+            {
+                m_popcon_validx = strtoul(match_line[1].c_str(), 0, 10);
+                break;
+            }
+        }
 }
 
 struct EngineMatchDecider : public Xapian::MatchDecider
@@ -147,6 +167,14 @@ Xapian::Query Engine::makeQuery()
 	return Xapian::Query(Xapian::Query::OP_AND, globalFilter, query);
 }
 
+float Engine::read_popcon(const Xapian::Document& doc) const
+{
+    if (m_popcon_validx == -1) return 0;
+    string val = doc.get_value(m_popcon_validx);
+    if (val.empty()) return 0;
+    return Xapian::sortable_unserialise(val);
+}
+
 void Engine::recompute()
 {
 	EngineMatchDecider md(*this);
@@ -244,8 +272,9 @@ void Engine::recompute()
 				//break;
 
 			Result res;
-			res.name = i.get_document().get_data();
-			res.popcon = m_popcon[res.name];
+            Xapian::Document doc = i.get_document();
+            res.name = doc.get_data();
+            res.popcon = read_popcon(doc);
 			res.relevance = i.get_percent();
 
 			if (res.popcon > m_res_max)
@@ -304,8 +333,9 @@ std::vector<Result> Engine::related(const std::string& name, int count) const
 	for (++mi; mi != matches.end(); ++mi)
 	{
 		Result res;
-		res.name = mi.get_document().get_data();
-		res.popcon = m_popcon[res.name];
+        Xapian::Document doc = mi.get_document();
+        res.name = doc.get_data();
+        res.popcon = read_popcon(doc);
 		res.relevance = mi.get_percent();
 		results.push_back(res);
 	}
diff --git a/src/Engine.h b/src/Engine.h
index 855450e..ff2607a 100644
--- a/src/Engine.h
+++ b/src/Engine.h
@@ -24,8 +24,7 @@
 #include <ept/apt/apt.h>
 #include <ept/debtags/debtags.h>
 #include <ept/debtags/vocabulary.h>
-#include <ept/axi/axi.h>
-#include <ept/popcon/popcon.h>
+#include <xapian.h>
 #include <string>
 #include <set>
 #include <vector>
@@ -71,9 +70,6 @@ protected:
 	/// Xapian query parser
 	Xapian::QueryParser m_qp;
 
-	/// Popcon scores
-	ept::popcon::Popcon m_popcon;
-
 	std::string m_filter_keywords;
 	std::string m_filter_type;
 	std::string m_filter_iface;
@@ -88,9 +84,13 @@ protected:
 	float m_max;
 	float m_res_max;
 
+    int m_popcon_validx;
+
 	Xapian::Query makeQuery();
 	void recompute();
 
+    float read_popcon(const Xapian::Document& doc) const;
+
 public:
 	/// Facet to use as the main package type
 	std::string mainFacet;
@@ -112,8 +112,8 @@ public:
 	/// Access the tag vocabulary
 	ept::debtags::Vocabulary& voc() { return m_vocabulary; }
 
-	/// Access the popcon data source
-	ept::popcon::Popcon& popcon() { return m_popcon; }
+    /// Check if popcon data is available
+    bool hasPopcon() const { return m_popcon_validx != -1; }
 
 	/// Get the list of available game types
 	const std::set<std::string>& types()
diff --git a/src/goplay.cpp b/src/goplay.cpp
index 6cf93b6..7868f18 100644
--- a/src/goplay.cpp
+++ b/src/goplay.cpp
@@ -173,7 +173,7 @@ static void UpdateUILists(GamesUI& ui)
 	static int widths_with_popcon[] = { 100, 300, 0 }; // widths for each column
 	static int widths_without_popcon[] = { 100, 0 };
 	ui.ResultsBrowser->clear();
-	if (engine.popcon().hasData())
+	if (engine.hasPopcon())
 	{
 		char empty_string[1] = "";
 		ui.ResultsBrowser->column_widths(widths_with_popcon);
@@ -251,7 +251,7 @@ static void UpdateUILists(GamesUI& ui)
 
 		string desc = string(fmtstr) + rec.package() + "\t" + 
 			string(fmtstr) + rec.shortDescription();
-		if (engine.popcon().hasData() && i->popcon)
+		if (engine.hasPopcon() && i->popcon)
 		{
 			desc += "\t" + string(fmtstr);
 			char stars[16];
-- 
1.8.4.rc3

Reply via email to