Created
January 8, 2022 13:21
-
-
Save mcalavera81/677e51465516fc96cc6a94d9ca9224f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query = { | |
'query': { | |
'bool': { | |
'should': [ | |
{'match_phrase': { | |
'title_exact_match': { | |
'query': SENTINEL_BEGIN + ' ' + usersSearch + ' ' + SENTINEL_END, | |
'boost': 1000, | |
} | |
}}, | |
{ | |
'function_score': { | |
'query': { | |
'constant_score': { | |
'filter': { | |
'match_phrase': { | |
'names_exact_match': SENTINEL_BEGIN + ' ' + usersSearch + ' ' + SENTINEL_END | |
} | |
}, | |
'boost': 1000.0 | |
} | |
}, | |
'functions': [ | |
{ | |
"gauss": { | |
"release_date": { | |
"origin": "now", | |
"scale": "5500d", | |
"decay": 0.5 | |
} | |
} | |
}, | |
{ | |
"field_value_factor": { | |
"field": "vote_average", | |
"modifier": "sqrt" | |
} | |
} | |
] | |
} | |
}, | |
{'multi_match': { | |
'query': usersSearch, #User's query | |
'fields': ['directors.name.bigramed','cast.name.bigramed'], | |
'type': 'cross_fields', | |
'boost': 100 | |
}}, | |
{'multi_match': { | |
'query': usersSearch, #User's query | |
'fields': ['overview', 'title', #C | |
'directors.name', 'cast.name'], | |
'type': 'cross_fields' | |
}}, | |
] | |
} | |
}, | |
'size': 5, | |
'explain': True | |
} | |
1 If the user’s query is a full, exact-title match, such as a search for “Star Trek Generations,” then that exact-title match should come straight to the top of the search results. | |
2 If the user’s query is a full, exact-name match, such as a search for “William Shatner,” then order results based on how recent and well rated the movie is. | |
3 Prioritize search results that include a person’s full name, such as the query “William Shatner Star Trek.” | |
4 Otherwise, base your scoring on a general text-based relevance of the user and a query. | |
■ SHOULD have full query exactly matching the title | |
■ SHOULD have full query, exactly matching a director’s or cast member’s full | |
name, scored by popularity and recency | |
■ SHOULD have part of the query match a director’s or cast member’s full name | |
■ SHOULD have all the user’s query terms match somewhere in the document |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment