Search Functionality

46 views
Skip to first unread message

Kevin

unread,
Dec 28, 2005, 4:25:15 PM12/28/05
to Django users
Could anyone provide some hints on how they have implemented search
functionality on their web site? Did you do it django or use another
middleware (eg, Lucene)? If you did it django, did you bypass the ORM
and use direct SQL to take advantage of full text search?

I'm currently trying to build the functionality directly in django's
ORM as a cascade of functions that would retrieve matches in decreasing
relevance, eg:

class Article(meta.Model):
title = meta.CharField()
description = meta.TextField()
keywords = meta.CharField()

def search(request, term):
matches = []
matches.extend(findExactTitle(term))
matches.extend(findInTitle(term))
matches.extend(findInKeywords(term))
matches.extend(findInDescription(term))

render_to_response('search_results', {'matches': matches}

Any ideas? Suggestions?

James Bennett

unread,
Dec 28, 2005, 4:58:20 PM12/28/05
to django...@googlegroups.com
On 12/28/05, Kevin <kevin...@gmail.com> wrote:
> Could anyone provide some hints on how they have implemented search
> functionality on their web site? Did you do it django or use another
> middleware (eg, Lucene)? If you did it django, did you bypass the ORM
> and use direct SQL to take advantage of full text search?

You may want to give this a try:
https://simon.bofh.ms/cgi-bin/trac-django-projects.cgi/wiki/AbstractSearching

I haven't yet had an opportunity to use it myself, but it seems to be
what you're looking for.


--
"May the forces of evil become confused on the way to your house."
-- George Carlin

Adrian Holovaty

unread,
Dec 29, 2005, 10:31:01 AM12/29/05
to django...@googlegroups.com
On 12/28/05, Kevin <kevin...@gmail.com> wrote:
> Could anyone provide some hints on how they have implemented search
> functionality on their web site? Did you do it django or use another
> middleware (eg, Lucene)? If you did it django, did you bypass the ORM
> and use direct SQL to take advantage of full text search?

Hey Kevin,

At World Online, the search engine (lawrence.com/search,
ljworld.com/search) uses swish-e (http://swish-e.org/) to index files.

We made a small script that reads a custom Django setting
(FULL_TEXT_INDEXING) to find out which models need to be indexed. The
indexer runs on a regular basis; for each to-be-indexed model, it
grabs all items in the system using get_list() (with optional limiting
kwargs designated in FULL_TEXT_INDEXING), renders each result in a
template according to its content type, and indexes the resulting
rendered template.

Then, when somebody does a search on the site, we use swish-e's Python
bindings to retrieve the IDs of the objects that match the search
criteria. Then we use Django's get_in_bulk() to retrieve the actual
objects. get_in_bulk() takes a list of IDs and returns a dictionary of
{id: object}. (Trivia: get_in_bulk() was created to solve this exact
problem.)

Hope that helps! It would be pretty cool to open-source this mini
search framework and pop it in django/contrib, but that would be up to
Jacob to decide.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

Jacob Kaplan-Moss

unread,
Dec 29, 2005, 3:23:24 PM12/29/05
to django...@googlegroups.com
On Dec 29, 2005, at 9:31 AM, Adrian Holovaty wrote:
> At World Online, the search engine (lawrence.com/search,
> ljworld.com/search) uses swish-e (http://swish-e.org/) to index files.

[snip]

> Hope that helps! It would be pretty cool to open-source this mini
> search framework and pop it in django/contrib, but that would be up to
> Jacob to decide.

I'd love to open it up; I don't see any reason that we'd need to keep
it hidden. I'll put it on my todo list :)

Jacob

David Pratt

unread,
Dec 29, 2005, 9:59:55 PM12/29/05
to django...@googlegroups.com
Hi Jacob and Adrian.

Doesn't Swish-e pose an incompatibility for licensing? Everything Django
has been BSD up to this point and I would hate to see anything alter
this. Isn't swish-e gpl?

Regards,
David

Tom Tobin

unread,
Dec 29, 2005, 11:06:12 PM12/29/05
to django...@googlegroups.com
On 12/29/05, David Pratt <fair...@eastlink.ca> wrote:
>
> Doesn't Swish-e pose an incompatibility for licensing? Everything Django
> has been BSD up to this point and I would hate to see anything alter
> this. Isn't swish-e gpl?

Swish-e grants a special exemption from automatically GPL'ing linked
programs which use the libswish-e API interface:

http://swish-e.org/license.html

Jacob Kaplan-Moss

unread,
Dec 30, 2005, 12:05:42 AM12/30/05
to django...@googlegroups.com
> http://swish-e.org/license.htmll

Plus, this would be a contributed app -- or possible something
distributed separately from Django -- that requires you to install
Swish-E separately. I don't see this being a core part of Django.

Seriously, though, this licensing stuff sucks :(

Jacob

Kevin

unread,
Dec 31, 2005, 10:33:19 PM12/31/05
to Django users
That would be great. I think it would a strong benefit to many django
users as search is such a common problem.

Reply all
Reply to author
Forward
0 new messages