{ "info": { "author": "Ben Timby", "author_email": "btimby@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "A `SmartFile`_ Open Source project. `Read more`_ about how SmartFile\nuses and contributes to Open Source software.\n\n.. figure:: http://www.smartfile.com/images/logo.jpg\n :alt: SmartFile\n\nIntroduction\n------------\n\nThis is a simple Django database backend that allows interaction with Sphinx\nvia SphinxQL. It is basically the default Django MySQL backend with some changes\nfor Sphinx.\n\nSphinxQL is a MySQL clone mode that Sphinx searchd supports. It allows you to\nquery indexes via regular old SQL syntax. If you are using rt (real-time) indexes,\nyou can also add and update documents in the index.\n\nThis backend is meant to be configued as a database in the Django settings.py.\n\nThis package provides a Manager class, SQLCompiler suite and supporting code to\nmake this possible.\n\nUsage\n-----\n\nFirst of all, you must define a database connection in the Django configuration.\nYou must also install the Sphinx database router and add django_sphinx_db to your\nINSTALLED_APPS list.\n\n::\n\n # Install django_sphinx_db:\n INSTALLED_APPS += ('django_sphinx_db', )\n\n # This is the name of the sphinx server in DATABASES:\n SPHINX_DATABASE_NAME = 'sphinx'\n\n # Define the connection to Sphinx\n DATABASES = {\n 'default': {\n # Your default database connection goes here...\n },\n SPHINX_DATABASE_NAME: {\n 'ENGINE': 'django_sphinx_db.backend.sphinx',\n # The database name does not matter.\n 'NAME': '',\n # There is no user name or password.\n 'USER': '',\n 'PASSWORD': '',\n # Don't use localhost, this will result in using a UDS instead of TCP...\n 'HOST': '127.0.0.1',\n 'PORT': '9306',\n },\n }\n\n # ... and route accordingly ...\n DATABASE_ROUTERS = (\n 'django_sphinx_db.routers.SphinxRouter',\n ) ```\n\nThen define a model that derives from the SphinxModel. As usual, the model will be placed in models.py.\n\n::\n\n from django_sphinx_db.backend.models import SphinxModel, SphinxField\n\n class MyIndex(SphinxModel):\n class Meta:\n # This next bit is important, you don't want Django to manage\n # the table for this model.\n managed = False\n\n name = SphinxField()\n content = SphinxField()\n date = models.DateTimeField()\n size = models.IntegerField()\n\nConfiguring Sphinx\n------------------\n\nNow you need to generate a configuration file for your index. A management\ncommand is provided to convert the model definition to a suitable configuration.\n\n::\n\n $ python manage.py syncsphinx >> /etc/sphinx.conf\n $ vi /etc/sphinx.conf\n\nThe generated config file should be a good start however, you are urged to\nreview the configuration against the\n[Sphinx configuration reference](http://sphinxsearch.com/docs/2.0.2/confgroup-index.html).\n\nUsing the Django ORM with Sphinx\n--------------------------------\n\nYou can now query and manage your real-time index using the Django ORM. You can\ninsert and update documents in the index using the following methods. The example\nbelow uses the [fulltext library](https://github.com/btimby/fulltext) for reading\nfile contents as plain text.\n\n::\n\n import os, time, fulltext\n\n # Add a document to the index.\n path = 'resume.doc'\n st = os.stat(path)\n MyIndex.objects.create(\n name = path,\n content = fulltext.get(path, ''),\n size = st.st_size,\n date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(st.st_mtime)),\n )\n\n # Update a document in the index\n doc = MyIndex.objects.get(pk=1)\n doc.content = fulltext.get(path, '')\n doc.size = st.st_size\n doc.date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(st.st_mtime))\n doc.save()\n\nYou can perform full-text queries using the Django `search` operator. Read the\n`Django documentation`_ for more information.\n\n::\n\n MyIndex.objects.filter(content__search='Foobar')\n\nThe query is passed through directly to Sphinx, so the\n`Sphinx extended query syntax`_\nis respected.\n\nUnit Testing\n------------\n\nThe Sphinx backend for Django will ignore create_test_db and destroy_test_db calls. These\ncalls will fail when the Sphinx database is configured, preventing you from running tests.\nHowever, this means that any configured Sphinx database will be used during testing. As\nlong as you write your tests with this in mind, there should be no problem. Remember that you\ncan use the TEST_NAME database connection parameter to redirect queries to a different database\nconnection during test runs.\n\n.. _SmartFile: http://www.smartfile.com/\n.. _Read more: http://www.smartfile.com/open-source.html\n.. _Django documentation: https://docs.djangoproject.com/en/dev/ref/models/querysets/#search\n.. _Sphinx extended query syntax: http://sphinxsearch.com/docs/2.0.2/extended-syntax.html", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/downloads/smartfile/django-sphinx-db/django-sphinx-db-0.1-3.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/smartfile/django-sphinx-db/", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "django-sphinx-db", "package_url": "https://pypi.org/project/django-sphinx-db/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-sphinx-db/", "project_urls": { "Download": "https://github.com/downloads/smartfile/django-sphinx-db/django-sphinx-db-0.1-3.tar.gz", "Homepage": "http://github.com/smartfile/django-sphinx-db/" }, "release_url": "https://pypi.org/project/django-sphinx-db/0.1-3/", "requires_dist": null, "requires_python": null, "summary": "Django database backend for SphinxQL.", "version": "0.1-3" }, "last_serial": 802930, "releases": { "0.1-3": [] }, "urls": [] }