lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Doron Cohen (JIRA)" <>
Subject [jira] Commented: (LUCENE-1019) CustomScoreQuery should support multiple ValueSourceQueries
Date Thu, 11 Oct 2007 13:42:50 GMT


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());

  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);

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

> CustomScoreQuery should support multiple ValueSourceQueries
> -----------------------------------------------------------
>                 Key: LUCENE-1019
>                 URL:
>             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:
For additional commands, e-mail:

View raw message