lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Miller <markrmil...@gmail.com>
Subject Re: Custom normalization in Similarity
Date Wed, 29 Aug 2007 14:09:57 GMT
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


Mime
View raw message