简体   繁体   中英

Increase CloudSearch _score by specific number

I am new to AWS cloudsearch, There is relevance score (_score) which is computed automatically based on the search terms occurrences..

My question is that Can I increase my relevance score(_score) by specific amount based on specific key value..

Example:

Lets say cloudsearch returns following two documents

fields: {
    {
       fullname: "Daniel Wildt",
       active: "T",
       _score: "82"
    }
    {
       fullname: "Robert",
       active: "F",
       _score: "84"
    }
}

I want First document (Daniel Wildt) to be higher... It means by active = T aws should add something to the score

Unfortunately you can't use a custom rank directly because that's only available for sort-enabled numeric fields (int, double, date).

Here are a couple alternative options

  • Sorting : if you plan to give a lot of weight to the active field, it will become dominant enough to be functionally equivalent to the the sort operator. That is, you can just add sort=active desc to your query to get the T results before F
  • Convert to int : map T and F to numeric values before submitting your documents to be indexed, eg T=1 F=0, then use these in a custom rank expression to affect the ordering of results &expr.myrank=_score+active&sort=myrank
  • Field weight : Add active:'T' to your query, which would potentially exclude results where active=F, and then use field weights to adjust the impact of this portion of the query: q.options={fields:['active^0.5']} . This will require some tuning

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM