use of org.apache.lucene.search.similarities.ClassicSimilarity in project lucene-solr by apache.
the class TestClassicSimilarityFactory method testParams.
/** Classic w/ explicit params */
public void testParams() throws Exception {
ClassicSimilarity sim = getSimilarity("text_overlap", ClassicSimilarity.class);
assertEquals(false, sim.getDiscountOverlaps());
}
use of org.apache.lucene.search.similarities.ClassicSimilarity in project lucene-solr by apache.
the class TestClassicSimilarityFactory method testDefaults.
/** Classic w/ default parameters */
public void testDefaults() throws Exception {
ClassicSimilarity sim = getSimilarity("text", ClassicSimilarity.class);
assertEquals(true, sim.getDiscountOverlaps());
}
use of org.apache.lucene.search.similarities.ClassicSimilarity in project lucene-solr by apache.
the class SweetSpotSimilarityTest method testSweetSpotComputeNorm.
public void testSweetSpotComputeNorm() throws IOException {
final SweetSpotSimilarity ss = new SweetSpotSimilarity();
ss.setLengthNormFactors(1, 1, 0.5f, true);
Similarity d = new ClassicSimilarity();
Similarity s = ss;
// base case, should degrade
for (int i = 1; i < 1000; i++) {
assertEquals("base case: i=" + i, computeNorm(d, "bogus", i), computeNorm(s, "bogus", i), 0.0f);
}
// make a sweet spot
ss.setLengthNormFactors(3, 10, 0.5f, true);
for (int i = 3; i <= 10; i++) {
assertEquals("3,10: spot i=" + i, 1.0f, computeNorm(ss, "bogus", i), 0.0f);
}
for (int i = 10; i < 1000; i++) {
final float normD = computeNorm(d, "bogus", i - 9);
final float normS = computeNorm(s, "bogus", i);
assertEquals("3,10: 10<x : i=" + i, normD, normS, 0.01f);
}
// separate sweet spot for certain fields
final SweetSpotSimilarity ssBar = new SweetSpotSimilarity();
ssBar.setLengthNormFactors(8, 13, 0.5f, false);
final SweetSpotSimilarity ssYak = new SweetSpotSimilarity();
ssYak.setLengthNormFactors(6, 9, 0.5f, false);
final SweetSpotSimilarity ssA = new SweetSpotSimilarity();
ssA.setLengthNormFactors(5, 8, 0.5f, false);
final SweetSpotSimilarity ssB = new SweetSpotSimilarity();
ssB.setLengthNormFactors(5, 8, 0.1f, false);
Similarity sp = new PerFieldSimilarityWrapper() {
@Override
public Similarity get(String field) {
if (field.equals("bar"))
return ssBar;
else if (field.equals("yak"))
return ssYak;
else if (field.equals("a"))
return ssA;
else if (field.equals("b"))
return ssB;
else
return ss;
}
};
for (int i = 3; i <= 10; i++) {
assertEquals("f: 3,10: spot i=" + i, 1.0f, computeNorm(sp, "foo", i), 0.0f);
}
for (int i = 10; i < 1000; i++) {
final float normD = computeNorm(d, "foo", i - 9);
final float normS = computeNorm(sp, "foo", i);
assertEquals("f: 3,10: 10<x : i=" + i, normD, normS, 0.01f);
}
for (int i = 8; i <= 13; i++) {
assertEquals("f: 8,13: spot i=" + i, 1.0f, computeNorm(sp, "bar", i), 0.01f);
}
for (int i = 6; i <= 9; i++) {
assertEquals("f: 6,9: spot i=" + i, 1.0f, computeNorm(sp, "yak", i), 0.01f);
}
for (int i = 13; i < 1000; i++) {
final float normD = computeNorm(d, "bar", i - 12);
final float normS = computeNorm(sp, "bar", i);
assertEquals("f: 8,13: 13<x : i=" + i, normD, normS, 0.01f);
}
for (int i = 9; i < 1000; i++) {
final float normD = computeNorm(d, "yak", i - 8);
final float normS = computeNorm(sp, "yak", i);
assertEquals("f: 6,9: 9<x : i=" + i, normD, normS, 0.01f);
}
for (int i = 9; i < 1000; i++) {
final float normSS = computeNorm(sp, "a", i);
final float normS = computeNorm(sp, "b", i);
assertTrue("s: i=" + i + " : a=" + normSS + " < b=" + normS, normSS < normS);
}
}
use of org.apache.lucene.search.similarities.ClassicSimilarity in project lucene-solr by apache.
the class SweetSpotSimilarityTest method testSweetSpotTf.
public void testSweetSpotTf() {
SweetSpotSimilarity ss = new SweetSpotSimilarity();
TFIDFSimilarity d = new ClassicSimilarity();
TFIDFSimilarity s = ss;
// tf equal
ss.setBaselineTfFactors(0.0f, 0.0f);
for (int i = 1; i < 1000; i++) {
assertEquals("tf: i=" + i, d.tf(i), s.tf(i), 0.0f);
}
// tf higher
ss.setBaselineTfFactors(1.0f, 0.0f);
for (int i = 1; i < 1000; i++) {
assertTrue("tf: i=" + i + " : d=" + d.tf(i) + " < s=" + s.tf(i), d.tf(i) < s.tf(i));
}
// tf flat
ss.setBaselineTfFactors(1.0f, 6.0f);
for (int i = 1; i <= 6; i++) {
assertEquals("tf flat1: i=" + i, 1.0f, s.tf(i), 0.0f);
}
ss.setBaselineTfFactors(2.0f, 6.0f);
for (int i = 1; i <= 6; i++) {
assertEquals("tf flat2: i=" + i, 2.0f, s.tf(i), 0.0f);
}
for (int i = 6; i <= 1000; i++) {
assertTrue("tf: i=" + i + " : s=" + s.tf(i) + " < d=" + d.tf(i), s.tf(i) < d.tf(i));
}
// stupidity
assertEquals("tf zero", 0.0f, s.tf(0), 0.0f);
}
use of org.apache.lucene.search.similarities.ClassicSimilarity in project lucene-solr by apache.
the class TestTaxonomyFacetCounts method testReallyNoNormsForDrillDown.
public void testReallyNoNormsForDrillDown() throws Exception {
Directory dir = newDirectory();
Directory taxoDir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
iwc.setSimilarity(new PerFieldSimilarityWrapper() {
final Similarity sim = new ClassicSimilarity();
@Override
public Similarity get(String name) {
assertEquals("field", name);
return sim;
}
});
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
FacetsConfig config = new FacetsConfig();
Document doc = new Document();
doc.add(newTextField("field", "text", Field.Store.NO));
doc.add(new FacetField("a", "path"));
writer.addDocument(config.build(taxoWriter, doc));
writer.close();
IOUtils.close(taxoWriter, dir, taxoDir);
}
Aggregations