简体   繁体   中英

Solr: how to map a boolean field into 1 and 2 for boosting

I want to boost documents which are inStock:true and with high price, in a way that:

  • inStock:true is 1
  • inStock:false is 2

So that I can use production of price and inStock numeric representation as boost function:

document boost = (inStock == true ? 2 : 1) * price

Is this possible? There is already a question about boolean field boosting , but it doesn't meet my requirement.

UPDATE1 :

SOLR-2136 implemented in Solr 4 is for conditional function (if), which makes my case easy. Since Solr 4 is not released yet, is there any workaround?

UPDATE2 : Try not to use boolean field type in Solr. It stores 'T' for true and 'F' for false, and you need to use map() and ord() in order to map true to 1 and false to 0. Simply use int for boolean values, and if you don't allow null in your boolean fields, do not index false values for your field.

Yeah there is a workaround:

Use the ord() function it will return an ordinal based on the set of indexed field values.

This means if you are indexing only the "true" values for your inStock field (and leaving false values out of the index) you can ensure that there is only one single value for you inStock field, which means this value will have the index position of 1 and ord(inStock) will return 1 for all documents having inStock==true. On the other hand ord() will return 0 if the inStock field is not available within a document.

If you wanna now map to true=1 and false=2 you can additionally use the map function to alter the numbers.

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