I have Article
model that contain a keywords
field which is an ArrayField
of a list of keywords in sorted ascending order. I want to do a query that finds all articles that have a minimum amount of keywords overlapping.
Example:
article_a = Article(keywords=["tag1", "tag2", "tag3"]
article_b = Article(keywords=["tag1", "tag2", ]
article_c = Article(keywords=["tag1", ]
article_a.find_similar_articles(min_overlap=2)
# Returns [article_b, ] since it overlaps with at least 2 elements.
There is a similar question here that is for general Postgres, not for the Django ORM.
Anyone know how I can query the Array Field in this way? Or perhaps you have a suggestion of another way to achieve the same result by structuring the data in another manner?