Yesterday, I reviewed my colleague's code which implemented a few tie-break rules to our search api. the code roughly looks like follow(to save space, I removed a few rules). for each tie-break method, it calls direct to the next rule if the condition is not satisfied.
private def tieBreakerSortWithinESRelevanceGroups(decoratedSearchRequest:DecoratedSearchRequest, leftListing:ListingInfo, rightListing:ListingInfo):Boolean = {
def tieBreakOnRoiScore(decoratedSearchRequest:DecoratedSearchRequest, leftListing:ListingInfo, rightListing:ListingInfo):Boolean = {
(decoratedSearchRequest.intent, leftListing.roiScore, rightListing.roiScore) match {
case (Some(Intent.TYPE), leftRoi, rightRoi) if (leftRoi == rightRoi) => tieBreakOnSource(decoratedSearchRequest, leftListing, rightListing)
case (Some(Intent.TYPE), leftRoi, rightRoi) => leftRoi < rightRoi
case _ => tieBreakOnSource(decoratedSearchRequest, leftListing, rightListing)