It seems I suck at documentation (yes, It’s very true), so here’s a quick How-to on using the Sphinx ORM for Django we created:
- Download and install Sphinx (you’re on your own here): http://www.sphinxsearch.com/
- Download and install the Django Sphinx package: http://django-sphinx.googlecode.com/ (again, on your own)
- Setup a source for your table:
source files_file_en : base { sql_query = \ SELECT files_file.id, files_file.name, files_data.description, files_file.tags as tag \ FROM files_file JOIN files_data \ ON files_file.id = files_data.file_id \ AND files_data.lang = 'en' \ AND files_file.visible = 1 \ GROUP BY files_file.id sql_query_info = SELECT * FROM files_file WHERE id=$id } - Setup an index for your table:
index files_file_en { source = files_file_en path = /var/data/files_file_en docinfo = extern morphology = none stopwords = min_word_len = 2 charset_type = sbcs min_prefix_len = 0 min_infix_len = 0 } - Go into your models and add the import:
from cursesite.core.search.models import SphinxSearch
- Go to the model you want to attach the search to:
search = SphinxSearch(index="files_file_en")
- Now query:
File.search.query('hello')
3 Responses to "Setting up Django with Sphinx Full-text Search"
Hi David,
Thanks for django-sphinx, I spent much of sunday setting up sphinx (first time) and fiddling with this (BTW: I’m also new to django).
Wonder if I could ask a couple of questions?
1. In your example above, I’m assuming ‘File’ the model class you have attached the ’search’ attribute to?
2. Am I correct in assuming that File.search.query(’q') would return a list of Model objects?
3. I used the setup.py to install django-sphinx, but looking at your example above, you seem to have it in a utility module, can I just do that if I prefer?
3. I’m having a little trouble understanding how this relates exactly to the rest of Django - would it be possible to see a slightly more complete example of a view?
Once again - thanks very much for sharing this !!!!
Rich, you’ve convinced me to stop being lazy: http://www.davidcramer.net/code/79/in-depth-django-sphinx-tutorial.html
That was blazingly fast!
Thank you very much indeed, that is a more complete picture.
I’m at work at the moment, but this evening, I’ll be working on my sphinx search page!
Cheers
- rich
Leave A Reply