You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Emmanuel Franquemagne <ke...@yahoo.fr> on 2007/08/29 15:52:15 UTC

Custom normalization in Similarity

Hello,

I'd like to know if there is a way to perform custom correction to the 
similarity norm before it is written
At best, we wished we could do this by extending the Similarity class, 
but encodeNorm, that would be the best place to do it, is a static 
method and thus it's no use to override it.

Is there a reason why this method is static? And is there any solution 
that could allow us to do this value correction?

Thanks for any help,
Emmanuel

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Custom normalization in Similarity

Posted by Mark Miller <ma...@gmail.com>.
I think that encodeNorm and decodeNorm on Similarity are really just 
utility methods for norm encode/decode. It would be nice to be able to 
override those if you wanted to change the encode/decode method, but you 
should be able to modify the norm elsewhere. Actual access to the norm 
information is handled in IndexReader and this behavior can be 
overridden. This short example would hide the norms stored in the index 
and instead return 1.0f for each doc:

public class FakeNormsIndexReader extends FilterIndexReader {
    byte[] ones = SegmentReader.createFakeNorms(maxDoc());

    public FakeNormsIndexReader(IndexReader in) {
        super(in);
     
    }

    public synchronized byte[] norms(String field) throws IOException {

        return ones;
    }

    public synchronized void norms(String field, byte[] result, int 
offset) {

        System.arraycopy(ones, 0, result, offset, maxDoc());
    }
}

- Mark

Emmanuel Franquemagne wrote:
> Hello,
>
> I'd like to know if there is a way to perform custom correction to the 
> similarity norm before it is written
> At best, we wished we could do this by extending the Similarity class, 
> but encodeNorm, that would be the best place to do it, is a static 
> method and thus it's no use to override it.
>
> Is there a reason why this method is static? And is there any solution 
> that could allow us to do this value correction?
>
> Thanks for any help,
> Emmanuel
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org