简体   繁体   中英

How to convert a boolean to an integer in SOLR?

I maintain a store that contains listings, some of them are premium members. I'm trying to get the premium members within a range of 25 km on top of the search results, the rest of the listings are ordered by nearest vicinity.

To indicate that a listing is premium, I have defined the boolean field listing_premium.

<field name="listing_premium" type="boolean" indexed="true" stored="true" />

It'd be easy if I could use this boolean in a sort clause by mapping the distance to the query (listing_location) and multiplying it with the integer representing the boolean (true = 1, false = 0)

The following does not work as listing_premium is a boolean...

&sort=mul(map(geodist(listing_location),0.0001,25,1,0),listing_premium)+desc,geodist(listing_location) asc

My question here is:

  • can I somehow map listing_premium to a 0 or 1
  • or can I include an if statement in the sort
  • or can I use copyField in the schema to create a generated field converting listing_premium to listing_premium_int

Much obliged!

The values for boolean might not be 0 and one. You can use the if() function to choose values based on that.

This expression:

if(listing_premium,1,0) 

returns 1 if listing_premium is true and 0 if it is false.

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