[Debtags-commits] [svn] r1869 - python

Enrico Zini enrico at costa.debian.org
Mon Aug 28 20:51:26 UTC 2006


Author: enrico
Date: Mon Aug 28 20:51:24 2006
New Revision: 1869

Modified:
   python/   (props changed)
   python/wxssearch
Log:
 r3215 at viaza:  enrico | 2006-08-28 17:01:03 +0100
 Use python-apt for the fulltext search, instead of calling apt-cache


Modified: python/wxssearch
==============================================================================
--- python/wxssearch	(original)
+++ python/wxssearch	Mon Aug 28 20:51:24 2006
@@ -105,16 +105,22 @@
 
     def setQuery(self, query):
         print "SetQuery", query
-        input = subprocess.Popen("apt-cache search " + query, shell=True, stdout = subprocess.PIPE, close_fds = True)
+        query = query.split()
 
-        # Read the package list and create the subcollection
-        pkgs = []
-        for pkg in input.stdout:
-            pkg, none = pkg.rstrip("\n").split(' - ', 1)
-            #print pkg
-            pkgs.append(pkg)
+        def match(pkg):
+            for q in query:
+                try:
+                    if pkg.name.find(q) == -1 and \
+                       pkg.rawDescription.find(q) == -1:
+                        return False
+                except UnicodeDecodeError:
+                    desc = pkg.rawDescription.decode("ascii", "replace")
+                    if pkg.name.find(q) == -1 and \
+                       desc.find(q) == -1:
+                        return False
+            return True
 
-        subcoll = self.fullcoll.choosePackages(pkgs)
+        subcoll = self.fullcoll.choosePackages(map(lambda x: x.name, filter(match, self.aptCache)))
 
         relIndex = Debtags.relevanceIndexFunction(self.fullcoll, subcoll)
 



More information about the Debtags-commits mailing list