11
11
12
12
13
13
__author__ = 'Daniel Lindsley'
14
- __version__ = (1 , 2 , 5 , 'beta' )
14
+ __version__ = (1 , 2 , 5 )
15
15
__all__ = ['backend' ]
16
16
17
17
32
32
def load_backend (backend_name = None ):
33
33
"""
34
34
Loads a backend for interacting with the search engine.
35
-
35
+
36
36
Optionally accepts a ``backend_name``. If provided, it should be a string
37
37
of one of the following (built-in) options::
38
-
38
+
39
39
* solr
40
40
* xapian
41
41
* whoosh
42
42
* simple
43
43
* dummy
44
-
44
+
45
45
If you've implemented a custom backend, you can provide the "short" portion
46
46
of the name (before the ``_backend``) and Haystack will attempt to load
47
47
that backend instead.
48
-
48
+
49
49
If not provided, the ``HAYSTACK_SEARCH_ENGINE`` setting is used.
50
50
"""
51
51
if not backend_name :
52
52
backend_name = settings .HAYSTACK_SEARCH_ENGINE
53
-
53
+
54
54
try :
55
55
# Most of the time, the search backend will be one of the
56
56
# backends that ships with haystack, so look there first.
@@ -67,8 +67,8 @@ def load_backend(backend_name=None):
67
67
available_backends = [
68
68
os .path .splitext (f )[0 ].split ("_backend" )[0 ] for f in os .listdir (backend_dir )
69
69
if f != "base.py"
70
- and not f .startswith ('_' )
71
- and not f .startswith ('.' )
70
+ and not f .startswith ('_' )
71
+ and not f .startswith ('.' )
72
72
and not f .endswith ('.pyc' )
73
73
and not f .endswith ('.pyo' )
74
74
]
@@ -86,18 +86,18 @@ def load_backend(backend_name=None):
86
86
def autodiscover ():
87
87
"""
88
88
Automatically build the site index.
89
-
89
+
90
90
Again, almost exactly as django.contrib.admin does things, for consistency.
91
91
"""
92
92
import imp
93
93
from django .conf import settings
94
-
94
+
95
95
for app in settings .INSTALLED_APPS :
96
96
# For each app, we need to look for an search_indexes.py inside that app's
97
97
# package. We can't use os.path here -- recall that modules may be
98
98
# imported different ways (think zip files) -- so we need to get
99
99
# the app's __path__ and look for search_indexes.py on that path.
100
-
100
+
101
101
# Step 1: find out the app's __path__ Import errors here will (and
102
102
# should) bubble up, but a missing __path__ (which is legal, but weird)
103
103
# fails silently -- apps that do weird things with __path__ might
@@ -106,7 +106,7 @@ def autodiscover():
106
106
app_path = importlib .import_module (app ).__path__
107
107
except AttributeError :
108
108
continue
109
-
109
+
110
110
# Step 2: use imp.find_module to find the app's search_indexes.py. For some
111
111
# reason imp.find_module raises ImportError if the app can't be found
112
112
# but doesn't actually try to import the module. So skip this app if
@@ -115,7 +115,7 @@ def autodiscover():
115
115
imp .find_module ('search_indexes' , app_path )
116
116
except ImportError :
117
117
continue
118
-
118
+
119
119
# Step 3: import the app's search_index file. If this has errors we want them
120
120
# to bubble up.
121
121
importlib .import_module ("%s.search_indexes" % app )
@@ -125,7 +125,7 @@ def handle_registrations(*args, **kwargs):
125
125
"""
126
126
Ensures that any configuration of the SearchSite(s) are handled when
127
127
importing Haystack.
128
-
128
+
129
129
This makes it possible for scripts/management commands that affect models
130
130
but know nothing of Haystack to keep the index up to date.
131
131
"""
@@ -135,17 +135,17 @@ def handle_registrations(*args, **kwargs):
135
135
# apps generate import errors and requires extra work on the user's
136
136
# part to make things work.
137
137
return
138
-
138
+
139
139
# This is a little dirty but we need to run the code that follows only
140
140
# once, no matter how many times the main Haystack module is imported.
141
141
# We'll look through the stack to see if we appear anywhere and simply
142
142
# return if we do, allowing the original call to finish.
143
143
stack = inspect .stack ()
144
-
144
+
145
145
for stack_info in stack [1 :]:
146
146
if 'handle_registrations' in stack_info [3 ]:
147
147
return
148
-
148
+
149
149
# Pull in the config file, causing any SearchSite initialization code to
150
150
# execute.
151
151
search_sites_conf = importlib .import_module (settings .HAYSTACK_SITECONF )
0 commit comments