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 Thyagaraj <th...@gmail.com> on 2013/08/01 08:37:58 UTC

Solr round ratings to nearest integer value

I'm using solr 4.0 with DIH jdbc connector and I use Solr Admin web interface
for testing. I have a field called *ratings* which varies like 0, 0.3, 0.5,
0.75, 1, 1.5, 1.6... and so on as per user input. 


I found the link 
http://lucene.472066.n3.nabble.com/How-to-round-solr-score-td495198.html
<http://lucene.472066.n3.nabble.com/How-to-round-solr-score-td495198.html>  
which is beyond of my understanding and I unable to make use of in my case.


I just want to round this rating values to nearest integer value through
solr like,
0.3 & 0.5 to 0
0.75 & 1.5 to 1
1.6 to 2


Anybody help me guiding please?

Thank you!



--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-round-ratings-to-nearest-integer-value-tp4081833.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr round ratings to nearest integer value

Posted by Jack Krupansky <ja...@basetechnology.com>.
Thanks for this inquiry; as a result I have added a "round" JavaScript 
script for the StatelessScriptUpdate processor to Early Access Release #5 of 
my Solr 4.x Deep Dive book in the chapter on update processors.

The script takes a field name, a number of decimal digits to round to 
(default is 0), and an output field (defaults to replacing the input field), 
and an option to convert the type of the rounded number to integer.

One thing I just noticed - your message indicates that 0.5 should round to 
0.0, but that is not the standard definition of rounding. What is your true 
intention there?

The script can replace the original value with the rounded value, or 
preserve the original value and place a rounded copy in another field. What 
is your preference? (Well, the script supports both, anyway.)

And I did give the script the "integer" option to convert the type, so that 
1.0 would become 1 Solr "int" fields.

-- Jack Krupansky

-----Original Message----- 
From: Thyagaraj
Sent: Thursday, August 01, 2013 2:37 AM
To: solr-user@lucene.apache.org
Subject: Solr round ratings to nearest integer value

I'm using solr 4.0 with DIH jdbc connector and I use Solr Admin web 
interface
for testing. I have a field called *ratings* which varies like 0, 0.3, 0.5,
0.75, 1, 1.5, 1.6... and so on as per user input.


I found the link
http://lucene.472066.n3.nabble.com/How-to-round-solr-score-td495198.html
<http://lucene.472066.n3.nabble.com/How-to-round-solr-score-td495198.html>
which is beyond of my understanding and I unable to make use of in my case.


I just want to round this rating values to nearest integer value through
solr like,
0.3 & 0.5 to 0
0.75 & 1.5 to 1
1.6 to 2


Anybody help me guiding please?

Thank you!



--
View this message in context: 
http://lucene.472066.n3.nabble.com/Solr-round-ratings-to-nearest-integer-value-tp4081833.html
Sent from the Solr - User mailing list archive at Nabble.com. 


Re: Solr round ratings to nearest integer value

Posted by Raymond Wiker <rw...@gmail.com>.
On Aug 1, 2013, at 17:36 , Thyagaraj <th...@gmail.com> wrote:
> Hello Raymond Wiker,
> 
> I just want to change the value while returning from the index (i.e, at
> query time). I tried the one like below but it's not working and showing
> same fraction value instead any nearest integer,
> 
> http://192.168.1.10:8080/solr/core10/select?q=*%3A*&rint%28ratings%29&wt=xml
> 
> Did I try correctly? if not could you let me correct way of doing it
> changing the above link?
> 
> Thank you!


Try something like http://localhost:8983/solr/core10/select?q=*%3A*&fl=*%2C+intratings%3Arint(ratings)&wt=xml

--- this adds the value "intratings" to your search results (rounded correctly, but it appears to be returned as a double...)





Re: Solr round ratings to nearest integer value

Posted by Thyagaraj <th...@gmail.com>.
Hello Raymond Wiker,

I just want to change the value while returning from the index (i.e, at
query time). I tried the one like below but it's not working and showing
same fraction value instead any nearest integer,

http://192.168.1.10:8080/solr/core10/select?q=*%3A*&rint%28ratings%29&wt=xml

Did I try correctly? if not could you let me correct way of doing it
changing the above link?

Thank you!



--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-round-ratings-to-nearest-integer-value-tp4081833p4081981.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr round ratings to nearest integer value

Posted by Raymond Wiker <rw...@gmail.com>.
You don't say whether you want to change the value in the index, or the
value that you return from the index (i.e, at query time).

If you want to change the value that you place in the index, you could
modify your SQL query to use the ROUND() function on the "ratings" value.
For Oracle, you could just use ROUND(ratings), while SQLServer appears to
require something like CONVERT(int, ROUND(ratings, 0)).

If you want to return a rounded value as part of the query result, you
could specify the list of fields to return (parameter "fl"), and specify
something like "rint(ratings)".

Note: for Oracle and SQLServer, ROUND() rounds *.5 upwards (which is the
way that I have been taught is correct), while rint() rounds *.5 downwards
(which is what you appear to want).



On Thu, Aug 1, 2013 at 8:37 AM, Thyagaraj <th...@gmail.com> wrote:

> I'm using solr 4.0 with DIH jdbc connector and I use Solr Admin web
> interface
> for testing. I have a field called *ratings* which varies like 0, 0.3, 0.5,
> 0.75, 1, 1.5, 1.6... and so on as per user input.
>
>
> I found the link
> http://lucene.472066.n3.nabble.com/How-to-round-solr-score-td495198.html
> <http://lucene.472066.n3.nabble.com/How-to-round-solr-score-td495198.html>
> which is beyond of my understanding and I unable to make use of in my case.
>
>
> I just want to round this rating values to nearest integer value through
> solr like,
> 0.3 & 0.5 to 0
> 0.75 & 1.5 to 1
> 1.6 to 2
>
>
> Anybody help me guiding please?
>
> Thank you!
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Solr-round-ratings-to-nearest-integer-value-tp4081833.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Solr round ratings to nearest integer value

Posted by Raymond Wiker <rw...@gmail.com>.
That query searches for ratings in the range 2.0 to 2.5, which does not
include 1.75. The fl setting only affects the returned value, and not the
search.

If you want to search for ratings that would round to 2, your query should
be something like

fq=[1.5 TO 2.5]

Note: the exact boundaries should be chosen with care to ensure that the
values returned match the behaviour of rint(). (rint(1.5) rounds to 2,
while rint(2.5) also rounds to 2 - my guess is that rint() rounds half
towards even; see https://en.wikipedia.org/wiki/Rounding).


On Mon, Aug 5, 2013 at 7:21 AM, Thyagaraj <th...@gmail.com> wrote:

> Hello Erick,
>
> Is it possible to without changing the sql query?. I just rounded ratings
> value at the query time and trying to search with filter query like the one
> below:
>
> q=*:*
> fq=ratings:[2.0 TO 2.5]
> fl=ratings:rint(ratings)
>
> I have a rating 1.75 in a record which is rounded to 2.0 by rint but it's
> not listing when fq is used like the one above. It's just rounding, but I
> also want to query the rounded value.
>
>
> Thank you!
>
>
>
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Solr-round-ratings-to-nearest-integer-value-tp4081833p4082464.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Solr round ratings to nearest integer value

Posted by Erick Erickson <er...@gmail.com>.
If you don't want to change the SQL query, then you probably
need to write a custom update component, which is not
hard to do.

Otherwise, the suggestions already offered are viable.

Best
Erick


On Mon, Aug 5, 2013 at 1:21 AM, Thyagaraj <th...@gmail.com> wrote:

> Hello Erick,
>
> Is it possible to without changing the sql query?. I just rounded ratings
> value at the query time and trying to search with filter query like the one
> below:
>
> q=*:*
> fq=ratings:[2.0 TO 2.5]
> fl=ratings:rint(ratings)
>
> I have a rating 1.75 in a record which is rounded to 2.0 by rint but it's
> not listing when fq is used like the one above. It's just rounding, but I
> also want to query the rounded value.
>
>
> Thank you!
>
>
>
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Solr-round-ratings-to-nearest-integer-value-tp4081833p4082464.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Solr round ratings to nearest integer value

Posted by Thyagaraj <th...@gmail.com>.
Hello Erick,

Is it possible to without changing the sql query?. I just rounded ratings
value at the query time and trying to search with filter query like the one
below:

q=*:*
fq=ratings:[2.0 TO 2.5] 
fl=ratings:rint(ratings)

I have a rating 1.75 in a record which is rounded to 2.0 by rint but it's
not listing when fq is used like the one above. It's just rounding, but I
also want to query the rounded value.


Thank you!






--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-round-ratings-to-nearest-integer-value-tp4081833p4082464.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr round ratings to nearest integer value

Posted by Erick Erickson <er...@gmail.com>.
Then you need to do two things:
1> index the values as integers, i.e. do the rounding at input time.
    You could use a custom update element to do this or (simpler)
    just do it in your indexing step. Using the round methods in your
    SQL statement has already been mentioned.
2> round the values at query time in your query. Again, the app or
    a custom query component would work here either way.

Overall I'd do both these operations in the app (DIH for indexing
and your client-facing app at query time).

Best
Erick


On Fri, Aug 2, 2013 at 2:24 AM, Thyagaraj <th...@gmail.com> wrote:

> After discussion I came to know that I want the second point...
>
> 2. Query to match only rounded integer values?
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Solr-round-ratings-to-nearest-integer-value-tp4081833p4082138.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Solr round ratings to nearest integer value

Posted by Jack Krupansky <ja...@basetechnology.com>.
Two solutions:

1. An update processor that copies the float field to an int field and 
rounds it. you can do that with a JavaScript script using the 
StatelessScriptUpdate processor. Then query on the integer field

2.Do range queries: xyz:[2.0 TO 2.5]

-- Jack Krupansky

-----Original Message----- 
From: Thyagaraj
Sent: Friday, August 02, 2013 2:24 AM
To: solr-user@lucene.apache.org
Subject: Re: Solr round ratings to nearest integer value

After discussion I came to know that I want the second point...

2. Query to match only rounded integer values?



--
View this message in context: 
http://lucene.472066.n3.nabble.com/Solr-round-ratings-to-nearest-integer-value-tp4081833p4082138.html
Sent from the Solr - User mailing list archive at Nabble.com. 


Re: Solr round ratings to nearest integer value

Posted by Thyagaraj <th...@gmail.com>.
After discussion I came to know that I want the second point...

2. Query to match only rounded integer values? 



--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-round-ratings-to-nearest-integer-value-tp4081833p4082138.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr round ratings to nearest integer value

Posted by Thyagaraj <th...@gmail.com>.
Hello  Jack Krupansky-2,


Can I have all the 3 if you don't mind?, if it's not over work for you
because I'm not sure exactly. Till then I'll discuss with one of my
developer.


Thank you for your interest!



--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-round-ratings-to-nearest-integer-value-tp4081833p4082130.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr round ratings to nearest integer value

Posted by Jack Krupansky <ja...@basetechnology.com>.
Do you want:

1. The indexed value to be rounded?
2. Query to match only rounded integer values?
3. Return value to be rounded?

Which of those three is your use case. All three are possible.

-- Jack Krupansky

-----Original Message----- 
From: Thyagaraj
Sent: Thursday, August 01, 2013 2:37 AM
To: solr-user@lucene.apache.org
Subject: Solr round ratings to nearest integer value

I'm using solr 4.0 with DIH jdbc connector and I use Solr Admin web 
interface
for testing. I have a field called *ratings* which varies like 0, 0.3, 0.5,
0.75, 1, 1.5, 1.6... and so on as per user input.


I found the link
http://lucene.472066.n3.nabble.com/How-to-round-solr-score-td495198.html
<http://lucene.472066.n3.nabble.com/How-to-round-solr-score-td495198.html>
which is beyond of my understanding and I unable to make use of in my case.


I just want to round this rating values to nearest integer value through
solr like,
0.3 & 0.5 to 0
0.75 & 1.5 to 1
1.6 to 2


Anybody help me guiding please?

Thank you!



--
View this message in context: 
http://lucene.472066.n3.nabble.com/Solr-round-ratings-to-nearest-integer-value-tp4081833.html
Sent from the Solr - User mailing list archive at Nabble.com.