Pārlūkot izejas kodu

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

master
David Winterbottom 14 gadus atpakaļ
vecāks
revīzija
4cbd212dfa

+ 1
- 0
examples/vanilla/settings.py Parādīt failu

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

+ 2
- 0
oscar/apps/product/abstract_models.py Parādīt failu

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

+ 5
- 2
oscar/apps/search/abstract_indexes.py Parādīt failu

@@ -1,5 +1,8 @@
1 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 7
 class AbstractProductIndex(SearchIndex):
5 8
     u"""
@@ -19,7 +22,7 @@ class AbstractProductIndex(SearchIndex):
19 22
 
20 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 27
     def get_updated_field(self):
25 28
         u"""

+ 5
- 4
oscar/apps/search/context_processors.py Parādīt failu

@@ -1,7 +1,8 @@
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 4
 def search_form(request):
4
-    '''
5
+    u"""
5 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 Parādīt failu

@@ -18,7 +18,7 @@ class MultiFacetedSearchForm(FacetedSearchForm):
18 18
     '''
19 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 23
     def search(self):
24 24
         '''

+ 6
- 2
oscar/apps/search/search_indexes.py Parādīt failu

@@ -1,9 +1,13 @@
1 1
 from haystack import site
2
+
2 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 8
 class ProductIndex(AbstractProductIndex):
6 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 Parādīt failu

@@ -1,17 +1,20 @@
1 1
 from django.conf.urls.defaults import *
2 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 10
 sqs = SearchQuerySet()
9
-for field_name, field in ProductIndex.fields.items():
11
+for field_name, field in search_indexes.ProductIndex.fields.items():
10 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 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 Parādīt failu

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

+ 5
- 1
oscar/templates/search/results.html Parādīt failu

@@ -2,7 +2,11 @@
2 2
 {% load currency_filters %}
3 3
 
4 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 11
 <ol>
8 12
 {% for result in page.object_list %}

Notiek ielāde…
Atcelt
Saglabāt