You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search_indexes.py 1.2KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from haystack import indexes
  2. from django.db.models import get_model
  3. class ProductIndex(indexes.SearchIndex, indexes.Indexable):
  4. """
  5. Base class for products solr index definition. Overide by creating your
  6. own copy of oscar.search_indexes.py
  7. """
  8. text = indexes.EdgeNgramField(document=True, use_template=True,
  9. template_name='oscar/search/indexes/product/item_text.txt')
  10. title = indexes.EdgeNgramField(model_attr='title', null=True)
  11. upc = indexes.CharField(model_attr="upc", null=True)
  12. date_created = indexes.DateTimeField(model_attr='date_created')
  13. date_updated = indexes.DateTimeField(model_attr='date_updated')
  14. def get_model(self):
  15. return get_model('catalogue', 'Product')
  16. def index_queryset(self):
  17. """
  18. Used when the entire index for model is updated.
  19. Orders by the most recently updated so that new objects are indexed first
  20. """
  21. return self.get_model().objects.order_by('-date_updated')
  22. def get_updated_field(self):
  23. """
  24. Used to specify the field used to determine if an object has been updated
  25. Can be used to filter the query set when updating the index
  26. """
  27. return 'date_updated'