[ 
https://issues.apache.org/jira/browse/LUCENE-1019?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12534038
 ] 

Doron Cohen commented on LUCENE-1019:
-------------------------------------

You could put this logic in your implementation of ValueSource, 
possibly constructed over multiple FieldCacheSources - 

{code:title=DateDecayQuery over multiple value sources}
public class DateDecayQuery extends CustomScoreQuery {

  public DateDecayQuery(Query subQuery) {
    super(subQuery, createValSrceQuery());
    setStrict(true);
  }

  private static ValueSourceQuery createValSrceQuery() {
    return new ValueSourceQuery(new HalfLifeValSrc());
  }
  
  private static class HalfLifeValSrc extends ValueSource {
    final ValueSource createdAt  = new IntFieldSource("created-at");
    final ValueSource halfLife  = new IntFieldSource("half-life");
    final long now = new Date().getTime() / 1000; // UNIX timestamp;
    final double LOG2 = Math.log(2);

    public DocValues getValues(final IndexReader reader) throws IOException {
      final DocValues valsCreated = createdAt.getValues(reader);
      final DocValues valsHalfLife = halfLife.getValues(reader);
      return new DocValues(reader.maxDoc()) {
        public float floatVal(int doc) {
          float vCreated = valsCreated.floatVal(doc);
          float vHalfLife = valsHalfLife.floatVal(doc);
          return (float) Math.exp(LOG2 * (vCreated - now) / vHalfLife);
        }
      };
    }
  }
}
{code}

Though usage is much simpler if this is added to the query.


> CustomScoreQuery should support multiple ValueSourceQueries
> -----------------------------------------------------------
>
>                 Key: LUCENE-1019
>                 URL: https://issues.apache.org/jira/browse/LUCENE-1019
>             Project: Lucene - Java
>          Issue Type: Improvement
>          Components: Search
>    Affects Versions: 2.2
>            Reporter: Kyle Maxwell
>         Attachments: CustomMultiQuery.v0.diff, CustomScoreQuery.v1.diff
>
>
> CustomScoreQuery's constructor currently accepts a subQuery, and a 
> ValueSourceQuery.  I would like it to accept multiple ValueSourceQueries.  
> The workaround of nested CustomScoreQueries works for simple cases, but it 
> quickly becomes either cumbersome to manage, or impossible to implement the 
> desired function.
> This patch implements CustomMultiScoreQuery with my desired functionality, 
> and refactors CustomScoreQuery to implement the special case of a 
> CustomMultiScoreQuery with 0 or 1 ValueSourceQueries.  This keeps the 
> CustomScoreQuery API intact.
> This patch includes basic tests, more or less taken from the original 
> implementation, and customized a bit to cover the new cases.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to