Djapian 2.3.1

High level Xapian integration for Django
Djapian is a Python package to allow full text search in your Django Project.

Usage example:

Assume that we have this models in our imaginary application:

class Person(models.Model):
 name = models.CharField(max_length=150)

 def __unicode__(self):
 return self.name

class Entry(models.Model):
 author = models.ForeignKey(Person, related_name="entries")
 title = models.CharField(max_length=250)
 created_on = models.DateTimeField(default=datetime.now)

 is_active = models.BooleanField(default=True)

 text = models.TextField()

 editors = models.ManyToManyField(Person, related_name="edited_entries")

 def headline(self):
 return "%s - %s" % (self.author, self.title)

 def __unicode__(self):
 return self.title


And we want to apply indexing functionality for model Entry. The next step is to create Indexer instance with proper settings. Indexer may look like this:

entry_indexer = Indexer(
 model=Entry,
 fields=["text"],
 tags=[
 ("author", "author.name" ),
 ("title", "title", 3),
 ("date", "created_on" ),
 ("active", "is_active" ),
 ("editors", "editors" )
 ],
 trigger=lambda obj: obj.is_active,
 )


In the django shell create some instances of models:

>>> p = Person.objects.create(name="Alex")
>>> Entry.objects.create(author=p, title="Test entry", text="Not large text field")
>>> Entry.objects.create(author=p, title="Another test entry", is_active=False)
>>> Entry.objects.create(author=p, title="Third small entry", text="Some another text")

>>> Entry.indexer.update()


Thats all! Each Entry instance has been indexed and now ready for search. Let's try:

>>> result = Entry.indexer.search('title:entry')
>>> len(result)
3
>>> for row in result:
... row.instance.headline()
...
Alex - Test entry
Alex - Another test entry
Alex - Third small entry

last updated on:
January 22nd, 2010, 22:37 GMT
price:
FREE!
developed by:
Alex Koshelev
homepage:
code.google.com
license type:
BSD License 
category:
ROOT \ Text Editing&Processing \ Indexing

FREE!

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Rate it!

Add your review!

SUBMIT