mirror of https://github.com/apache/lucene.git
Trying to fix failing tests after bumping up version to 8.0
This commit is contained in:
parent
774e3d8f29
commit
93fbfc2e56
|
@ -32,8 +32,8 @@ public class TestSegmentInfos extends LuceneTestCase {
|
||||||
public void testIllegalCreatedVersion() {
|
public void testIllegalCreatedVersion() {
|
||||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new SegmentInfos(5));
|
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new SegmentInfos(5));
|
||||||
assertEquals("indexCreatedVersionMajor must be >= 6, got: 5", e.getMessage());
|
assertEquals("indexCreatedVersionMajor must be >= 6, got: 5", e.getMessage());
|
||||||
e = expectThrows(IllegalArgumentException.class, () -> new SegmentInfos(8));
|
e = expectThrows(IllegalArgumentException.class, () -> new SegmentInfos(Version.LATEST.major + 1));
|
||||||
assertEquals("indexCreatedVersionMajor is in the future: 8", e.getMessage());
|
assertEquals("indexCreatedVersionMajor is in the future: " + (Version.LATEST.major + 1), e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// LUCENE-5954
|
// LUCENE-5954
|
||||||
|
@ -56,7 +56,7 @@ public class TestSegmentInfos extends LuceneTestCase {
|
||||||
Codec codec = Codec.getDefault();
|
Codec codec = Codec.getDefault();
|
||||||
|
|
||||||
SegmentInfos sis = new SegmentInfos(Version.LATEST.major);
|
SegmentInfos sis = new SegmentInfos(Version.LATEST.major);
|
||||||
SegmentInfo info = new SegmentInfo(dir, Version.LUCENE_7_0_0, Version.LUCENE_7_0_0, "_0", 1, false, Codec.getDefault(),
|
SegmentInfo info = new SegmentInfo(dir, Version.LUCENE_8_0_0, Version.LUCENE_8_0_0, "_0", 1, false, Codec.getDefault(),
|
||||||
Collections.<String,String>emptyMap(), id, Collections.<String,String>emptyMap(), null);
|
Collections.<String,String>emptyMap(), id, Collections.<String,String>emptyMap(), null);
|
||||||
info.setFiles(Collections.<String>emptySet());
|
info.setFiles(Collections.<String>emptySet());
|
||||||
codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);
|
codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);
|
||||||
|
@ -65,7 +65,7 @@ public class TestSegmentInfos extends LuceneTestCase {
|
||||||
sis.add(commitInfo);
|
sis.add(commitInfo);
|
||||||
sis.commit(dir);
|
sis.commit(dir);
|
||||||
sis = SegmentInfos.readLatestCommit(dir);
|
sis = SegmentInfos.readLatestCommit(dir);
|
||||||
assertEquals(Version.LUCENE_7_0_0, sis.getMinSegmentLuceneVersion());
|
assertEquals(Version.LUCENE_8_0_0, sis.getMinSegmentLuceneVersion());
|
||||||
assertEquals(Version.LATEST, sis.getCommitLuceneVersion());
|
assertEquals(Version.LATEST, sis.getCommitLuceneVersion());
|
||||||
dir.close();
|
dir.close();
|
||||||
}
|
}
|
||||||
|
@ -78,14 +78,14 @@ public class TestSegmentInfos extends LuceneTestCase {
|
||||||
Codec codec = Codec.getDefault();
|
Codec codec = Codec.getDefault();
|
||||||
|
|
||||||
SegmentInfos sis = new SegmentInfos(Version.LATEST.major);
|
SegmentInfos sis = new SegmentInfos(Version.LATEST.major);
|
||||||
SegmentInfo info = new SegmentInfo(dir, Version.LUCENE_7_0_0, Version.LUCENE_7_0_0, "_0", 1, false, Codec.getDefault(),
|
SegmentInfo info = new SegmentInfo(dir, Version.LUCENE_8_0_0, Version.LUCENE_8_0_0, "_0", 1, false, Codec.getDefault(),
|
||||||
Collections.<String,String>emptyMap(), id, Collections.<String,String>emptyMap(), null);
|
Collections.<String,String>emptyMap(), id, Collections.<String,String>emptyMap(), null);
|
||||||
info.setFiles(Collections.<String>emptySet());
|
info.setFiles(Collections.<String>emptySet());
|
||||||
codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);
|
codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);
|
||||||
SegmentCommitInfo commitInfo = new SegmentCommitInfo(info, 0, -1, -1, -1);
|
SegmentCommitInfo commitInfo = new SegmentCommitInfo(info, 0, -1, -1, -1);
|
||||||
sis.add(commitInfo);
|
sis.add(commitInfo);
|
||||||
|
|
||||||
info = new SegmentInfo(dir, Version.LUCENE_7_0_0, Version.LUCENE_7_0_0, "_1", 1, false, Codec.getDefault(),
|
info = new SegmentInfo(dir, Version.LUCENE_8_0_0, Version.LUCENE_8_0_0, "_1", 1, false, Codec.getDefault(),
|
||||||
Collections.<String,String>emptyMap(), id, Collections.<String,String>emptyMap(), null);
|
Collections.<String,String>emptyMap(), id, Collections.<String,String>emptyMap(), null);
|
||||||
info.setFiles(Collections.<String>emptySet());
|
info.setFiles(Collections.<String>emptySet());
|
||||||
codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);
|
codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);
|
||||||
|
@ -94,7 +94,7 @@ public class TestSegmentInfos extends LuceneTestCase {
|
||||||
|
|
||||||
sis.commit(dir);
|
sis.commit(dir);
|
||||||
sis = SegmentInfos.readLatestCommit(dir);
|
sis = SegmentInfos.readLatestCommit(dir);
|
||||||
assertEquals(Version.LUCENE_7_0_0, sis.getMinSegmentLuceneVersion());
|
assertEquals(Version.LUCENE_8_0_0, sis.getMinSegmentLuceneVersion());
|
||||||
assertEquals(Version.LATEST, sis.getCommitLuceneVersion());
|
assertEquals(Version.LATEST, sis.getCommitLuceneVersion());
|
||||||
dir.close();
|
dir.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,32 +77,6 @@ public class TestBM25Similarity extends LuceneTestCase {
|
||||||
assertTrue(expected.getMessage().contains("illegal b value"));
|
assertTrue(expected.getMessage().contains("illegal b value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLengthEncodingBackwardCompatibility() throws IOException {
|
|
||||||
Similarity similarity = new BM25Similarity();
|
|
||||||
for (int indexCreatedVersionMajor : new int[] { Version.LUCENE_6_0_0.major, Version.LATEST.major}) {
|
|
||||||
for (int length : new int[] {1, 2, 4}) { // these length values are encoded accurately on both cases
|
|
||||||
Directory dir = newDirectory();
|
|
||||||
// set the version on the directory
|
|
||||||
new SegmentInfos(indexCreatedVersionMajor).commit(dir);
|
|
||||||
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig().setSimilarity(similarity));
|
|
||||||
Document doc = new Document();
|
|
||||||
String value = IntStream.range(0, length).mapToObj(i -> "b").collect(Collectors.joining(" "));
|
|
||||||
doc.add(new TextField("foo", value, Store.NO));
|
|
||||||
w.addDocument(doc);
|
|
||||||
IndexReader reader = DirectoryReader.open(w);
|
|
||||||
IndexSearcher searcher = newSearcher(reader);
|
|
||||||
searcher.setSimilarity(similarity);
|
|
||||||
Explanation expl = searcher.explain(new TermQuery(new Term("foo", "b")), 0);
|
|
||||||
Explanation docLen = findExplanation(expl, "fieldLength");
|
|
||||||
assertNotNull(docLen);
|
|
||||||
assertEquals(docLen.toString(), length, (int) docLen.getValue());
|
|
||||||
w.close();
|
|
||||||
reader.close();
|
|
||||||
dir.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Explanation findExplanation(Explanation expl, String text) {
|
private static Explanation findExplanation(Explanation expl, String text) {
|
||||||
if (expl.getDescription().equals(text)) {
|
if (expl.getDescription().equals(text)) {
|
||||||
return expl;
|
return expl;
|
||||||
|
|
|
@ -185,32 +185,6 @@ public class TestClassicSimilarity extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNormEncodingBackwardCompatibility() throws IOException {
|
|
||||||
Similarity similarity = new ClassicSimilarity();
|
|
||||||
for (int indexCreatedVersionMajor : new int[] { Version.LUCENE_6_0_0.major, Version.LATEST.major}) {
|
|
||||||
for (int length : new int[] {1, 4, 16 }) { // these length values are encoded accurately on both cases
|
|
||||||
Directory dir = newDirectory();
|
|
||||||
// set the version on the directory
|
|
||||||
new SegmentInfos(indexCreatedVersionMajor).commit(dir);
|
|
||||||
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig().setSimilarity(similarity));
|
|
||||||
Document doc = new Document();
|
|
||||||
String value = IntStream.range(0, length).mapToObj(i -> "b").collect(Collectors.joining(" "));
|
|
||||||
doc.add(new TextField("foo", value, Store.NO));
|
|
||||||
w.addDocument(doc);
|
|
||||||
IndexReader reader = DirectoryReader.open(w);
|
|
||||||
IndexSearcher searcher = newSearcher(reader);
|
|
||||||
searcher.setSimilarity(similarity);
|
|
||||||
Explanation expl = searcher.explain(new TermQuery(new Term("foo", "b")), 0);
|
|
||||||
Explanation fieldNorm = findExplanation(expl, "fieldNorm");
|
|
||||||
assertNotNull(fieldNorm);
|
|
||||||
assertEquals(fieldNorm.toString(), 1/Math.sqrt(length), fieldNorm.getValue(), 0f);
|
|
||||||
w.close();
|
|
||||||
reader.close();
|
|
||||||
dir.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Explanation findExplanation(Explanation expl, String text) {
|
private static Explanation findExplanation(Explanation expl, String text) {
|
||||||
if (expl.getDescription().startsWith(text)) {
|
if (expl.getDescription().startsWith(text)) {
|
||||||
return expl;
|
return expl;
|
||||||
|
|
|
@ -609,33 +609,4 @@ public class TestSimilarityBase extends LuceneTestCase {
|
||||||
actual.setDiscountOverlaps(true);
|
actual.setDiscountOverlaps(true);
|
||||||
assertEquals(expected.computeNorm(state), actual.computeNorm(state));
|
assertEquals(expected.computeNorm(state), actual.computeNorm(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLengthEncodingBackwardCompatibility() throws IOException {
|
|
||||||
Similarity similarity = RandomPicks.randomFrom(random(), sims);
|
|
||||||
for (int indexCreatedVersionMajor : new int[] { Version.LUCENE_6_0_0.major, Version.LATEST.major}) {
|
|
||||||
for (int length : new int[] {1, 2, 4}) { // these length values are encoded accurately on both cases
|
|
||||||
Directory dir = newDirectory();
|
|
||||||
// set the version on the directory
|
|
||||||
new SegmentInfos(indexCreatedVersionMajor).commit(dir);
|
|
||||||
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig().setSimilarity(similarity));
|
|
||||||
Document doc = new Document();
|
|
||||||
String value = IntStream.range(0, length).mapToObj(i -> "b").collect(Collectors.joining(" "));
|
|
||||||
doc.add(new TextField("foo", value, Store.NO));
|
|
||||||
w.addDocument(doc);
|
|
||||||
IndexReader reader = DirectoryReader.open(w);
|
|
||||||
IndexSearcher searcher = newSearcher(reader);
|
|
||||||
searcher.setSimilarity(similarity);
|
|
||||||
Term term = new Term("foo", "b");
|
|
||||||
TermContext context = TermContext.build(reader.getContext(), term);
|
|
||||||
SimWeight simWeight = similarity.computeWeight(1f, searcher.collectionStatistics("foo"), searcher.termStatistics(term, context));
|
|
||||||
SimilarityBase.BasicSimScorer simScorer = (SimilarityBase.BasicSimScorer) similarity.simScorer(simWeight, reader.leaves().get(0));
|
|
||||||
float docLength = simScorer.getLengthValue(0);
|
|
||||||
assertEquals(length, (int) docLength);
|
|
||||||
|
|
||||||
w.close();
|
|
||||||
reader.close();
|
|
||||||
dir.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue