Skip to content


Subversion checkout URL

You can clone with
Download ZIP


how to get xapian document from model #27

thoughtafter opened this Issue · 3 comments

2 participants


I know this is more of a question instead of an issue, unless this cannot be easily done, then it is an issue. I want to get the xapian document from a model. Specifically I'd like to do this to use find_similar_to:


Or something like that. Of course find_similar_to could potentially be updated to allow a model but I think this will have other applications as well. Basically I'm looking for an inverse of the indexed_object property. I'm thinking there's probably a Xapian method to retrieve a document by the xapian_id but I haven't dug deeply enough to find it.


If you want to find the xapian document that belongs to an active record model, you could try the following (not tested):

add index statements to your blueprints for the unique model id like so:

blueprint.index :model_id do

Now you should be able to search by model id and get max one hit: "model_id:address-22"


Yes that had occurred to me immediately but it seemed silly to index another field since we're already passing that string in twice, as "data" and as "unique term". It took a few hours of readings docs and source code but I came up with this:

def xapian_docid

def xapian_document

That doesn't quite work as expected (with these methods in the model) as the add_doc_helper_methods_to method has not been applied. But I thought maybe you'd have a better idea of how to integrate this into xapian_db than I would.


You could do it like this:

def xapian_document
  docid       = XapianDb.database.reader.postlist("Q#{xapian_id}").first.docid
  doc         = XapianDb.database.reader.document dicid
  blueprint   = XapianDb::DocumentBlueprint.blueprint_for
  doc.extend blueprint.accessors_module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.