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

Kyle Maxwell updated LUCENE-1019:
---------------------------------

    Attachment: CustomScoreQuery.v1.diff

Here's a slightly simpler version of the diff (v1).

The default behavior of CustomScoreQuery with multiple ValueSourceQueries does 
not matter to me.  I really want to be able to override it with custom logic.  
Also note that multiplying twice is currently as simple as 
CustomScoreQuery(CustomScoreQuery(subQuery, value1), value2).  But what about 
things that aren't linear combinations?

Use case:  I want the score to fall off exponentially as content ages, with a 
decay rate that varies on a per document basis.  

Each document has three fields: "text," "created-at," and "half-life."  
Created-at is represented as a UNIX timestamp, and half-life in seconds.  I'm 
not sure that the following query is able to be expressed as nested queries.  
There may be another way to do this, but this seems simple and elegant to me.

{code:java}
public class DateDecayQuery extends CustomScoreQuery {
        public final double LOG2 = Math.log(2);
        private long now;

        public DateDecayQuery(Query subQuery) {
                super(subQuery, new ValueSourceQuery[] {
                                new FieldScoreQuery("date", Type.INT),
                                new FieldScoreQuery("half-life", Type.INT) });
                now = new Date().getTime() / 1000; // UNIX timestamp;
                setStrict(true);
        }

        public float customScore(int doc, float score, float fields[]) {
                float date = fields[0];
                float halfLife = fields[1];
                float dateScore = (float) Math.exp(LOG2 * (date - now) / 
halfLife);
                return score * dateScore;
        }
}
{code}

> 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