Просмотр исходного кода

Added support for spelling mistakes, plus some tidying up of the search app

master
David Winterbottom 14 лет назад
Родитель
Сommit
4cbd212dfa

+ 1
- 0
examples/vanilla/settings.py Просмотреть файл

214
 HAYSTACK_SITECONF = 'oscar.search_sites'
214
 HAYSTACK_SITECONF = 'oscar.search_sites'
215
 HAYSTACK_SEARCH_ENGINE = 'solr'
215
 HAYSTACK_SEARCH_ENGINE = 'solr'
216
 HAYSTACK_SOLR_URL = 'http://127.0.0.1:8080/solr'
216
 HAYSTACK_SOLR_URL = 'http://127.0.0.1:8080/solr'
217
+HAYSTACK_INCLUDE_SPELLING = True
217
 
218
 
218
 # Local overrides
219
 # Local overrides
219
 try:
220
 try:

+ 2
- 0
oscar/apps/product/abstract_models.py Просмотреть файл

86
     recommended_items = models.ManyToManyField('product.Item', through='ProductRecommendation', blank=True)
86
     recommended_items = models.ManyToManyField('product.Item', through='ProductRecommendation', blank=True)
87
     
87
     
88
     date_created = models.DateTimeField(auto_now_add=True)
88
     date_created = models.DateTimeField(auto_now_add=True)
89
+
90
+    # This field is used by Haystack to reindex search
89
     date_updated = models.DateTimeField(auto_now=True, null=True, default=None)
91
     date_updated = models.DateTimeField(auto_now=True, null=True, default=None)
90
 
92
 
91
     objects = models.Manager()
93
     objects = models.Manager()

+ 5
- 2
oscar/apps/search/abstract_indexes.py Просмотреть файл

1
 from haystack.indexes import *
1
 from haystack.indexes import *
2
-from oscar.apps.product.models import Item
2
+
3
+from oscar.core.loading import import_module
4
+product_models = import_module('product.models', ['Item'])
5
+
3
 
6
 
4
 class AbstractProductIndex(SearchIndex):
7
 class AbstractProductIndex(SearchIndex):
5
     u"""
8
     u"""
19
 
22
 
20
         Orders by the most recently updated so that new objects are indexed first
23
         Orders by the most recently updated so that new objects are indexed first
21
         """
24
         """
22
-        return Item.objects.order_by('-date_updated')
25
+        return product_models.Item.objects.order_by('-date_updated')
23
 
26
 
24
     def get_updated_field(self):
27
     def get_updated_field(self):
25
         u"""
28
         u"""

+ 5
- 4
oscar/apps/search/context_processors.py Просмотреть файл

1
-from oscar.apps.search.forms import MultiFacetedSearchForm
1
+from oscar.core.loading import import_module
2
+search_forms = import_module('search.forms', ['MultiFacetedSearchForm'])
2
 
3
 
3
 def search_form(request):
4
 def search_form(request):
4
-    '''
5
+    u"""
5
     Ensures that the search form is available site wide
6
     Ensures that the search form is available site wide
6
-    '''
7
-    return {'search_form': MultiFacetedSearchForm(request.GET)}
7
+    """
8
+    return {'search_form': search_forms.MultiFacetedSearchForm(request.GET)}

+ 1
- 1
oscar/apps/search/forms.py Просмотреть файл

18
     '''
18
     '''
19
     An extension of the regular faceted search form to alow for multiple facets
19
     An extension of the regular faceted search form to alow for multiple facets
20
     '''
20
     '''
21
-    q = forms.CharField(required=False, label=_('Search'), widget=SearchInput({ "placeholder": _('Search') }))
21
+    q = forms.CharField(required=False, label=_('Search'), widget=SearchInput({"placeholder": _('Search')}))
22
 
22
 
23
     def search(self):
23
     def search(self):
24
         '''
24
         '''

+ 6
- 2
oscar/apps/search/search_indexes.py Просмотреть файл

1
 from haystack import site
1
 from haystack import site
2
+
2
 from oscar.apps.search.abstract_indexes import AbstractProductIndex
3
 from oscar.apps.search.abstract_indexes import AbstractProductIndex
3
-from oscar.apps.product.models import Item
4
+from oscar.core.loading import import_module
5
+product_models = import_module('product.models', ['Item'])
6
+
4
 
7
 
5
 class ProductIndex(AbstractProductIndex):
8
 class ProductIndex(AbstractProductIndex):
6
     pass
9
     pass
7
 
10
 
8
-site.register(Item, ProductIndex)
11
+
12
+site.register(product_models.Item, ProductIndex)
9
 
13
 

+ 11
- 8
oscar/apps/search/urls.py Просмотреть файл

1
 from django.conf.urls.defaults import *
1
 from django.conf.urls.defaults import *
2
 from haystack.query import SearchQuerySet
2
 from haystack.query import SearchQuerySet
3
 
3
 
4
-from oscar.apps.search.views import Suggestions, MultiFacetedSearchView
5
-from oscar.apps.search.forms import MultiFacetedSearchForm
6
-from oscar.apps.search.search_indexes import ProductIndex
4
+from oscar.core.loading import import_module
5
+search_views = import_module('search.views', ['Suggestions', 'MultiFacetedSearchView'])
6
+search_forms = import_module('search.forms', ['MultiFacetedSearchForm'])
7
+search_indexes = import_module('search.search_indexes', ['ProductIndex'])
8
+
7
 
9
 
8
 sqs = SearchQuerySet()
10
 sqs = SearchQuerySet()
9
-for field_name, field in ProductIndex.fields.items():
11
+for field_name, field in search_indexes.ProductIndex.fields.items():
10
     if field.faceted is True:
12
     if field.faceted is True:
11
-        #ensure we facet the results set by the defined facetable fields
13
+        # Ensure we facet the results set by the defined facetable fields
12
         sqs.facet(field_name)
14
         sqs.facet(field_name)
13
 
15
 
14
-urlpatterns = patterns('search.views',
15
-    url(r'^suggest/$', Suggestions.as_view(), name='oscar-search-suggest'),
16
-    url(r'^$', MultiFacetedSearchView(form_class=MultiFacetedSearchForm, searchqueryset=sqs), name='oscar-search'),
16
+urlpatterns = patterns('search.apps.views',
17
+    url(r'^suggest/$', search_views.Suggestions.as_view(), name='oscar-search-suggest'),
18
+    url(r'^$', search_views.MultiFacetedSearchView(form_class=search_forms.MultiFacetedSearchForm, 
19
+        searchqueryset=sqs), name='oscar-search'),
17
 )
20
 )

+ 2
- 2
oscar/apps/search/views.py Просмотреть файл

59
     """
59
     """
60
     template = 'search/results.html'
60
     template = 'search/results.html'
61
 
61
 
62
-    def __call__(self, request):
62
+    def __call__(self, request, *args, **kwargs):
63
         """
63
         """
64
         Generates the actual response to the search.
64
         Generates the actual response to the search.
65
         
65
         
74
         except product_models.Item.DoesNotExist:
74
         except product_models.Item.DoesNotExist:
75
             pass
75
             pass
76
         
76
         
77
-        return super(MultiFacetedSearchView, self)(*args, **kwargs)
77
+        return super(MultiFacetedSearchView, self).__call__(request, *args, **kwargs)
78
 
78
 
79
     def __name__(self):
79
     def __name__(self):
80
         return "MultiFacetedSearchView"
80
         return "MultiFacetedSearchView"

+ 5
- 1
oscar/templates/search/results.html Просмотреть файл

2
 {% load currency_filters %}
2
 {% load currency_filters %}
3
 
3
 
4
 {% block content %}
4
 {% block content %}
5
-<h2>Search</h2>
5
+<h2>Search for '{{ query }}'</h2>
6
+
7
+{% if suggestion %}
8
+Did you mean <a href="{% url oscar-search %}?q={{ suggestion }}">{{ suggestion }}</a>?
9
+{% endif %}
6
 
10
 
7
 <ol>
11
 <ol>
8
 {% for result in page.object_list %}
12
 {% for result in page.object_list %}

Загрузка…
Отмена
Сохранить