Skip to content

Commit afa9cd4

Browse files
committed
Moved EXCLUDED_INDEXES to a per-backend setting.
1 parent 3631a8f commit afa9cd4

File tree

6 files changed

+154
-125
lines changed

6 files changed

+154
-125
lines changed

docs/migration_from_1_to_2.rst

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ look like::
3030
HAYSTACK_SOLR_TIMEOUT = 60 * 5
3131
HAYSTACK_INCLUDE_SPELLING = True
3232
HAYSTACK_BATCH_SIZE = 100
33-
33+
3434
# Or...
3535
HAYSTACK_SEARCH_ENGINE = 'whoosh'
3636
HAYSTACK_WHOOSH_PATH = '/home/search/whoosh_index'
3737
HAYSTACK_WHOOSH_STORAGE = 'file'
3838
HAYSTACK_WHOOSH_POST_LIMIT = 128 * 1024 * 1024
3939
HAYSTACK_INCLUDE_SPELLING = True
4040
HAYSTACK_BATCH_SIZE = 100
41-
41+
4242
# Or...
4343
HAYSTACK_SEARCH_ENGINE = 'xapian'
4444
HAYSTACK_XAPIAN_PATH = '/home/search/xapian_index'
@@ -125,35 +125,35 @@ A Haystack 1.X index might've looked like::
125125
from haystack.indexes import *
126126
from haystack import site
127127
from myapp.models import Note
128-
129-
128+
129+
130130
class NoteIndex(SearchIndex):
131131
text = CharField(document=True, use_template=True)
132132
author = CharField(model_attr='user')
133133
pub_date = DateTimeField(model_attr='pub_date')
134-
134+
135135
def get_queryset(self):
136136
"""Used when the entire index for model is updated."""
137137
return Note.objects.filter(pub_date__lte=datetime.datetime.now())
138-
139-
138+
139+
140140
site.register(Note, NoteIndex)
141141

142142
A converted Haystack 2.X index should look like::
143143

144144
import datetime
145145
from haystack import indexes
146146
from myapp.models import Note
147-
148-
147+
148+
149149
class NoteIndex(indexes.SearchIndex, indexes.Indexable):
150150
text = indexes.CharField(document=True, use_template=True)
151151
author = indexes.CharField(model_attr='user')
152152
pub_date = indexes.DateTimeField(model_attr='pub_date')
153-
153+
154154
def get_model(self):
155155
return Note
156-
156+
157157
def index_queryset(self):
158158
"""Used when the entire index for model is updated."""
159159
return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now())
@@ -180,15 +180,21 @@ method. This was present in the Haystack 1.2.X series (with a deprecation warnin
180180
in 1.2.4+) but has been removed in Haystack v2.
181181

182182
Finally, if you were unregistering other indexes before, you should make use of
183-
the new ``HAYSTACK_EXCLUDED_INDEXES`` setting. It should be a list of strings
184-
that contain the Python import path to the indexes that should not be loaded &
185-
used. For example::
183+
the new ``EXCLUDED_INDEXES`` setting available in each backend's settings. It
184+
should be a list of strings that contain the Python import path to the indexes
185+
that should not be loaded & used. For example::
186186

187-
HAYSTACK_EXCLUDED_INDEXES = [
188-
# Imagine that these indexes exist. They don't.
189-
'django.contrib.auth.search_indexes.UserIndex',
190-
'third_party_blog_app.search_indexes.EntryIndex',
191-
]
187+
HAYSTACK_CONNECTIONS = {
188+
'default': {
189+
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
190+
'URL': 'http://localhost:9001/solr/default',
191+
'EXCLUDED_INDEXES': [
192+
# Imagine that these indexes exist. They don't.
193+
'django.contrib.auth.search_indexes.UserIndex',
194+
'third_party_blog_app.search_indexes.EntryIndex',
195+
]
196+
}
197+
}
192198

193199
This allows for reliable swapping of the index that handles a model without
194200
relying on correct import order.
@@ -239,9 +245,9 @@ that the classes are defined above it) and should look like::
239245

240246
from haystack.backends import BaseEngine
241247
from haystack.backends.solr_backend import SolrSearchQuery
242-
248+
243249
# Code then...
244-
250+
245251
class MyCustomSolrEngine(BaseEngine):
246252
# Use our custom backend.
247253
backend = MySolrBackend

docs/settings.rst

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ dictionary of dictionaries resembling the following (complete) example::
4040
'TIMEOUT': 60 * 5,
4141
'INCLUDE_SPELLING': True,
4242
'BATCH_SIZE': 100,
43+
'EXCLUDED_INDEXES': ['thirdpartyapp.search_indexes.BarIndex'],
4344
},
4445
'autocomplete': {
4546
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
@@ -48,15 +49,18 @@ dictionary of dictionaries resembling the following (complete) example::
4849
'POST_LIMIT': 128 * 1024 * 1024,
4950
'INCLUDE_SPELLING': True,
5051
'BATCH_SIZE': 100,
52+
'EXCLUDED_INDEXES': ['thirdpartyapp.search_indexes.BarIndex'],
5153
},
5254
'slave': {
5355
'ENGINE': 'xapian_backend.XapianEngine',
5456
'PATH': '/home/search/xapian_index',
5557
'INCLUDE_SPELLING': True,
5658
'BATCH_SIZE': 100,
59+
'EXCLUDED_INDEXES': ['thirdpartyapp.search_indexes.BarIndex'],
5760
},
5861
'db': {
5962
'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
63+
'EXCLUDED_INDEXES': ['thirdpartyapp.search_indexes.BarIndex'],
6064
}
6165
}
6266

@@ -96,30 +100,39 @@ The following options are optional:
96100
* ``POST_LIMIT`` - (Whoosh-only) How large the file sizes can be. Default is
97101
``128 * 1024 * 1024``.
98102
* ``FLAGS`` - (Xapian-only) A list of flags to use when querying the index.
103+
* ``EXCLUDED_INDEXES`` - A list of strings (as Python import paths) to indexes
104+
you do **NOT** want included. Useful for omitting third-party things you
105+
don't want indexed or for when you want to replace an index.
99106

100107

101108
``HAYSTACK_ROUTERS``
102109
====================
103110

104111
**Optional**
105112

113+
This setting controls how routing is performed to allow different backends to
114+
handle updates/deletes/reads.
106115

116+
An example::
107117

118+
HAYSTACK_ROUTERS = ['search_routers.MasterSlaveRouter', 'haystack.routers.DefaultRouter']
108119

109-
``HAYSTACK_EXCLUDED_INDEXES``
110-
=============================
111-
112-
**Optional**
113-
114-
120+
Defaults to ``['haystack.routers.DefaultRouter']``.
115121

116122

117123
``HAYSTACK_DOCUMENT_FIELD``
118124
===========================
119125

120126
**Optional**
121127

128+
This setting controls what fieldname Haystack relies on as the default field
129+
for searching within.
130+
131+
An example::
132+
133+
HAYSTACK_DOCUMENT_FIELD = 'wall_o_text'
122134

135+
Defaults to ``text``.
123136

124137

125138
``HAYSTACK_SEARCH_RESULTS_PER_PAGE``

haystack/backends/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,6 @@ def reset_queries(self):
763763

764764
def get_unified_index(self):
765765
if self._index is None:
766-
self._index = self.unified_index()
766+
self._index = self.unified_index(self.options.get('EXCLUDED_INDEXES', []))
767767

768768
return self._index

0 commit comments

Comments
 (0)