各ドキュメントが3つの異なるフィールド(filed1、field2、field3)を持つドキュメントコレクションの平均ドキュメント長を計算したい
これは、フィールドが1つしかない場合の平均長を計算するプログラムです。
private byte[] normsDocLengthArr = null;
private double avgDocLength;
normsDocLengthArr = indexReader.norms("filed1");
//norms-Returns the byte-encoded normalization factor for the named field of every document.
double sumLength = 0;
for (int i = 0; i < normsDocLengthArr.length; i++) {
double encodeLength = DefaultSimilarity.decodeNorm(normsDocLengthArr[i]);
//decodeNorm -Decodes a normalization factor stored in an index.
double length = 1 / (encodeLength * encodeLength);
sumLength += length;
}
this.avgDocLength = sumLength / normsDocLengthArr.length;
これが私が3つのフィールドすべてに拡張した方法です。
private byte[] normsDocLengthArrField1 = null;
private byte[] normsDocLengthArrField2 = null;
private byte[] normsDocLengthArrField3 = null;
private double avgDocLength;
normsDocLengthArrField1 = indexReader.norms("filed1");
normsDocLengthArrField2 = indexReader.norms("filed2");
normsDocLengthArrField3 = indexReader.norms("filed3");
//norms-Returns the byte-encoded normalization factor for the named field of every document.
double sumLength = 0;
for (int i = 0; i < normsDocLengthArrField1.length; i++) {
double encodeLengthF1 = DefaultSimilarity.decodeNorm(normsDocLengthArrField1[i]);
double encodeLengthF2 = DefaultSimilarity.decodeNorm(normsDocLengthArrField2[i]);
double encodeLengthF3 = DefaultSimilarity.decodeNorm(normsDocLengthArrField3[i]);
//decodeNorm -Decodes a normalization factor stored in an index.
double length = 1 / {(encodeLengthF1 * encodeLengthF1)+(encodeLengthF2 * encodeLengthF2)+(encodeLengthF3 * encodeLengthF3)};
sumLength += length;
}
this.avgDocLength = sumLength / (normsDocLengthArrField1.length+ normsDocLengthArrField2.length+normsDocLengthArrField3.length;
3フィールドのDoc平均長を計算する実装が正しいかどうかを知りたいだけですか?