'How do I search for a query in Django with words that are not in the same order as a product?

products = ProductModel.objects.filter(Q(name__icontains=search) | Q(sku__icontains=search))\
.select_related('prices')\
.prefetch_related('images_set', 'remainsmodel_set', 'addressonwarehouse_set')\
.order_by(sortby + orderby)

Example:

Product: 'Silicone Case for IPhon 13'

q = 'Case for IPhon 13'

r = 1 item

q = 'Silicone IPhon 13' ("Silicone + IPhon 13" should be displayed and the product should be matched)

r = 0 item

How to make it so that the search was not for the full name, and the individual words no matter what order.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source