Need an ability to query documents that has common facet values, and rank them based on the # of common/shared facet values

We love the product… It is great to see so many features and first class developer tools/documentation.

Could you please help with following usecase and help us explore an option if we could meet this efficiently with help of algolia go sdk.

WHEN say you are looking at a content (a document/object in algolia), and it has certain values for a facet say metatags (i.e. low fat, low carb, cheap). Note here the metatags field is of type is string array inside the document.

THEN there is an ability to find additional content (documents/objects in algolia) that have 1 or more common facet value as that with respect to the referenced content and have them ranked based on number of matching facet values.

Hi Govinda,

Your question is interesting. I don’t think ranking works that way in Algolia, but it seems like you want to find similar documents based on the number of matching tags.

It looks like you are processing the results server-side so why not search using tagFilters to find items with ANY of the desired _tags, and then sort them based on the number of matches per item.

I am doing something kind of related.

Hopefully you are better with Go than I am with Python… anyway, here’s how I do it:

result = index.search("", {"attributesToRetrieve": ["objectID", "_tags"], "hitsPerPage": 999, 'tagFilters': [doctags], "attributesToHighlight": "", "attributesToSnippet": "" })
hits = result['hits']
ids = []
for hit in hits:
    count = 0
    for tag in hit['_tags']:
        if tag in tagstomatch:
            count = count + 1
    ids.append({'id': hit['objectID'], 'count': count })
ranked = sorted(ids, key=operator.itemgetter('count'), reverse=True)
return ranked

It’s not for use ‘live’ on a website - it’s will be used to send out emails, but it is actually pretty fast!