search for the orm – djugl april 2009
TRANSCRIPT
-
8/8/2019 Search for the ORM DJUGL April 2009
1/15
Search for the ORMBen Firshman http://benfirshman.com/
http://benfirshman.com/http://benfirshman.com/ -
8/8/2019 Search for the ORM DJUGL April 2009
2/15
djangosearch
Originally a Solr interface by Joseph
Kocherhans and Jacob Kaplan-Moss.
For the Google Summer of Code, I added a
QuerySet style interface and other
backends.
Adding SQL database backends to
djangosearch was the wrong approach.
-
8/8/2019 Search for the ORM DJUGL April 2009
3/15
SQL full text support
PostgreSQL, MySQL, SQLite and Oracle allhave full text search built in.
The __search field lookup for filter()
already exists, why not build on that?
-
8/8/2019 Search for the ORM DJUGL April 2009
4/15
__search lookup
Only one field is searched.
Indexes arent created automatically.
Only MySQL support.
-
8/8/2019 Search for the ORM DJUGL April 2009
5/15
What do we need?
-
8/8/2019 Search for the ORM DJUGL April 2009
6/15
What do we need?
Searching over multiple fields, alongside the
__search lookup.
-
8/8/2019 Search for the ORM DJUGL April 2009
7/15
What do we need?
Searching over multiple fields, alongside the
__search lookup.
Automatic index creation.
-
8/8/2019 Search for the ORM DJUGL April 2009
8/15
What do we need?
Searching over multiple fields, alongside the
__search lookup.
Automatic index creation.
Relevance.
-
8/8/2019 Search for the ORM DJUGL April 2009
9/15
What do we need?
Searching over multiple fields, alongside the
__search lookup.
Automatic index creation.
Relevance.
Generic search views.
-
8/8/2019 Search for the ORM DJUGL April 2009
10/15
What do we need?
Searching over multiple fields, alongside the
__search lookup.
Automatic index creation.
Relevance.
Generic search views.
Support for all databases.
-
8/8/2019 Search for the ORM DJUGL April 2009
11/15
The Solution
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateTimeField()
body = models.TextField()
class Meta:
ordering = ('pub_date','headline')
def __unicode__(self):
return self.headline
-
8/8/2019 Search for the ORM DJUGL April 2009
12/15
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
-
8/8/2019 Search for the ORM DJUGL April 2009
13/15
The Solution
>>> Article.objects.search('alpha')
[, ]
>>> Article.objects.search('beta')[, ]
>>> _.order_by('-search__relevance')
[, ]
>>> Article.objects.filter(body__search='prague')
[]
-
8/8/2019 Search for the ORM DJUGL April 2009
14/15
What about other
engines? Solr, Xapian, Sphinx, Whoosh...
All existing projects are fairly similar, weshould collaborate.
Decide on a user API and write backends.
django-haystack looks particularlypromising.
-
8/8/2019 Search for the ORM DJUGL April 2009
15/15
Try it out!
http://github.com/bfirsh/django/tree/search
http://benfirshman.com/ @bfirsh
http://github.com/bfirsh/django/tree/searchhttp://github.com/bfirsh/django/tree/searchhttp://github.com/bfirsh/django/tree/searchhttp://github.com/bfirsh/django/tree/searchhttp://github.com/bfirsh/django/tree/searchhttp://github.com/bfirsh/django/tree/search