You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by bbarani <bb...@gmail.com> on 2015/09/29 20:36:25 UTC

Using dynamically calculated value for sorting

Hi,

We have a price field in our SOLR XML feed that we currently use for
sorting. We are planning to introduce discounts based on login credentials
and we have to dynamically calculate price (using base price in SOLR feed)
based on a specific discount returned by an API. Now after the discount is
calculated we want to sort based on the new price (discounted price).

 What is the best way to do that? Any ideas would be appreciated.



--
View this message in context: http://lucene.472066.n3.nabble.com/Using-dynamically-calculated-value-for-sorting-tp4231950.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Using dynamically calculated value for sorting

Posted by bbarani <bb...@gmail.com>.
Thanks for your reply.

Overall design has changed little bit.

Now I will be sending the SKU id (SKU id is in SOLR document) to an external
API and it will return a new price to me for that SKU based on some logic (I
wont be calculating the new price). 

Once I get that value I need to use that new price value for sorting. 






--
View this message in context: http://lucene.472066.n3.nabble.com/Using-dynamically-calculated-value-for-sorting-tp4231950p4232320.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Using dynamically calculated value for sorting

Posted by Chris Hostetter <ho...@fucit.org>.
: sorting. We are planning to introduce discounts based on login credentials
: and we have to dynamically calculate price (using base price in SOLR feed)
: based on a specific discount returned by an API. Now after the discount is
: calculated we want to sort based on the new price (discounted price).
: 
:  What is the best way to do that? Any ideas would be appreciated.

It's hard to provide a completley generic answer to your question w/o more 
details in terms of how you define "discount"

if the discount is a fixed amount, or fixed percentage, for all documents 
returned from the index for that user, then you can use simple functions 
to do something like "sort=min(0,sub(price,flat_discount)) asc, popularity 
desc"

https://cwiki.apache.org/confluence/display/solr/Function+Queries

If the discount depends on other factors, then you have to explain what 
those other factors are -- if they can be represented as a numerical 
calculation based entirely on a single (or small number) of constants you 
pass in to hte query based on the userid, plus some numerical values in 
every document, then you can probably expand on that type of solution even 
more.

But w/o knowing hte details, it's hard to give you any further guidance.




-Hoss
http://www.lucidworks.com/

Re: Using dynamically calculated value for sorting

Posted by Leonardo Foderaro <st...@gmail.com>.
Hi,
please take a look at Alba, a framework which simplifies the development of
new Solr plugins. You can write a plugin (e.g. custom function to be used
to boost/sort your docs or a custom Response Writer) in literally five
lines of code.

More specifically I think these two examples could be useful.

This is the basic example, which shows you how to write a function to
calculate the length of a text field and how to use that information for
boosting/sorting/filtering:
https://github.com/leonardofoderaro/alba/wiki/Your-first-Function-Query:-the-title-length

Here is a slightly more advanced example, how to a discount on books older
than X years:
https://github.com/leonardofoderaro/alba/wiki/discounting-old-books

Disclaimer 1: it has never been used in production.... yet ;-)

Disclaimer 2: I'm the author of the Alba Framework

Should you have any questions / issues / hints / PR  on how to improve it
please let me know.

best regards,
Leonardo










On Tue, Sep 29, 2015 at 8:36 PM, bbarani <bb...@gmail.com> wrote:

> Hi,
>
> We have a price field in our SOLR XML feed that we currently use for
> sorting. We are planning to introduce discounts based on login credentials
> and we have to dynamically calculate price (using base price in SOLR feed)
> based on a specific discount returned by an API. Now after the discount is
> calculated we want to sort based on the new price (discounted price).
>
>  What is the best way to do that? Any ideas would be appreciated.
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Using-dynamically-calculated-value-for-sorting-tp4231950.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>