django-oscar / django-oscar

Domain-driven e-commerce for Django
http://oscarcommerce.com
BSD 3-Clause "New" or "Revised" License
6.23k stars 2.22k forks source link

solr index is not matched with product pk. #4332

Open ankush06 opened 1 month ago

ankush06 commented 1 month ago

Found a bug? Please fill out the sections below.

Issue Summary

Product category query is not properly mapping solr-product ID to product pk. The pk is populated with MSB bit when product ID is more than 9. Example if product ID in solr is "catalogue.product.11" then product pk becomes 1. This cause a product with pk 1 to display instant of product 11. image

Steps to Reproduce

  1. Add a solr backend for search
  2. Add more than 10 product in a category

Template should render all the product.

Technical details

Settings

HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.solr_backend.SolrEngine', 'URL': 'http://127.0.0.1:8983/solr/sandbox', 'ADMIN_URL': 'http://127.0.0.1:8983/solr/admin/cores', 'INCLUDE_SPELLING': True, }, } HAYSTACK_SEARCH_RESULTS_PER_PAGE=20 HAYSTACK_ITERATOR_LOAD_PER_QUERY=20 HAYSTACK_ID_FIELD='id' HAYSTACK_DJANGO_CT_FIELD="django_ct" HAYSTACK_DJANGO_ID_FIELD= 'django_id' #default django_id HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor

ankush06 commented 1 month ago

As a workaround, i updated search_handlers to update pk from ID.

` def bulk_fetch_results(self, paginated_results):

    objects = []

    models_pks = loaded_objects = {}
    for result in paginated_results:
        result.pk = result.id.split('.')[-1]
        models_pks.setdefault(result.model, []).append(result.pk)`