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?
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
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
[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
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
Swish-e grants a special exemption from automatically GPL'ing linked
programs which use the libswish-e API interface:
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