How to Search for a Range and Score by Highest Value to Lowest (or vice-versa)

Frequently there is a need to find something with a specific range but still rank the matches by how close they are to another number, frequently either the min or the max of the range. Without any changes to a query criterion the engine will score all matches to a range of values as equal.

Take the case of a real estate search by price. We're looking for a home in the range of $300,000 to $400,000. By increasing relevance of the higher priced items, we automatically include the highest priced homes first that fell within the range. The same concept can apply to showing the lowest-priced homes.

To create this query requires two criterion: one determines the exact match flag; the other the relevance to use.

 criteria: [
   // range exact match tagging
   dimension: 'price',
   value: [300000 400000]
   // we cull anything that is less than 200,000 and more than 500,000
   // because we think that anything less or more expensive is
   // simply not a candidate
   cullDistance: 100000,
   // determines that this criterion does not impact overall score,
   // just exact matches
   weight: 0
   // "ideal" value for relevance scoring
   dimension: 'price',
   value: 400000, // "ranks" most expensive first
   exactMatch: true