{"id":16624257,"url":"https://github.com/dcramer/django-sphinx","last_synced_at":"2025-04-05T00:05:35.471Z","repository":{"id":625972,"uuid":"266288","full_name":"dcramer/django-sphinx","owner":"dcramer","description":"A transparent layer for full-text search using Sphinx and Django","archived":false,"fork":false,"pushed_at":"2015-11-28T12:57:15.000Z","size":461,"stargazers_count":357,"open_issues_count":29,"forks_count":122,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-02T12:54:03.773Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://groups.google.com/group/django-sphinx","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dcramer.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-08-01T05:02:06.000Z","updated_at":"2024-07-20T10:43:56.000Z","dependencies_parsed_at":"2022-07-18T09:08:55.035Z","dependency_job_id":null,"html_url":"https://github.com/dcramer/django-sphinx","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-sphinx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-sphinx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-sphinx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-sphinx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcramer","download_url":"https://codeload.github.com/dcramer/django-sphinx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266562,"owners_count":20910836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T03:45:41.823Z","updated_at":"2025-04-05T00:05:35.455Z","avatar_url":"https://github.com/dcramer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"**This project is no longer maintained**\n\nThis is a layer that functions much like the Django ORM does except it works on top of the Sphinx (http://www.sphinxsearch.com) full-text search engine.\n\nPlease Note: You will need to create your own sphinx indexes and install sphinx on your server to use this app.\n\n*There will no longer be release packages available. Please use SVN to checkout the latest trunk version, as it should always be stable and current.*\n\nInstallation\n------------\n\nTo install the latest stable version::\n\n\tsudo easy_install django-sphinx\n\nTo install the latest development version (updated quite often)::\n\n\tgit clone git://github.com/dcramer/django-sphinx.git  \n\tcd django-sphinx\n\tsudo python setup.py install\n\n*Note:* You will need to install the `sphinxapi.py` package into your Python Path or use one of the included versions. To use the included version, you must specify the following in your `settings.py` file::\n\n\t# Sphinx 0.9.9\n\tSPHINX_API_VERSION = 0x116\n\n\t# Sphinx 0.9.8\n\tSPHINX_API_VERSION = 0x113\n\n\t# Sphinx 0.9.7\n\tSPHINX_API_VERSION = 0x107\n\nUsage\n-----\n\nThe following is some example usage::\n\n\tfrom djangosphinx.models import SphinxSearch\n\t\n\tclass MyModel(models.Model):\n\t    search = SphinxSearch() # optional: defaults to db_table\n\t    # If your index name does not match MyModel._meta.db_table\n\t    # Note: You can only generate automatic configurations from the ./manage.py script\n\t    # if your index name matches.\n\t    search = SphinxSearch('index_name')\n\n\t    # Or maybe we want to be more.. specific\n\t    searchdelta = SphinxSearch(\n\t        index='index_name delta_name',\n\t        weights={\n\t            'name': 100,\n\t            'description': 10,\n\t            'tags': 80,\n\t        },\n\t        mode='SPH_MATCH_ALL',\n\t        rankmode='SPH_RANK_NONE',\n\t    )\n\n\tqueryset = MyModel.search.query('query')\n\tresults1 = queryset.order_by('@weight', '@id', 'my_attribute')\n\tresults2 = queryset.filter(my_attribute=5)\n\tresults3 = queryset.filter(my_other_attribute=[5, 3,4])\n\tresults4 = queryset.exclude(my_attribute=5)[0:10]\n\tresults5 = queryset.count()\n\n\t# as of 2.0 you can now access an attribute to get the weight and similar arguments\n\tfor result in results1:\n\t    print result, result._sphinx\n\t# you can also access a similar set of meta data on the queryset itself (once it's been sliced or executed in any way)\n\tprint results1._sphinx\n\n\nSome additional methods:\n* count()\n* extra() (passed to the queryset)\n* all() (does nothing)\n* select_related() (passed to the queryset)\n* group_by(field, field, field)\n* set_options(index='', weights={}, weights=[], mode='SPH_MODE_*', rankmode='SPH_MATCH_*')\n\nThe django-sphinx layer also supports some basic querying over multiple indexes. To use this you first need to understand the rules of a UNION. Your indexes must contain exactly the same fields. These fields must also include a `content_type` selection which should be the content_type id associated with that table (model).\n\nYou can then do something like this::\n\n\tfrom djangosphinx.models import SphinxSearch\n\t\n\tSphinxSearch('index1 index2 index3').query('hello')\n\nThis will return a list of all matches, ordered by weight, from all indexes. This performs one SQL query per index with matches in it, as Django's ORM does not support SQL UNION.\n\nConfig Generation\n-----------------\n\ndjango-sphinx now includes a tool to create sample configuration for your models. It will generate both a source, and index configuration for a model class. You will still need to manually tweak the output, and insert it into your configuration, but it should aid in initial setup.\n\nTo use it::\n\n\tfrom djangosphinx.utils import *\n\n\tfrom myproject.myapp.models import MyModel\n\n\toutput = generate_config_for_model(MyModel)\n\n\tprint output\n\nIf you have multiple models which you wish to use the UNION searching::\n\n\tmodel_classes = (ModelOne, ModelTwoWhichResemblesModelOne)\n\n\toutput = generate_config_for_models(model_classes)\n\nYou can also now output configuration from the command line::\n\n\t./manage.py generate_sphinx_config \u003cappname\u003e\n\nThis will loop through all models in \u003cappname\u003e and attempt to find any with a SphinxSearch instance that is using the default index name (db_table).\n\nUsing the Config Generator\n--------------------------\n\n*New in 2.2*\n\ndjango-sphinx now includes a simply python script to generate a config using your default template renderer. By default, we mean that if `coffin` is included in your INSTALLED_APPS, it uses it, otherwise it uses Django.\n\nTwo variables directly relate to the config generation:\n\n\t# The base path for sphinx files. Sub directories will include data, log, and run.\n\tSPHINX_ROOT = '/var/sphinx-search/'\n\t\n\t# Optional, defaults to 'conf/sphinx.html'. This should be configuration template.\n\t# See the included templates/sphinx.conf for an example.\n\tSPHINX_CONFIG_TEMPLATE = 'conf/sphinx.html'\n\nOnce done, your config can be passed via any sphinx command like so:\n\n\t# Index your stuff\n\tDJANGO_SETTINGS_MODULE=myproject.settings indexer --config /path/to/djangosphinx/config.py --all --rotate\n\t\n\t# Start the daemon\n\tDJANGO_SETTINGS_MODULE=myproject.settings searchd --config /path/to/djangosphinx/config.py\n\t\n\t# Query the daemon\n\tDJANGO_SETTINGS_MODULE=myproject.settings search --config /path/to/djangosphinx/config.py my query\n\t\n\t# Kill the daemon\n\tkill -9 $(cat /var/sphinx-search/run/searchd.pid)\n\nFor now, we recommend you setup some basic bash aliases or scripts to deal with this. This is just the first step in embedded config generation, so stay tuned!\n\n* Note: Make sure your PYTHON_PATH is setup properly!\n\nUsing Sphinx in Admin\n---------------------\n\nSphinx includes it's own ModelAdmin class to allow you to use it with Django's built-in admin app.\n\nTo use it, see the following example::\n\n\tfrom djangosphinx.admin import SphinxModelAdmin\n\t\n\tclass MyAdmin(SphinxModelAdmin):\n\t\tindex = 'my_index_name' # defaults to Model._meta.db_table\n\t\tweights = {'field': 100}\n\nLimitations? You know it.\n\n- Only shows your max sphinx results (defaults to 1000)\n- Filters currently don't work.\n- This is a huge hack, so it may or may not continue working when Django updates.\n\nFrequent Questions\n------------------\n\n*How do I run multiple copies of Sphinx using django-sphinx?*\n\nThe easiest way is to just run a different SPHINX_PORT setting in your settings.py. If you are using the above config generation, just modify the PORT, and start up the daemon\n\nResources\n---------\n\n* http://groups.google.com/group/django-sphinx\n* http://www.davidcramer.net/code/65/setting-up-django-with-sphinx.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcramer%2Fdjango-sphinx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcramer%2Fdjango-sphinx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcramer%2Fdjango-sphinx/lists"}