org.apache.lucene.search.similarities

## Class BaseSimilarityTestCase

- java.lang.Object
- - org.junit.Assert
  - - org.apache.lucene.util.LuceneTestCase
    - - org.apache.lucene.search.similarities.BaseSimilarityTestCase

-     public abstract class BaseSimilarityTestCase
      extends LuceneTestCase

  Abstract class to do basic tests for a similarity. NOTE: This test focuses on the similarity impl, nothing else. The [stretch] goal is for this test to be so thorough in testing a new Similarity that if this test passes, then all Lucene/Solr tests should also pass. Ie, if there is some bug in a given Similarity that this test fails to catch then this test needs to be improved!

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.lucene.util.LuceneTestCase

      `LuceneTestCase.AwaitsFix, LuceneTestCase.BadApple, LuceneTestCase.Monster, LuceneTestCase.Nightly, LuceneTestCase.Slow, LuceneTestCase.SuppressCodecs, LuceneTestCase.SuppressFileSystems, LuceneTestCase.SuppressFsync, LuceneTestCase.SuppressReproduceLine, LuceneTestCase.SuppressSysoutChecks, LuceneTestCase.SuppressTempFileChecks, LuceneTestCase.ThrowingRunnable, LuceneTestCase.Weekly`

  - ### Field Summary

    - ### Fields inherited from class org.apache.lucene.util.LuceneTestCase

      `assertsAreEnabled, classRules, DEFAULT_LINE_DOCS_FILE, INFOSTREAM, JENKINS_LARGE_LINE_DOCS_FILE, LEAVE_TEMPORARY, MAYBE_CACHE_POLICY, RANDOM_MULTIPLIER, ruleChain, suiteFailureMarker, SYSPROP_AWAITSFIX, SYSPROP_BADAPPLES, SYSPROP_FAILFAST, SYSPROP_MAXFAILURES, SYSPROP_MONSTER, SYSPROP_NIGHTLY, SYSPROP_SLOW, SYSPROP_WEEKLY, TEST_ASSERTS_ENABLED, TEST_AWAITSFIX, TEST_BADAPPLES, TEST_CODEC, TEST_DIRECTORY, TEST_DOCVALUESFORMAT, TEST_LINE_DOCS_FILE, TEST_MONSTER, TEST_NIGHTLY, TEST_POSTINGSFORMAT, TEST_SLOW, TEST_THROTTLING, TEST_WEEKLY, VERBOSE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BaseSimilarityTestCase()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `afterClass()`
    `static void` | `beforeClass()`
    `protected abstract Similarity` | `getSimilarity(Random random)` Return a new similarity with all parameters randomized within valid ranges.
    `void` | `testRandomScoring()` Tests scoring across a bunch of random terms/corpora/frequencies for each possible document length.

    - ### Methods inherited from class org.apache.lucene.util.LuceneTestCase

      `addVirusChecker, assertDeletedDocsEquals, assertDocsAndPositionsEnumEquals, assertDocsEnumEquals, assertDocsSkippingEquals, assertDocValuesEquals, assertDocValuesEquals, assertFieldInfosEquals, assertNormsEquals, assertPointsEquals, assertPositionsSkippingEquals, assertReaderEquals, assertReaderStatisticsEquals, assertStoredFieldEquals, assertStoredFieldsEquals, assertTermsEnumEquals, assertTermsEquals, assertTermsEquals, assertTermsStatisticsEquals, assertTermStatsEquals, assertTermVectorsEquals, asSet, assumeFalse, assumeNoException, assumeTrue, assumeWorkingMMapOnWindows, atLeast, atLeast, callStackContains, callStackContains, callStackContainsAnyOf, closeAfterSuite, closeAfterTest, collate, createTempDir, createTempDir, createTempFile, createTempFile, dumpArray, dumpIterator, ensureSaneIWCOnNightly, expectThrows, expectThrows, expectThrows, expectThrowsAnyOf, expectThrowsAnyOf, getBaseTempDirForTestClass, getDataInputStream, getDataPath, getOnlyLeafReader, getTestClass, getTestName, hasWorkingMMapOnWindows, isTestThread, localeForLanguageTag, maybeChangeLiveIndexWriterConfig, maybeWrapReader, newAlcoholicMergePolicy, newAlcoholicMergePolicy, newDirectory, newDirectory, newDirectory, newDirectory, newDirectory, newField, newField, newFSDirectory, newFSDirectory, newIndexWriterConfig, newIndexWriterConfig, newIndexWriterConfig, newIOContext, newIOContext, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newMaybeVirusCheckingDirectory, newMaybeVirusCheckingFSDirectory, newMergePolicy, newMergePolicy, newMergePolicy, newMockDirectory, newMockDirectory, newMockDirectory, newMockFSDirectory, newMockFSDirectory, newSearcher, newSearcher, newSearcher, newStringField, newStringField, newStringField, newStringField, newTextField, newTextField, newTieredMergePolicy, newTieredMergePolicy, overrideDefaultQueryCache, overrideTestDefaultQueryCache, random, randomLocale, randomTimeZone, rarely, rarely, replaceMaxFailureRule, resetDefaultQueryCache, restoreCPUCoreCount, restoreIndexWriterMaxDocs, restoreSpins, runWithRestrictedPermissions, setIndexWriterMaxDocs, setUp, setupCPUCoreCount, setupSpins, slowFileExists, tearDown, usually, usually, wrapReader`

    - ### Methods inherited from class org.junit.Assert

      `assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertThrows, assertThrows, assertTrue, assertTrue, fail, fail`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### BaseSimilarityTestCase

          public BaseSimilarityTestCase()

  - ### Method Detail

    - #### beforeClass

          public static void beforeClass()
                                  throws Exception

      Throws:
        `Exception`

    - #### afterClass

          public static void afterClass()
                                 throws Exception

      Throws:
        `Exception`

    - #### getSimilarity

          protected abstract Similarity getSimilarity(Random random)

      Return a new similarity with all parameters randomized within valid ranges.

    - #### testRandomScoring

          public void testRandomScoring()
                                 throws Exception

      Tests scoring across a bunch of random terms/corpora/frequencies for each possible document length. It does the following checks:
      - scores are non-negative and finite.
      - score matches the explanation exactly.
      - internal explanations calculations are sane (e.g. sum of: and so on actually compute sums)
      - scores don't decrease as term frequencies increase: e.g. score(freq=N + 1) >= score(freq=N)
      - scores don't decrease as documents get shorter, e.g. score(len=M) >= score(len=M+1)
      - scores don't decrease as terms get rarer, e.g. score(term=N) >= score(term=N+1)
      - scoring works for floating point frequencies (e.g. sloppy phrase and span queries will work)
      - scoring works for reasonably large 64-bit statistic values (e.g. distributed search will work)
      - scoring works for reasonably large boost values (0 .. Integer.MAX_VALUE, e.g. query boosts will work)
      - scoring works for parameters randomized within valid ranges (see `getSimilarity(Random)`)
      Throws:
        `Exception`

Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.