Professional Documents
Culture Documents
class Meta:
ordering = ('pub_date','headline')
def __unicode__(self):
return self.headline
The Solution
class Article(models.Model):
headline = models.CharField(max_length=100,
search_index=True, search_weight=1)
pub_date = models.DateTimeField()
body = models.TextField(search_index=True,
search_weight=0.3)
class Meta:
ordering = ('pub_date','headline')
def __unicode__(self):
return self.headline
The Solution
>>> Article.objects.search('alpha')
[<Article: Django 1.1 alpha 1 released>, <Article:
Django 1.1 beta released>]
>>> Article.objects.search('beta')
[<Article: Django 1.1 alpha 1 released>, <Article:
Django 1.1 beta released>]
>>> _.order_by('-search__relevance')
[<Article: Django 1.1 beta released>, <Article:
Django 1.1 alpha 1 released>]
>>> Article.objects.filter(body__search='prague')
[<Article: EuroDjangoCon 2009>]
What about other
engines?
• Solr, Xapian, Sphinx, Whoosh...
• All existing projects are fairly similar, we
should collaborate.
• Decide on a user API and write backends.
• django-haystack looks particularly
promising.
Try it out!
http://github.com/bfirsh/django/tree/search
http://benfirshman.com/ @bfirsh