1

Similar to my earlier question, I need a way to move certain items to the end of my search results, without using ordering.

I have a checkbox field (currently indexed as a string, containing "1" or "0"). I need the checked items ("1") to be at the bottom of the results.

Normally, it would be possible to do this with ordering, but since I am boosting certain fields, applying ordering operations screws up the result relevancy.

I have a method which adds predicates to my IQueryable object containing:

queryable.Where(item => item["discontinued"].Equals("1").Boost(1.0f)
                     || item["discontinued"].Equals("0").Boost(4.0f));

I found from my earlier question that you cannot use negative boost values with Azure search, so I instead tried to give a higher boost for the unchecked items than the checked ones. Is this even possible?: to use two different boost values against the same field depending on the value?. My current testing seems to show that this does not work.

0

I found this article which shows a similar approach to boosting (see the end of last code sample, toward the bottom) which confirms that my logic was correct.

The error was my choice of boost values.

I am boosting around 15 other fields with values in the range of 24 to 50. I guess that in order for this boost rule to have greater influence than the other ones it needs to be orders of magnitude greater (probably) than the other boost values (this must depend on the number of boosted fields and the frequency of occurrences of search terms). What I found was that upping the boost for non-discontinued items to 1000 fixed the problem. Not a very scientific way to fix the problem, but it seems to work. Note that in my case, I need the discontinued boosting to be used like sorting i.e. to take higher precedence than any of the other boosting rules.

My code now looks like:

queryable.Where(item => item["discontinued"].Equals("1").Boost(1f)
                     || item["discontinued"].Equals("0").Boost(1000f));

On a side note, I experimented with changing the type of the discontinued field from string to bool in the index, but this did not work. You cannot use boosting on a bool field, but you can use sorting.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.