lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rohit Agarwal <rohit.agar...@eazydiner.com>
Subject Sorting Problem with custom ValueSourceParser
Date Tue, 04 Oct 2016 18:41:46 GMT
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";
        }
    }
}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message