Sorting Problem with custom ValueSourceParser

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Sorting Problem with custom ValueSourceParser

Rohit Agarwal
I am writing a custom ValueSourceParser. Everything is working fine except
when i use valuesourceparser for sorting it stops working for calls with
different data.

Eg: if i make a query to sort by func(cost) desc
It works.
Now if i change cost with some another field eg func(rating) desc
It sorts the result by cost only.

Now if i restart the solr server and call sort by func(rating) it works but
now it will stick with rating

Any idea why this would be happening?

Code:

public class MySourceParser extends ValueSourceParser {

    @Override
    public void init(NamedList args) {
        super.init(args);
    }

    @Override
    public ValueSource parse(FunctionQParser functionQParser) throws
SyntaxError {
        ValueSource source = functionQParser.parseValueSource();
        String val = functionQParser.parseArg();
        return new MySource(source, val);
    }

    public class MySource extends ValueSource {

        private ValueSource source;
        private String val;

        public MySource(ValueSource source, String val) {
            this.source = source;
            this.val = val;
        }

        @Override
        public FunctionValues getValues(Map map, LeafReaderContext
leafReaderContext) throws IOException {
            FunctionValues functionValues = source.getValues(map,
leafReaderContext);
            return new IntDocValues(this) {
                @Override
                public int intVal(int i) {
                    return functionValues.intVal(i);
                }
            };
        }

        @Override
        public void createWeight(Map context, IndexSearcher searcher)
throws IOException {
            source.createWeight(context, searcher);
        }

        @Override
        public boolean equals(Object o) {
            return true;
        }

        @Override
        public int hashCode() {
            return this.hashCode();
        }

        @Override
        public String description() {
            return "testing";
        }
    }
}
Reply | Threaded
Open this post in threaded view
|

Re: Sorting Problem with custom ValueSourceParser

Chris Hostetter-3

: Eg: if i make a query to sort by func(cost) desc
: It works.
: Now if i change cost with some another field eg func(rating) desc
: It sorts the result by cost only.
:
: Now if i restart the solr server and call sort by func(rating) it works but
: now it will stick with rating
:
: Any idea why this would be happening?

sounds like a queryResultCache collision -- perhaps all instances of your
ValueSource are saying they are equal to eachother?

:         @Override
:         public boolean equals(Object o) {
:             return true;
:         }

yup.

:         @Override
:         public int hashCode() {
:             return this.hashCode();
:         }


I don't even know what to say about that hashCode implementation ... i'm
honestly amazed your solr instance doesn't constantly throw
StackOverflowError on every request using your Value Source.



-Hoss
http://www.lucidworks.com/
Reply | Threaded
Open this post in threaded view
|

Re: Sorting Problem with custom ValueSourceParser

Rohit Agarwal
Hi Hoss,

Thanks for the response. Will make the necessary changes and get back to
you.

Btw this is just a testing code. The logic is yet to be implemented. What
according to you could be the best way to return hashcode?

Regards,
Rohit

On Oct 5, 2016 5:27 AM, "Chris Hostetter" <[hidden email]> wrote:

>
> : Eg: if i make a query to sort by func(cost) desc
> : It works.
> : Now if i change cost with some another field eg func(rating) desc
> : It sorts the result by cost only.
> :
> : Now if i restart the solr server and call sort by func(rating) it works
> but
> : now it will stick with rating
> :
> : Any idea why this would be happening?
>
> sounds like a queryResultCache collision -- perhaps all instances of your
> ValueSource are saying they are equal to eachother?
>
> :         @Override
> :         public boolean equals(Object o) {
> :             return true;
> :         }
>
> yup.
>
> :         @Override
> :         public int hashCode() {
> :             return this.hashCode();
> :         }
>
>
> I don't even know what to say about that hashCode implementation ... i'm
> honestly amazed your solr instance doesn't constantly throw
> StackOverflowError on every request using your Value Source.
>
>
>
> -Hoss
> http://www.lucidworks.com/
>
Reply | Threaded
Open this post in threaded view
|

Re: Sorting Problem with custom ValueSourceParser

Rohit Agarwal
I tried returning false in equals method but still it has no effect.

Btw is there any documentation where i can look at what the functions are
used for. I can't find any proper documentation related to it. It is very
difficult to guess the usage of the functions.

I don't think it will be a good idea to go through the whole solr code just
to make a external valuesourceparser. Any ideas?

Regards,
Rohit Agarwal

On Wed, Oct 5, 2016 at 10:11 AM, Rohit Agarwal <[hidden email]>
wrote:

> Hi Hoss,
>
> Thanks for the response. Will make the necessary changes and get back to
> you.
>
> Btw this is just a testing code. The logic is yet to be implemented. What
> according to you could be the best way to return hashcode?
>
> Regards,
> Rohit
>
> On Oct 5, 2016 5:27 AM, "Chris Hostetter" <[hidden email]>
> wrote:
>
>>
>> : Eg: if i make a query to sort by func(cost) desc
>> : It works.
>> : Now if i change cost with some another field eg func(rating) desc
>> : It sorts the result by cost only.
>> :
>> : Now if i restart the solr server and call sort by func(rating) it works
>> but
>> : now it will stick with rating
>> :
>> : Any idea why this would be happening?
>>
>> sounds like a queryResultCache collision -- perhaps all instances of your
>> ValueSource are saying they are equal to eachother?
>>
>> :         @Override
>> :         public boolean equals(Object o) {
>> :             return true;
>> :         }
>>
>> yup.
>>
>> :         @Override
>> :         public int hashCode() {
>> :             return this.hashCode();
>> :         }
>>
>>
>> I don't even know what to say about that hashCode implementation ... i'm
>> honestly amazed your solr instance doesn't constantly throw
>> StackOverflowError on every request using your Value Source.
>>
>>
>>
>> -Hoss
>> http://www.lucidworks.com/
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Sorting Problem with custom ValueSourceParser

Tirthankar
In reply to this post by Rohit Agarwal