简体   繁体   English

如何在SOLR中将布尔值转换为整数?

[英]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. 我正在努力让高级会员在搜索结果上方25公里范围内,其余列表按最近的位置排序。

To indicate that a listing is premium, I have defined the boolean field listing_premium. 为了表明列表是高级的,我定义了布尔字段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) 如果我可以通过将距离映射到查询(listing_location)并将其与代表布尔值的整数相乘,就可以在sort子句中使用此布尔值(true = 1,false = 0)

The following does not work as listing_premium is a boolean... 以下内容不起作用,因为listing_premium是一个布尔值...

&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 我可以以某种方式将listing_premium映射到0或1
  • or can I include an if statement in the sort 或者我可以在排序中包含if语句
  • or can I use copyField in the schema to create a generated field converting listing_premium to listing_premium_int 或者我可以在模式中使用copyField来创建一个将listing_premium转换为listing_premium_int的字段

Much obliged! 多谢!

The values for boolean might not be 0 and one. 布尔值可能不是0和1。 You can use the if() function to choose values based on that. 您可以使用if()函数基于此选择值。

This expression: 该表达式:

if(listing_premium,1,0) 

returns 1 if listing_premium is true and 0 if it is false. 如果listing_premium为true,则返回1;如果为false,则返回0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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