Icontains unable to search certain words from a field that uses richtext field - Django

I made a search function in my project where a user can enter a query and a number of fields will be searched before sending a response with the data filtered. As usual I am using icontains in the views for making the queries in my model. I copied certain words directly from a field that uses ckeditor to the searchbar to see if it works. What I have noticed is it is unable to match certain that are in bold form. Image of that field

In the image for example if I search the words arbitration agreement no data is returned but as you can see the words exists in the field. This is happeing with all the bold words.

Please help me to solve the problem as I am unable to understand as to why this is happeing. Below is the view that deals with the search functionality. Using ckeditor for the field.

views.py

def search_citation(request):
    
    q = request.data.get('q')
    
    print(f'{q}')
    
    if q is None:
        q = ""
    
    if len(q) > 78 or len(q) < 1:
        
        return Response({"message":'not appropriate'}, status=status.HTTP_200_OK)
    
    try:
      
      judge_name = Civil.objects.filter(judge_name__icontains = q)
      
      case_no =  Civil.objects.filter(case_no__icontains = q)
      
      party_name =  Civil.objects.filter(party_name__icontains = q)
      
      advocate_petitioner = Civil.objects.filter(advocate_petitioner__icontains = q)
      
      advocate_respondent = Civil.objects.filter(advocate_respondent__icontains = q)
      
      judgements = Civil.objects.filter(judgements__icontains = q)
      
      institution_name = Civil.objects.filter(institution_name__icontains = q)
      
      title = Civil.objects.filter(title__icontains = q)
      
      sub_law_type = Civil.objects.filter(sub_law_type__icontains = q)
      
      law_category =  Civil.objects.filter(law_category__icontains = q)
      
      q_final = judge_name | case_no | party_name | advocate_petitioner | advocate_respondent | title | sub_law_type | law_category | judgements | institution_name
      
      q_serial = Initial_Detail_Serial(q_final, many = True)
      
      return Response(q_serial.data, status= status.HTTP_200_OK)
      
    except Exception as e:
        
        print(e)
        
        return Response({"error":str(e)}, status=status.HTTP_400_BAD_REQUEST)

Back to Top