Search in sources :

Example 1 with FieldInvertState

use of org.apache.lucene.index.FieldInvertState in project lucene-solr by apache.

the class TestSimilarityBase method testDiscountOverlapsBoost.

// LUCENE-5221
public void testDiscountOverlapsBoost() throws IOException {
    BM25Similarity expected = new BM25Similarity();
    SimilarityBase actual = new DFRSimilarity(new BasicModelIne(), new AfterEffectB(), new NormalizationH2());
    expected.setDiscountOverlaps(false);
    actual.setDiscountOverlaps(false);
    FieldInvertState state = new FieldInvertState(Version.LATEST.major, "foo");
    state.setLength(5);
    state.setNumOverlap(2);
    assertEquals(expected.computeNorm(state), actual.computeNorm(state));
    expected.setDiscountOverlaps(true);
    actual.setDiscountOverlaps(true);
    assertEquals(expected.computeNorm(state), actual.computeNorm(state));
}
Also used : FieldInvertState(org.apache.lucene.index.FieldInvertState)

Example 2 with FieldInvertState

use of org.apache.lucene.index.FieldInvertState in project lucene-solr by apache.

the class TestBooleanSimilarity method testSameNormsAsBM25.

public void testSameNormsAsBM25() {
    BooleanSimilarity sim1 = new BooleanSimilarity();
    BM25Similarity sim2 = new BM25Similarity();
    sim2.setDiscountOverlaps(true);
    for (int iter = 0; iter < 100; ++iter) {
        final int length = TestUtil.nextInt(random(), 1, 100);
        final int position = random().nextInt(length);
        final int numOverlaps = random().nextInt(length);
        FieldInvertState state = new FieldInvertState(Version.LATEST.major, "foo", position, length, numOverlaps, 100);
        assertEquals(sim2.computeNorm(state), sim1.computeNorm(state), 0f);
    }
}
Also used : FieldInvertState(org.apache.lucene.index.FieldInvertState)

Example 3 with FieldInvertState

use of org.apache.lucene.index.FieldInvertState in project lucene-solr by apache.

the class TestMemoryIndex method testSimilarities.

@Test
public void testSimilarities() throws IOException {
    MemoryIndex mi = new MemoryIndex();
    mi.addField("f1", "a long text field that contains many many terms", analyzer);
    IndexSearcher searcher = mi.createSearcher();
    LeafReader reader = (LeafReader) searcher.getIndexReader();
    NumericDocValues norms = reader.getNormValues("f1");
    assertEquals(0, norms.nextDoc());
    float n1 = norms.longValue();
    // Norms are re-computed when we change the Similarity
    mi.setSimilarity(new Similarity() {

        @Override
        public long computeNorm(FieldInvertState state) {
            return 74;
        }

        @Override
        public SimWeight computeWeight(float boost, CollectionStatistics collectionStats, TermStatistics... termStats) {
            throw new UnsupportedOperationException();
        }

        @Override
        public SimScorer simScorer(SimWeight weight, LeafReaderContext context) throws IOException {
            throw new UnsupportedOperationException();
        }
    });
    norms = reader.getNormValues("f1");
    assertEquals(0, norms.nextDoc());
    float n2 = norms.longValue();
    assertTrue(n1 != n2);
    TestUtil.checkReader(reader);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) NumericDocValues(org.apache.lucene.index.NumericDocValues) LeafReader(org.apache.lucene.index.LeafReader) ClassicSimilarity(org.apache.lucene.search.similarities.ClassicSimilarity) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity) Similarity(org.apache.lucene.search.similarities.Similarity) IOException(java.io.IOException) TermStatistics(org.apache.lucene.search.TermStatistics) CollectionStatistics(org.apache.lucene.search.CollectionStatistics) FieldInvertState(org.apache.lucene.index.FieldInvertState) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) Test(org.junit.Test)

Example 4 with FieldInvertState

use of org.apache.lucene.index.FieldInvertState in project lucene-solr by apache.

the class TestClassicSimilarity method testSameNormsAsBM25.

public void testSameNormsAsBM25() {
    ClassicSimilarity sim1 = new ClassicSimilarity();
    BM25Similarity sim2 = new BM25Similarity();
    sim2.setDiscountOverlaps(true);
    for (int iter = 0; iter < 100; ++iter) {
        final int length = TestUtil.nextInt(random(), 1, 1000);
        final int position = random().nextInt(length);
        final int numOverlaps = random().nextInt(length);
        FieldInvertState state = new FieldInvertState(Version.LATEST.major, "foo", position, length, numOverlaps, 100);
        assertEquals(sim2.computeNorm(state), sim1.computeNorm(state), 0f);
    }
}
Also used : FieldInvertState(org.apache.lucene.index.FieldInvertState)

Aggregations

FieldInvertState (org.apache.lucene.index.FieldInvertState)4 IOException (java.io.IOException)1 LeafReader (org.apache.lucene.index.LeafReader)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 NumericDocValues (org.apache.lucene.index.NumericDocValues)1 SortedNumericDocValues (org.apache.lucene.index.SortedNumericDocValues)1 CollectionStatistics (org.apache.lucene.search.CollectionStatistics)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 TermStatistics (org.apache.lucene.search.TermStatistics)1 BM25Similarity (org.apache.lucene.search.similarities.BM25Similarity)1 ClassicSimilarity (org.apache.lucene.search.similarities.ClassicSimilarity)1 Similarity (org.apache.lucene.search.similarities.Similarity)1 Test (org.junit.Test)1