4

Apr

Filed in Code, Django |

One of my tasks lately has been updating the django-sphinx library to work with Sphinx 0.98, as it includes GIS components which we have been wanting to possibly utilize on our new search engine. So today, the conclusion of.. very few hours of work, I’d like to announce 2.0.0 of the Django integration.

The SphinxSearch manager has been completely rewritten to rely strictly on the Python Sphinx API (a request from the author of Sphinx), which means it should have much more compatibility with newer versions in the future. I have also updated the querysets it returns to work like normal Django QuerySet instances, to where they clone themselves so you can fork your queryset into several different actions.

The search results also now have a proxy which wraps each object. This proxy is specifically geared towards ticket #17, and allows you to access a _sphinx attribute on each instance, without actually modifying that instance. You can also now access a _sphinx attribute on the queryset itself. Both of these contain relative meta-data for their object.

So, a quick usage example using the new API:

In [1]: from sphinxtest.tests.models import *

In [2]: x = Document.search.query('a')

In [3]: x._sphinx
Out[3]:
{'total': 10,
 'total_found': 10,
 'words': [{'docs': 10, 'hits': 10, 'word': 'a'}]}

In [4]: x
Out[4]: [<Document: Document object>, <Document: Document object>, <Document: Document object>, <Document: Document object>, <Document: Document object>, <Document: Document object>, <Document: Document object>, <Document: Document object>, <Document: Document object>, <Document: Document object>]

In [5]: x[0]._sphinx
Out[5]: {'weight': 1}

In [6]: x[0].title
Out[6]: u'Document 0'

In [7]: type(x)
Out[7]: <class 'djangosphinx.SphinxSearch'>

In [8]: type(x[0])
Out[8]: <class 'djangosphinx.SphinxProxy'>

As you can see, it’s full backwards compatible. Calling queryset._sphinx will force evaluation on the queryset. Grab the release over at Google code.

Comments and criticism, send em my way :)

View Comments Responses to "Announcing django-sphinx 2.0.0 Full-text Search"

Subscribe to this topic with RSS or get the Trackback URL
kevin (Apr 5th):

thanks david. this looks like a great project. keep up the great work!

[...] Announcing django-sphinx 2.0.0 Full-text Search | David Cramer’s Blog [...]

mozam (Jun 9th):

I think you need to add ResetFilter to your class. If you add filters, they never get cleared so all subsequent queries are subject to the buildup of filters.

Awesome work, BTW.

Praveen (Jan 15th):

Hi David when i run
>>> from mysite.library.models import *
>>> x = Listing_channels.search.query(‘Bowling’)
>>> x

In your given example it returns list of object of Document class
>>> type(x)

It returns me manager for you sphinxSearch

I do not know how to deal with djangosphinx.manager

In my models.py
class Listing_channels(models.Model):
list_channel = models.CharField(max_length = 20)
visibility = models.BooleanField()
search = djangosphinx.SphinxSearch(index=”test”)
class Meta:
db_table = ‘library_listing_channels’

def __unicode__(self):
return self.list_channel

def get_search(self):
return u’/sigh_seeing/%s/’ % self.search
and print to html template

David (Jan 15th):

Please use http://groups.google.com/group/django-sphinx for usage questions. As for the “issue” which you posted which had the question in it, I didn’t see any problem. It returned a QuerySet result which is an iterator in django-sphinx.

Leave A Reply

 Username (*required)

 Email Address (*private)

 Website (*optional)

Note: Comments moderation may be active so there is no need to resubmit your comment.
blog comments powered by Disqus