As your DateSourceParser is put in standardValueSourceParsers map with key 
"dateDeboost" (right?), I think you need specify name of your source like 
"dateDeboost(title)". 

26.11.2013, 06:46, "sling" <sling...@gmail.com>:
> Thanks a lot for your reply, Chris.
>
> I was trying to sort the query result by the Datefunction, by passing
> q={!boost b=dateDeboost()}title:test to the /select request-handler.
>
> Before, my custom DateFunction is like this:
> public class DateFunction extends FieldCacheSource {
>         private static final long serialVersionUID = 6752223682280098130L;
>         private static long now;
>         public DateFunction(String field) {
>                 super(field);
>                 now = System.currentTimeMillis();
>         }
>         @Override
>         public FunctionValues getValues(Map context,
>                         AtomicReaderContext readerContext) throws IOException 
> {
>                 long[] times = cache.getLongs(readerContext.reader(), field, 
> false);
>                 final float[] weights = new float[times.length];
>                 for (int i = 0; i < times.length; i++) {
>                         weights[i] = ScoreUtils.getNewsScoreFactor(now, 
> times[i]);
>                 }
>                 return new FunctionValues() {
>                         @Override
>                         public float floatVal(int doc) {
>                                 return weights[doc];
>                         }
>                 };
>         }
> }
> It calculate every documet's date-weight, but at the same time , it only
> need the one doc's date-weight, so it run slowly.
>
> When I see the source code of recip function in
> org.apache.solr.search.ValueSourceParser, like this:
> addParser("recip", new ValueSourceParser() {
>       @Override
>       public ValueSource parse(FunctionQParser fp) throws SyntaxError {
>         ValueSource source = fp.parseValueSource();
>         float m = fp.parseFloat();
>         float a = fp.parseFloat();
>         float b = fp.parseFloat();
>         return new ReciprocalFloatFunction(source, m, a, b);
>       }
> });
> and in the ReciprocalFloatFunction, it get the value like this:
> @Override
>   public FunctionValues getValues(Map context, AtomicReaderContext
> readerContext) throws IOException {
>     final FunctionValues vals = source.getValues(context, readerContext);
>     return new FloatDocValues(this) {
>       @Override
>       public float floatVal(int doc) {
>         return a/(m*vals.floatVal(doc) + b);
>       }
>       @Override
>       public String toString(int doc) {
>         return Float.toString(a) + "/("
>                 + m + "*float(" + vals.toString(doc) + ')'
>                 + '+' + b + ')';
>       }
>     };
>   }
>
> So I think this is what I want.
> When calculate a doc's date-weight, I needn't "cache.getLongs(xxxxx)",
> instead, I should "source.getValues(xxx)"
>
> Therefore I change my code, but when fp.parseValueSource(), it throws an
> error like this:
> org.apache.solr.search.SyntaxError: Expected identifier at pos 12
> str='dateDeboost()'
>
> Do I describe clearly this time?
>
> Thanks again!
>
> sling
>
> --
> View this message in context: 
> http://lucene.472066.n3.nabble.com/In-a-functon-query-I-can-t-get-the-ValueSource-when-extend-ValueSourceParser-tp4103026p4103207.html
> Sent from the Solr - User mailing list archive at Nabble.com.

Reply via email to