Search in sources :

Example 1 with IDFStats

use of org.apache.lucene.search.similarities.TFIDFSimilarity.IDFStats in project lucene-solr by apache.

the class TestClassicSimilarity method testSaneNormValues.

public void testSaneNormValues() throws IOException {
    ClassicSimilarity sim = new ClassicSimilarity();
    for (int i = 0; i < 256; i++) {
        float boost = TFIDFSimilarity.OLD_NORM_TABLE[i];
        assertFalse("negative boost: " + boost + ", byte=" + i, boost < 0.0f);
        assertFalse("inf bost: " + boost + ", byte=" + i, Float.isInfinite(boost));
        assertFalse("nan boost for byte=" + i, Float.isNaN(boost));
        if (i > 0) {
            assertTrue("boost is not increasing: " + boost + ",byte=" + i, boost > TFIDFSimilarity.OLD_NORM_TABLE[i - 1]);
        }
    }
    TFIDFSimilarity.IDFStats stats = (IDFStats) sim.computeWeight(1f, new IndexSearcher(new MultiReader()).collectionStatistics("foo"));
    for (int i = 0; i < 256; i++) {
        float boost = stats.normTable[i];
        assertFalse("negative boost: " + boost + ", byte=" + i, boost < 0.0f);
        assertFalse("inf bost: " + boost + ", byte=" + i, Float.isInfinite(boost));
        assertFalse("nan boost for byte=" + i, Float.isNaN(boost));
        if (i > 0) {
            assertTrue("boost is not decreasing: " + boost + ",byte=" + i, boost < stats.normTable[i - 1]);
        }
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) MultiReader(org.apache.lucene.index.MultiReader) IDFStats(org.apache.lucene.search.similarities.TFIDFSimilarity.IDFStats) IDFStats(org.apache.lucene.search.similarities.TFIDFSimilarity.IDFStats)

Aggregations

MultiReader (org.apache.lucene.index.MultiReader)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 IDFStats (org.apache.lucene.search.similarities.TFIDFSimilarity.IDFStats)1