You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Vaijanath Rao <va...@gmail.com> on 2012/04/15 12:56:31 UTC

Help with Scorer

Hi,

I am currently facing a problem with the scorer.  What I want is to add
score to original score based on the certain logic.

Here is snippet for the code

public class AddAdditioanlWeight extends Weight {

    private Query internalQuery = null;
    private Scorer subScorer =null;
    private Weight internalWeight = null;


  public AddAdditioanlWeight(Searcher searcher, Query query) throws
IOException {
     this.internalQuery = query;
     internalWeight = query.createWeight(searcher); // create weight based
on the originalQuery
  }

    @Override
    public Query getQuery() {
        return null;
    }

    @Override
    public float getValue() {
        return 0;
    }

    @Override
    public void normalize(float arg0) {

    }

    public AdditionalScorer scorer(IndexReader reader, boolean
scoreDocsInOrder, boolean topScorer) throws IOException {
        subScorer = internalWeight.scorer(reader, scoreDocsInOrder,
topScorer);
        // I get the subScorer as null for termQuery or PhraseQuery and
others.

    }
}

The problem I am running into is that the subScorer is always null can
someone help me in figuring out issue with my snippet code.

--Thanks and Regards
Vaijanath


-- 
I am feeling fine, healthier and Happier, what about you

Re: Help with Scorer

Posted by Vaijanath Rao <va...@gmail.com>.
Hi Uwe,

It worked thanks.

--Thanks and Regards
Vaijanath

On Sun, Apr 15, 2012 at 4:08 AM, Uwe Schindler <uw...@thetaphi.de> wrote:

> Hi,****
>
> ** **
>
> the internal weight (may) return null for the scorer, if the query hits no
> documents. This is just a shortcut. So you have to check, if your query
> really returns any results.****
>
> ** **
>
> About your code in general: You don’t need to do all this, to modify the
> score of an existing query use an own subclass of CustomScoreQuery from the
> search.function package. You just have to subclass this query and override
> getCustomScoreProvider that returns a provider class that can modify the
> score of any hit from the inner query. CustomScoreQuery already implements
> all the stuff you are trying to so, but in a correct way (your code is
> missing correct normalization,…).****
>
> ** **
>
> -----****
>
> Uwe Schindler****
>
> H.-H.-Meier-Allee 63, D-28213 Bremen****
>
> http://www.thetaphi.de****
>
> eMail: uwe@thetaphi.de****
>
> ** **
>
> *From:* Vaijanath Rao [mailto:vaiju1981@gmail.com]
> *Sent:* Sunday, April 15, 2012 12:57 PM
> *To:* dev@lucene.apache.org
> *Subject:* Help with Scorer****
>
> ** **
>
> Hi,
>
> I am currently facing a problem with the scorer.  What I want is to add
> score to original score based on the certain logic.
>
> Here is snippet for the code
>
> public class AddAdditioanlWeight extends Weight {
>
>     private Query internalQuery = null;
>     private Scorer subScorer =null;
>     private Weight internalWeight = null;
>
>
>   public AddAdditioanlWeight(Searcher searcher, Query query) throws
> IOException {
>      this.internalQuery = query;
>      internalWeight = query.createWeight(searcher); // create weight based
> on the originalQuery
>   }
>
>     @Override
>     public Query getQuery() {
>         return null;
>     }
>
>     @Override
>     public float getValue() {
>         return 0;
>     }
>
>     @Override
>     public void normalize(float arg0) {
>
>     }
>
>     public AdditionalScorer scorer(IndexReader reader, boolean
> scoreDocsInOrder, boolean topScorer) throws IOException {
>         subScorer = internalWeight.scorer(reader, scoreDocsInOrder,
> topScorer);
>         // I get the subScorer as null for termQuery or PhraseQuery and
> others.
>
>     }
> }
>
> The problem I am running into is that the subScorer is always null can
> someone help me in figuring out issue with my snippet code.
>
> --Thanks and Regards
> Vaijanath
>
>
> --
> I am feeling fine, healthier and Happier, what about you****
>



-- 
I am feeling fine, healthier and Happier, what about you

RE: Help with Scorer

Posted by Uwe Schindler <uw...@thetaphi.de>.
Hi,

 

the internal weight (may) return null for the scorer, if the query hits no
documents. This is just a shortcut. So you have to check, if your query
really returns any results.

 

About your code in general: You don't need to do all this, to modify the
score of an existing query use an own subclass of CustomScoreQuery from the
search.function package. You just have to subclass this query and override
getCustomScoreProvider that returns a provider class that can modify the
score of any hit from the inner query. CustomScoreQuery already implements
all the stuff you are trying to so, but in a correct way (your code is
missing correct normalization,.).

 

-----

Uwe Schindler

H.-H.-Meier-Allee 63, D-28213 Bremen

http://www.thetaphi.de <http://www.thetaphi.de/> 

eMail: uwe@thetaphi.de

 

From: Vaijanath Rao [mailto:vaiju1981@gmail.com] 
Sent: Sunday, April 15, 2012 12:57 PM
To: dev@lucene.apache.org
Subject: Help with Scorer

 

Hi,

I am currently facing a problem with the scorer.  What I want is to add
score to original score based on the certain logic. 

Here is snippet for the code

public class AddAdditioanlWeight extends Weight {

    private Query internalQuery = null;
    private Scorer subScorer =null;
    private Weight internalWeight = null;


  public AddAdditioanlWeight(Searcher searcher, Query query) throws
IOException {
     this.internalQuery = query;
     internalWeight = query.createWeight(searcher); // create weight based
on the originalQuery
  }
  
    @Override
    public Query getQuery() {
        return null;
    }
    
    @Override
    public float getValue() {
        return 0;
    }
    
    @Override
    public void normalize(float arg0) {
        
    }

    public AdditionalScorer scorer(IndexReader reader, boolean
scoreDocsInOrder, boolean topScorer) throws IOException {
        subScorer = internalWeight.scorer(reader, scoreDocsInOrder,
topScorer);
        // I get the subScorer as null for termQuery or PhraseQuery and
others.

    }
}

The problem I am running into is that the subScorer is always null can
someone help me in figuring out issue with my snippet code. 

--Thanks and Regards
Vaijanath


-- 
I am feeling fine, healthier and Happier, what about you