On Tue, Jan 22, 2008 at 07:05:37AM -0800, Daniel Burrows wrote:

> > However, with regards to dependencies, you may consider skipping libept
> > and the debtags index altogether, and just look at Xapian and the index
> > built by apt-xapian-index into /var/lib/apt-xapian-index/.
> 
>   While Xapian is on the very long list of things I want to work on, I
> don't see how this relates to the bug report in question?  Users
> evidently want debtags support, and I don't see how xapian-index
> provides it.  In particular, how do I look up a package's tags from its
> name (the main thing aptitude does with debtags) using xapian?

This way (I drafted in python so I could quickly test it, but the C++
code isn't very different):

  #!/usr/bin/python
  
  import xapian
  
  # Access the Xapian index
  db = xapian.Database("/var/lib/apt-xapian-index/index")
  
  # Look for packages by name (term with XP prefix, see
  # /var/lib/apt-xapian-index/README)
  query = xapian.Query('XPdebtags')
  
  # Perform the query
  enquire = xapian.Enquire(db)
  enquire.set_query(query)
  
  # Get the first and only element
  matches = enquire.get_mset(0, 1)
  for m in matches:
      # Print only those terms of the document that are tags (XT prefix)
      for term in [t.term for t in m[xapian.MSET_DOCUMENT].termlist() if 
t.term.startswith("XT")]:
          print term[2:]

Using other prefixes you can access any other information that is
indexed in apt-xapian-index that is not indexed in apt (at the moment,
the only such thing is Debtags, but anything may follow).

Numeric information is accessed using:

      print m[xapian.MSET_DOCUMENT].get_value(id)

where the id can be looked up in /var/lib/apt-xapian-index/values;
popcon information is going to end up there, for example.


If you want to *just* get the tags of a package, libept is quite
straightforward; you can have a look at Xapian if you want to leave open
the possibility of using apt-xapian-index also for something more than
just accessing the tags, like fast full text search with tag filter,
access data indexed by extra plugins, sort by popcon, sort by relevance
and so on.


Ciao,

Enrico

-- 
GPG key: 1024D/797EBFAB 2000-12-05 Enrico Zini <[EMAIL PROTECTED]>

Attachment: signature.asc
Description: Digital signature

Reply via email to