You could cook something up using the SQL, but the proper solution for this is using a full-text search engine. Haystack is a great package that will let you solve this quickly.
Text search based on relevance in Django by matching relevanct data to each individual items in object
-
11-12-2021 - |
Question
class Org(models.Model):
org_name = models.CharField(max_length=255)
name = models.CharField(max_length=50)
phone = models.CharField(max_length=50)
email_id = models.EmailField()
incorporation_date = models.DateTimeField()
def __unicode__(self):
return self.org_name
Data at hand org_name, name, phone, email_id, incorporation_date... How can I use the data I have to compare with the data in model and display results based on relevance.
Example:
Apple, Steve, 000-000-0000, steveo@apple.com, 1979
I should be able to compare Apple with data in org_name, Steve in name etc.., and display the rows which has the match and in descending order of relevance using DJANGO!
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow