1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
.. _ref-settings:
=================
Haystack Settings
=================
As a way to extend/change the default behavior within Haystack, there are
several settings you can alter within your ``settings.py``. This is a
comprehensive list of the settings Haystack recognizes.
``HAYSTACK_DEFAULT_OPERATOR``
=============================
**Optional**
This setting controls what the default behavior for chaining ``SearchQuerySet``
filters together is.
Valid options are::
HAYSTACK_DEFAULT_OPERATOR = 'AND'
HAYSTACK_DEFAULT_OPERATOR = 'OR'
Defaults to ``AND``.
``HAYSTACK_CONNECTIONS``
========================
**Required**
This setting controls which backends should be available. It should be a
dictionary of dictionaries resembling the following (complete) example::
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://localhost:9001/solr/default',
'TIMEOUT': 60 * 5,
'INCLUDE_SPELLING': True,
'BATCH_SIZE': 100,
'EXCLUDED_INDEXES': ['thirdpartyapp.search_indexes.BarIndex'],
},
'autocomplete': {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': '/home/search/whoosh_index',
'STORAGE': 'file',
'POST_LIMIT': 128 * 1024 * 1024,
'INCLUDE_SPELLING': True,
'BATCH_SIZE': 100,
'EXCLUDED_INDEXES': ['thirdpartyapp.search_indexes.BarIndex'],
},
'slave': {
'ENGINE': 'xapian_backend.XapianEngine',
'PATH': '/home/search/xapian_index',
'INCLUDE_SPELLING': True,
'BATCH_SIZE': 100,
'EXCLUDED_INDEXES': ['thirdpartyapp.search_indexes.BarIndex'],
},
'db': {
'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
'EXCLUDED_INDEXES': ['thirdpartyapp.search_indexes.BarIndex'],
}
}
No default for this setting is provided.
The main keys (``default`` & friends) are identifiers for your application.
You can use them any place the API exposes ``using`` as a method or kwarg.
There must always be at least a ``default`` key within this setting.
The ``ENGINE`` option is required for all backends & should point to the
``BaseEngine`` subclass for the backend.
Additionally, each backend may have additional options it requires:
* Solr
* ``URL`` - The URL to the Solr core. e.g. http://localhost:9001/solr/collection1
* ``ADMIN_URL`` - The URL to the administrative functions. e.g.
http://localhost:9001/solr/admin/cores
* Whoosh
* ``PATH`` - The filesystem path to where the index data is located.
* Xapian
* ``PATH`` - The filesystem path to where the index data is located.
The following options are optional:
* ``INCLUDE_SPELLING`` - Include spelling suggestions. Default is ``False``
* ``BATCH_SIZE`` - How many records should be updated at once via the management
commands. Default is ``1000``.
* ``TIMEOUT`` - (Solr and ElasticSearch) How long to wait (in seconds) before
the connection times out. Default is ``10``.
* ``STORAGE`` - (Whoosh-only) Which storage engine to use. Accepts ``file`` or
``ram``. Default is ``file``.
* ``POST_LIMIT`` - (Whoosh-only) How large the file sizes can be. Default is
``128 * 1024 * 1024``.
* ``FLAGS`` - (Xapian-only) A list of flags to use when querying the index.
* ``EXCLUDED_INDEXES`` - A list of strings (as Python import paths) to indexes
you do **NOT** want included. Useful for omitting third-party things you
don't want indexed or for when you want to replace an index.
* ``KWARGS`` - (Solr and ElasticSearch) Any additional keyword arguments that
should be passed on to the underlying client library.
* ``DATE_FACET_FIELD`` - (Solr-only) Support to ``date_facet`` on Solr >= 6.6.
Olders set ``date``. Default is ``range``.
``HAYSTACK_ROUTERS``
====================
**Optional**
This setting controls how routing is performed to allow different backends to
handle updates/deletes/reads.
An example::
HAYSTACK_ROUTERS = ['search_routers.MasterSlaveRouter', 'haystack.routers.DefaultRouter']
Defaults to ``['haystack.routers.DefaultRouter']``.
``HAYSTACK_SIGNAL_PROCESSOR``
=============================
**Optional**
This setting controls what ``SignalProcessor`` class is used to handle Django's
signals & keep the search index up-to-date.
An example::
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
Defaults to ``'haystack.signals.BaseSignalProcessor'``.
``HAYSTACK_DOCUMENT_FIELD``
===========================
**Optional**
This setting controls what fieldname Haystack relies on as the default field
for searching within.
An example::
HAYSTACK_DOCUMENT_FIELD = 'wall_o_text'
Defaults to ``text``.
``HAYSTACK_SEARCH_RESULTS_PER_PAGE``
====================================
**Optional**
This setting controls how many results are shown per page when using the
included ``SearchView`` and its subclasses.
An example::
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 50
Defaults to ``20``.
``HAYSTACK_CUSTOM_HIGHLIGHTER``
===============================
**Optional**
This setting allows you to specify your own custom ``Highlighter``
implementation for use with the ``{% highlight %}`` template tag. It should be
the full path to the class.
An example::
HAYSTACK_CUSTOM_HIGHLIGHTER = 'myapp.utils.BorkHighlighter'
No default is provided. Haystack automatically falls back to the default
implementation.
``HAYSTACK_ITERATOR_LOAD_PER_QUERY``
====================================
**Optional**
This setting controls the number of results that are pulled at once when
iterating through a ``SearchQuerySet``. If you generally consume large portions
at a time, you can bump this up for better performance.
.. note::
This is not used in the case of a slice on a ``SearchQuerySet``, which
already overrides the number of results pulled at once.
An example::
HAYSTACK_ITERATOR_LOAD_PER_QUERY = 100
The default is 10 results at a time.
``HAYSTACK_LIMIT_TO_REGISTERED_MODELS``
=======================================
**Optional**
This setting allows you to control whether or not Haystack will limit the
search results seen to just the models registered. It should be a boolean.
If your search index is never used for anything other than the models
registered with Haystack, you can turn this off and get a small to moderate
performance boost.
An example::
HAYSTACK_LIMIT_TO_REGISTERED_MODELS = False
Default is ``True``.
``HAYSTACK_ID_FIELD``
=====================
**Optional**
This setting allows you to control what the unique field name used internally
by Haystack is called. Rarely needed unless your field names collide with
Haystack's defaults.
An example::
HAYSTACK_ID_FIELD = 'my_id'
Default is ``id``.
``HAYSTACK_DJANGO_CT_FIELD``
============================
**Optional**
This setting allows you to control what the content type field name used
internally by Haystack is called. Rarely needed unless your field names
collide with Haystack's defaults.
An example::
HAYSTACK_DJANGO_CT_FIELD = 'my_django_ct'
Default is ``django_ct``.
``HAYSTACK_DJANGO_ID_FIELD``
============================
**Optional**
This setting allows you to control what the primary key field name used
internally by Haystack is called. Rarely needed unless your field names
collide with Haystack's defaults.
An example::
HAYSTACK_DJANGO_ID_FIELD = 'my_django_id'
Default is ``django_id``.
``HAYSTACK_IDENTIFIER_METHOD``
==============================
**Optional**
This setting allows you to provide a custom method for
``haystack.utils.get_identifier``. Useful when the default identifier
pattern of <app.label>.<object_name>.<pk> isn't suited to your
needs.
An example::
HAYSTACK_IDENTIFIER_METHOD = 'my_app.module.get_identifier'
Default is ``haystack.utils.default_get_identifier``.
``HAYSTACK_FUZZY_MIN_SIM``
==========================
**Optional**
This setting allows you to change the required similarity when using ``fuzzy``
filter.
Default is ``0.5``
``HAYSTACK_FUZZY_MAX_EXPANSIONS``
=================================
**Optional**
This setting allows you to change the number of terms fuzzy queries will
expand to when using ``fuzzy`` filter.
Default is ``50``
|