match

match(str fieldname)allows exact matching between keywords. The function operates on fields of type keyword or lists of keyword.

For keywords, the function returns True for an exact match and False otherwise. For lists of keywords, the function acts as match(any), returning True for an exact match between any two keywords of the lists.

The function can operate on a field in the query and the same field in a database document, or between a field in the query and a different field in a database document.

Input

  • fieldname1 (str) - the name of the field to match in query document. params[fieldname1] must be of type keyword or list[keyword]

  • fieldname2 (str, default=fieldname1) - the name of the field to match in database document. doc[fieldname2] must be of type keyword or list[keyword]

Output

  • (Boolean) - true if match(any) between params[fieldname1] and doc[fieldname2]

Example:

def score_function(params, doc):
    if match("city",”shipping_city”) and match("street"):
        return 1
    return 0

In the above example:

  • The field 'street' is compared between the query and each document. If the field includes a matching value, the corresponding match function will return true.

  • The field 'city' in the query is compared with the field 'shipping_city' in the database documents. If there is a matching value, the corresponding match function will return true.

Last updated