You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ja...@apache.org on 2026/02/04 00:34:11 UTC
(lucene) branch branch_10x updated (06d868d0b36 -> a9d3f4dbd98)
This is an automated email from the ASF dual-hosted git repository.
jainankitk pushed a change to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git
from 06d868d0b36 Fix MergedByteVectorValues internal ordinal tracking (#15553)
new 2dde6b570aa Use expectThrows for expected exceptions (#15611)
new c7c5a67acd7 Update documentation for Lucene104PostingsFormat (#15625)
new 0423a521d8b Minor refactor in SegmentTermsEnum.java (#15624)
new a9d3f4dbd98 Fix FVH boost issue (#15442) (#15635)
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
lucene/CHANGES.txt | 6 +++
.../analysis/core/TestStopFilterFactory.java | 1 -
.../lucene103/blocktree/SegmentTermsEnum.java | 27 +++--------
.../codecs/lucene104/Lucene104PostingsFormat.java | 2 +-
.../apache/lucene/index/TestDocValuesIndexing.java | 1 -
.../lucene/index/TestIndexWriterExceptions.java | 55 +++++++++-------------
.../lucene/index/TestIndexWriterMergePolicy.java | 7 ++-
.../apache/lucene/util/TestAttributeSource.java | 1 -
.../org/apache/lucene/util/TestBytesRefHash.java | 20 ++++----
.../test/org/apache/lucene/util/TestSetOnce.java | 8 ++--
.../TestLimitedFiniteStringsIterator.java | 1 -
.../search/vectorhighlight/FieldPhraseList.java | 1 +
.../TestUnifiedHighlighterReanalysis.java | 6 ++-
.../uhighlight/TestUnifiedHighlighterTermVec.java | 35 +++++++-------
.../vectorhighlight/TestFieldPhraseList.java | 24 ++++++++++
.../luke/models/analysis/TestAnalysisImpl.java | 4 +-
.../luke/models/documents/TestDocumentsImpl.java | 4 +-
.../luke/models/overview/TestOverviewImpl.java | 8 ++--
.../lucene/luke/models/search/TestSearchImpl.java | 17 ++++---
.../lucene/queries/spans/TestSpanWithinQuery.java | 8 +++-
.../spatial/vector/TestPointVectorStrategy.java | 4 +-
21 files changed, 120 insertions(+), 120 deletions(-)
(lucene) 01/04: Use expectThrows for expected exceptions (#15611)
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jainankitk pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit 2dde6b570aaeee35047f61734fefcf2731a2a29b
Author: Zhang Chao <80...@qq.com>
AuthorDate: Tue Jan 27 08:16:36 2026 +0800
Use expectThrows for expected exceptions (#15611)
---
.../analysis/core/TestStopFilterFactory.java | 1 -
.../apache/lucene/index/TestDocValuesIndexing.java | 1 -
.../lucene/index/TestIndexWriterExceptions.java | 55 +++++++++-------------
.../lucene/index/TestIndexWriterMergePolicy.java | 7 ++-
.../apache/lucene/util/TestAttributeSource.java | 1 -
.../org/apache/lucene/util/TestBytesRefHash.java | 20 ++++----
.../test/org/apache/lucene/util/TestSetOnce.java | 8 ++--
.../TestLimitedFiniteStringsIterator.java | 1 -
.../TestUnifiedHighlighterReanalysis.java | 6 ++-
.../uhighlight/TestUnifiedHighlighterTermVec.java | 35 +++++++-------
.../luke/models/analysis/TestAnalysisImpl.java | 4 +-
.../luke/models/documents/TestDocumentsImpl.java | 4 +-
.../luke/models/overview/TestOverviewImpl.java | 8 ++--
.../lucene/luke/models/search/TestSearchImpl.java | 17 ++++---
.../lucene/queries/spans/TestSpanWithinQuery.java | 8 +++-
.../spatial/vector/TestPointVectorStrategy.java | 4 +-
16 files changed, 82 insertions(+), 98 deletions(-)
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestStopFilterFactory.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestStopFilterFactory.java
index 0946a922439..4f0f5a196a5 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestStopFilterFactory.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestStopFilterFactory.java
@@ -96,7 +96,6 @@ public class TestStopFilterFactory extends BaseTokenStreamFactoryTestCase {
// implicit default words file
"format",
"bogus");
- fail();
});
msg = expected.getMessage();
assertTrue(msg, msg.contains("can not be specified"));
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
index c7381310b37..2c54916bd8a 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
@@ -102,7 +102,6 @@ public class TestDocValuesIndexing extends LuceneTestCase {
IllegalArgumentException.class,
() -> {
w.addDocument(doc);
- fail("didn't hit expected exception");
});
DirectoryReader r = w.getReader();
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
index 2087d294f8c..89497fcffec 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
@@ -663,14 +663,12 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
writer.addDocument(doc);
doc.add(newField("crash", "this should crash after 4 terms", DocCopyIterator.custom5));
doc.add(newField("other", "this will not get indexed", DocCopyIterator.custom5));
- try {
- writer.addDocument(doc);
- fail("did not hit expected exception");
- } catch (IOException ioe) {
- if (VERBOSE) {
- System.out.println("TEST: hit expected exception");
- ioe.printStackTrace(System.out);
- }
+ IndexWriter finalWriter = writer;
+ Document finalDoc = doc;
+ IOException ioe = expectThrows(IOException.class, () -> finalWriter.addDocument(finalDoc));
+ if (VERBOSE) {
+ System.out.println("TEST: hit expected exception");
+ ioe.printStackTrace(System.out);
}
if (0 == i) {
@@ -960,13 +958,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
for (int i = 0; i < 23; i++) {
addDoc(writer);
if ((i - 1) % 2 == 0) {
- try {
- writer.commit();
- } catch (
- @SuppressWarnings("unused")
- IOException ioe) {
- // expected
- }
+ expectThrows(IOException.class, () -> writer.commit());
}
}
((ConcurrentMergeScheduler) writer.getConfig().getMergeScheduler()).sync();
@@ -1731,7 +1723,6 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
Field theField = new StoredField("foo", v);
doc.add(theField);
iw.addDocument(doc);
- fail("didn't get expected exception");
});
assertNull(iw.getTragicException());
@@ -1760,7 +1751,6 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
BytesRef v = null;
theField.setBytesValue(v);
iw.addDocument(doc);
- fail("didn't get expected exception");
});
assertNull(iw.getTragicException());
@@ -1789,7 +1779,6 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
Field theField = new StoredField("foo", v);
doc.add(theField);
iw.addDocument(doc);
- fail("didn't get expected exception");
});
assertNull(iw.getTragicException());
@@ -2252,16 +2241,14 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
return true;
}
}) {
- writer.rollback();
- fail();
+ RuntimeException e = expectThrows(RuntimeException.class, () -> writer.rollback());
+ assertEquals("boom", e.getMessage());
+ assertEquals(
+ "has suppressed exceptions: " + Arrays.toString(e.getSuppressed()),
+ 0,
+ e.getSuppressed().length);
+ assertNull(e.getCause());
}
- } catch (RuntimeException e) {
- assertEquals("boom", e.getMessage());
- assertEquals(
- "has suppressed exceptions: " + Arrays.toString(e.getSuppressed()),
- 0,
- e.getSuppressed().length);
- assertNull(e.getCause());
}
}
@@ -2313,12 +2300,14 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
doc.add(new IntPoint("point2d", random().nextInt(), random().nextInt()));
writer.addDocument(new Document());
}
- try {
- writer.commit();
- fail();
- } catch (RuntimeException e) {
- assertEquals("boom", e.getMessage());
- }
+ RuntimeException expected =
+ expectThrows(
+ RuntimeException.class,
+ () -> {
+ writer.commit();
+ });
+ assertEquals("boom", expected.getMessage());
+
try {
maybeFailDelete.set(true);
writer.rollback();
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java
index c562d3ed624..cece4299faa 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java
@@ -725,10 +725,9 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
writer.addDocument(d2);
writer.flush();
mergeAndFail.set(true);
- try (DirectoryReader reader = DirectoryReader.open(writer)) {
- assertNotNull(reader); // make compiler happy and use the reader
- fail();
- } catch (RuntimeException e) {
+ try {
+ RuntimeException e =
+ expectThrows(RuntimeException.class, () -> DirectoryReader.open(writer));
assertEquals("boom", e.getMessage());
} finally {
mergeAndFail.set(false);
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java b/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java
index cf7a244a784..21ea2e7a3de 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java
@@ -165,7 +165,6 @@ public class TestAttributeSource extends LuceneTestCase {
() -> {
AttributeSource src = new AttributeSource();
src.addAttribute(Token.class);
- fail("Should throw IllegalArgumentException");
});
expectThrows(
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestBytesRefHash.java b/lucene/core/src/test/org/apache/lucene/util/TestBytesRefHash.java
index c73b1182505..9d2fd94ebe0 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestBytesRefHash.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestBytesRefHash.java
@@ -332,26 +332,22 @@ public class TestBytesRefHash extends LuceneTestCase {
}
}
- @Test(expected = MaxBytesLengthExceededException.class)
+ @Test
public void testLargeValue() {
int[] sizes =
- new int[] {
- random().nextInt(5),
- ByteBlockPool.BYTE_BLOCK_SIZE - 33 + random().nextInt(31),
- ByteBlockPool.BYTE_BLOCK_SIZE - 1 + random().nextInt(37)
- };
+ new int[] {random().nextInt(5), ByteBlockPool.BYTE_BLOCK_SIZE - 33 + random().nextInt(31)};
BytesRef ref = new BytesRef();
for (int i = 0; i < sizes.length; i++) {
ref.bytes = new byte[sizes[i]];
ref.offset = 0;
ref.length = sizes[i];
- try {
- assertEquals(i, hash.add(ref));
- } catch (MaxBytesLengthExceededException e) {
- if (i < sizes.length - 1) fail("unexpected exception at size: " + sizes[i]);
- throw e;
- }
+ assertEquals(i, hash.add(ref));
}
+
+ ref.bytes = new byte[ByteBlockPool.BYTE_BLOCK_SIZE - 1 + random().nextInt(37)];
+ ref.offset = 0;
+ ref.length = ref.bytes.length;
+ expectThrows(MaxBytesLengthExceededException.class, () -> hash.add(ref));
}
/** Test method for {@link org.apache.lucene.util.BytesRefHash#addByPoolOffset(int)} . */
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestSetOnce.java b/lucene/core/src/test/org/apache/lucene/util/TestSetOnce.java
index e7329afdc25..952e49bfea8 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestSetOnce.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestSetOnce.java
@@ -59,19 +59,19 @@ public class TestSetOnce extends LuceneTestCase {
assertNull(set.get());
}
- @Test(expected = AlreadySetException.class)
+ @Test
public void testSettingCtor() throws Exception {
SetOnce<Integer> set = new SetOnce<>(5);
assertEquals(5, set.get().intValue());
- set.set(7);
+ expectThrows(AlreadySetException.class, () -> set.set(7));
}
- @Test(expected = AlreadySetException.class)
+ @Test
public void testSetOnce() throws Exception {
SetOnce<Integer> set = new SetOnce<>();
set.set(5);
assertEquals(5, set.get().intValue());
- set.set(7);
+ expectThrows(AlreadySetException.class, () -> set.set(7));
}
@Test
diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/TestLimitedFiniteStringsIterator.java b/lucene/core/src/test/org/apache/lucene/util/automaton/TestLimitedFiniteStringsIterator.java
index 4b0873812f3..7af763040f2 100644
--- a/lucene/core/src/test/org/apache/lucene/util/automaton/TestLimitedFiniteStringsIterator.java
+++ b/lucene/core/src/test/org/apache/lucene/util/automaton/TestLimitedFiniteStringsIterator.java
@@ -55,7 +55,6 @@ public class TestLimitedFiniteStringsIterator extends LuceneTestCase {
IllegalArgumentException.class,
() -> {
new LimitedFiniteStringsIterator(a, -7);
- fail("did not hit exception");
});
}
diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterReanalysis.java b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterReanalysis.java
index f31a4c1b149..0ad299eb4cc 100644
--- a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterReanalysis.java
+++ b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterReanalysis.java
@@ -55,7 +55,7 @@ public class TestUnifiedHighlighterReanalysis extends UnifiedHighlighterTestBase
assertEquals("Hello", highlighter.highlightWithoutSearcher("nonexistent", query, "Hello", 1));
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void testIndexSearcherNullness() throws IOException {
String text =
"This is a test. Just a test highlighting without a searcher. Feel free to ignore.";
@@ -66,7 +66,9 @@ public class TestUnifiedHighlighterReanalysis extends UnifiedHighlighterTestBase
IndexReader indexReader = indexWriter.getReader()) {
IndexSearcher searcher = newSearcher(indexReader);
UnifiedHighlighter highlighter = UnifiedHighlighter.builder(searcher, indexAnalyzer).build();
- highlighter.highlightWithoutSearcher("body", query, text, 1); // should throw
+ expectThrows(
+ IllegalStateException.class,
+ () -> highlighter.highlightWithoutSearcher("body", query, text, 1));
}
}
}
diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterTermVec.java b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterTermVec.java
index edb96e5c6ba..8c342a212a8 100644
--- a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterTermVec.java
+++ b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterTermVec.java
@@ -205,7 +205,7 @@ public class TestUnifiedHighlighterTermVec extends UnifiedHighlighterTestBase {
}
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testUserFailedToIndexOffsets() throws IOException {
FieldType fieldType = new FieldType(tvType); // note: it's indexed too
fieldType.setStoreTermVectorPositions(random().nextBoolean());
@@ -216,24 +216,23 @@ public class TestUnifiedHighlighterTermVec extends UnifiedHighlighterTestBase {
doc.add(new Field("body", "term vectors", fieldType));
iw.addDocument(doc);
- IndexReader ir = iw.getReader();
- iw.close();
+ try (IndexReader ir = iw.getReader()) {
+ iw.close();
- IndexSearcher searcher = newSearcher(ir);
- UnifiedHighlighter.Builder uhBuilder = new UnifiedHighlighter.Builder(searcher, indexAnalyzer);
- UnifiedHighlighter highlighter =
- new UnifiedHighlighter(uhBuilder) {
- @Override
- protected Set<HighlightFlag> getFlags(String field) {
- return Collections.emptySet(); // no WEIGHT_MATCHES
- }
- };
- TermQuery query = new TermQuery(new Term("body", "vectors"));
- TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER);
- try {
- highlighter.highlight("body", query, topDocs, 1); // should throw
- } finally {
- ir.close();
+ IndexSearcher searcher = newSearcher(ir);
+ UnifiedHighlighter.Builder uhBuilder =
+ new UnifiedHighlighter.Builder(searcher, indexAnalyzer);
+ UnifiedHighlighter highlighter =
+ new UnifiedHighlighter(uhBuilder) {
+ @Override
+ protected Set<HighlightFlag> getFlags(String field) {
+ return Collections.emptySet(); // no WEIGHT_MATCHES
+ }
+ };
+ TermQuery query = new TermQuery(new Term("body", "vectors"));
+ TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER);
+ expectThrows(
+ IllegalArgumentException.class, () -> highlighter.highlight("body", query, topDocs, 1));
}
}
}
diff --git a/lucene/luke/src/test/org/apache/lucene/luke/models/analysis/TestAnalysisImpl.java b/lucene/luke/src/test/org/apache/lucene/luke/models/analysis/TestAnalysisImpl.java
index 99d1f057358..cdf0f9213a8 100644
--- a/lucene/luke/src/test/org/apache/lucene/luke/models/analysis/TestAnalysisImpl.java
+++ b/lucene/luke/src/test/org/apache/lucene/luke/models/analysis/TestAnalysisImpl.java
@@ -132,7 +132,7 @@ public class TestAnalysisImpl extends LuceneTestCase {
assertNotNull(tokens);
}
- @Test(expected = LukeException.class)
+ @Test
public void testAnalyzeStepByStep_preset() {
AnalysisImpl analysis = new AnalysisImpl();
String analyzerType = "org.apache.lucene.analysis.standard.StandardAnalyzer";
@@ -140,7 +140,7 @@ public class TestAnalysisImpl extends LuceneTestCase {
assertEquals(analyzerType, analyzer.getClass().getName());
String text = "This test must fail.";
- analysis.analyzeStepByStep(text);
+ expectThrows(LukeException.class, () -> analysis.analyzeStepByStep(text));
}
@Test
diff --git a/lucene/luke/src/test/org/apache/lucene/luke/models/documents/TestDocumentsImpl.java b/lucene/luke/src/test/org/apache/lucene/luke/models/documents/TestDocumentsImpl.java
index b230778331e..d9c5bca2cc7 100644
--- a/lucene/luke/src/test/org/apache/lucene/luke/models/documents/TestDocumentsImpl.java
+++ b/lucene/luke/src/test/org/apache/lucene/luke/models/documents/TestDocumentsImpl.java
@@ -243,10 +243,10 @@ public class TestDocumentsImpl extends DocumentsTestBase {
assertEquals(0, documents.getTermPositions().size());
}
- @Test(expected = AlreadyClosedException.class)
+ @Test
public void testClose() throws Exception {
new DocumentsImpl(reader);
reader.close();
- IndexUtils.getFieldNames(reader);
+ expectThrows(AlreadyClosedException.class, () -> IndexUtils.getFieldNames(reader));
}
}
diff --git a/lucene/luke/src/test/org/apache/lucene/luke/models/overview/TestOverviewImpl.java b/lucene/luke/src/test/org/apache/lucene/luke/models/overview/TestOverviewImpl.java
index 04707358518..bab9acef197 100644
--- a/lucene/luke/src/test/org/apache/lucene/luke/models/overview/TestOverviewImpl.java
+++ b/lucene/luke/src/test/org/apache/lucene/luke/models/overview/TestOverviewImpl.java
@@ -121,16 +121,16 @@ public class TestOverviewImpl extends OverviewTestBase {
assertEquals("f2", result.get(0).getField());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testGetTopTerms_illegal_numterms() {
OverviewImpl overview = new OverviewImpl(reader, indexDir.toString());
- overview.getTopTerms("f2", -1);
+ expectThrows(IllegalArgumentException.class, () -> overview.getTopTerms("f2", -1));
}
- @Test(expected = AlreadyClosedException.class)
+ @Test
public void testClose() throws Exception {
OverviewImpl overview = new OverviewImpl(reader, indexDir.toString());
reader.close();
- overview.getNumFields();
+ expectThrows(AlreadyClosedException.class, () -> overview.getNumFields());
}
}
diff --git a/lucene/luke/src/test/org/apache/lucene/luke/models/search/TestSearchImpl.java b/lucene/luke/src/test/org/apache/lucene/luke/models/search/TestSearchImpl.java
index 6a3e4dc2c22..a2ba76b2c1a 100644
--- a/lucene/luke/src/test/org/apache/lucene/luke/models/search/TestSearchImpl.java
+++ b/lucene/luke/src/test/org/apache/lucene/luke/models/search/TestSearchImpl.java
@@ -254,10 +254,10 @@ public class TestSearchImpl extends LuceneTestCase {
search.guessSortTypes("f7").toArray());
}
- @Test(expected = LukeException.class)
+ @Test
public void testGuessSortTypesNoSuchField() {
SearchImpl search = new SearchImpl(reader);
- search.guessSortTypes("unknown");
+ expectThrows(LukeException.class, () -> search.guessSortTypes("unknown"));
}
@Test
@@ -295,11 +295,10 @@ public class TestSearchImpl extends LuceneTestCase {
assertFalse(search.getSortType("f7", "STRING", false).isPresent());
}
- @Test(expected = LukeException.class)
+ @Test
public void testGetSortTypeNoSuchField() {
SearchImpl search = new SearchImpl(reader);
-
- search.getSortType("unknown", "STRING", false);
+ expectThrows(LukeException.class, () -> search.getSortType("unknown", "STRING", false));
}
@Test
@@ -341,10 +340,10 @@ public class TestSearchImpl extends LuceneTestCase {
assertEquals(10, res.getOffset());
}
- @Test(expected = LukeException.class)
+ @Test
public void testNextPageSearchNotStarted() {
SearchImpl search = new SearchImpl(reader);
- search.nextPage();
+ expectThrows(LukeException.class, () -> search.nextPage());
}
@Test
@@ -371,10 +370,10 @@ public class TestSearchImpl extends LuceneTestCase {
assertEquals(0, res.getOffset());
}
- @Test(expected = LukeException.class)
+ @Test
public void testPrevPageSearchNotStarted() {
SearchImpl search = new SearchImpl(reader);
- search.prevPage();
+ expectThrows(LukeException.class, () -> search.prevPage());
}
@Test
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/spans/TestSpanWithinQuery.java b/lucene/queries/src/test/org/apache/lucene/queries/spans/TestSpanWithinQuery.java
index 5a8164930fc..026081e0223 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/spans/TestSpanWithinQuery.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/spans/TestSpanWithinQuery.java
@@ -118,12 +118,16 @@ public class TestSpanWithinQuery extends LuceneTestCase {
check(query, expectedDocs);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testDifferentFieldsThrowsIllegalArgumentException() {
SpanQuery big = new SpanTermQuery(new Term("field1", "one"));
SpanQuery little = new SpanTermQuery(new Term("field2", "two"));
- new SpanWithinQuery(big, little);
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ new SpanWithinQuery(big, little);
+ });
}
public void testToString() {
diff --git a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/vector/TestPointVectorStrategy.java b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/vector/TestPointVectorStrategy.java
index e6ddd2a3adc..0e6ef3f16f2 100644
--- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/vector/TestPointVectorStrategy.java
+++ b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/vector/TestPointVectorStrategy.java
@@ -51,12 +51,12 @@ public class TestPointVectorStrategy extends StrategyTestCase {
assertNotNull(query);
}
- @Test(expected = UnsupportedOperationException.class)
+ @Test
public void testInvalidQueryShape() {
this.strategy = PointVectorStrategy.newInstance(ctx, getClass().getSimpleName());
Point point = ctx.makePoint(0, 0);
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, point);
- this.strategy.makeQuery(args);
+ expectThrows(UnsupportedOperationException.class, () -> this.strategy.makeQuery(args));
}
@Test
(lucene) 02/04: Update documentation for Lucene104PostingsFormat (#15625)
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jainankitk pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit c7c5a67acd7c920999fd5aff94d708489d164ee7
Author: 兆森 <wa...@gmail.com>
AuthorDate: Thu Jan 29 07:57:31 2026 +0800
Update documentation for Lucene104PostingsFormat (#15625)
---
lucene/CHANGES.txt | 2 ++
.../org/apache/lucene/codecs/lucene104/Lucene104PostingsFormat.java | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index e85c3b8f499..92d27a3c348 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -255,6 +255,8 @@ Other
* GITHUB#15341: Align float vectors on disk to 64 bytes, for optimal performance on Arm Neoverse
machines (including vectors inside CFS files). (Mike McCandless, Kaival Parikh)
+* GITHUB#15619: Update documentation in Lucene104PostingsFormat. with 259 documents, the first 256 document ids should be encoded as one packed block (Lyon-NEU)
+
Build
---------------------
* Upgrade forbiddenapis to version 3.10. (Uwe Schindler)
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene104/Lucene104PostingsFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene104/Lucene104PostingsFormat.java
index 7f901bd90dc..7517a3509c7 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene104/Lucene104PostingsFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene104/Lucene104PostingsFormat.java
@@ -51,7 +51,7 @@ import org.apache.lucene.util.packed.PackedInts;
* <p>When the postings are long enough, Lucene104PostingsFormat will try to encode most
* integer data as a packed block.
* <p>Take a term with 259 documents as an example, the first 256 document ids are encoded as
- * two packed blocks, while the remaining 3 are encoded as one VInt block.
+ * one packed block, while the remaining 3 are encoded as one VInt block.
* <p>Different kinds of data are always encoded separately into different packed blocks, but
* may possibly be interleaved into the same VInt block.
* <p>This strategy is applied to pairs: <document number, frequency>, <position,
(lucene) 04/04: Fix FVH boost issue (#15442) (#15635)
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jainankitk pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit a9d3f4dbd986e021acad145eb23b95c34e507893
Author: yangfeng123456 <10...@users.noreply.github.com>
AuthorDate: Wed Feb 4 08:07:39 2026 +0800
Fix FVH boost issue (#15442) (#15635)
---
lucene/CHANGES.txt | 4 ++++
.../search/vectorhighlight/FieldPhraseList.java | 1 +
.../vectorhighlight/TestFieldPhraseList.java | 24 ++++++++++++++++++++++
3 files changed, 29 insertions(+)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 92d27a3c348..08c51862bf0 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -205,6 +205,10 @@ Optimizations
Bug Fixes
---------------------
+* GITHUB#15442: Preserve boost values when merging overlapping phrases in
+ FastVectorHighlighter so highlight scoring fully reflects query boosts.
+ (Yang Feng)
+
* GITHUB#14161: PointInSetQuery's constructor now throws IllegalArgumentException
instead of UnsupportedOperationException when values are out of order. (Shubham Sharma)
diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldPhraseList.java b/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldPhraseList.java
index ae3bd7b0357..63e77b48657 100644
--- a/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldPhraseList.java
+++ b/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldPhraseList.java
@@ -177,6 +177,7 @@ public class FieldPhraseList {
// The result is that all informations in TermInfo are lost and not available for further
// operations.
existWpi.getTermsInfos().addAll(wpi.getTermsInfos());
+ existWpi.boost += wpi.getBoost(); // Accumulate boost
return;
}
}
diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/TestFieldPhraseList.java b/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/TestFieldPhraseList.java
index 8396423e37b..f2b76a6e722 100644
--- a/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/TestFieldPhraseList.java
+++ b/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/TestFieldPhraseList.java
@@ -289,4 +289,28 @@ public class TestFieldPhraseList extends AbstractTestCase {
assertTrue(a.compareTo(b) < 0);
assertTrue(b.compareTo(a) > 0);
}
+
+ public void testMergeOverlappingWeightedPhraseInfoAccumulateBoost() {
+ LinkedList<TermInfo> infos1 = new LinkedList<>();
+ infos1.add(new TermInfo("中国", 0, 2, 0, 0));
+ infos1.add(new TermInfo("经济", 3, 5, 1, 1));
+ WeightedPhraseInfo wpi1 = new WeightedPhraseInfo(infos1, 2.0f);
+
+ LinkedList<TermInfo> infos2 = new LinkedList<>();
+ infos2.add(new TermInfo("经济", 3, 5, 1, 1));
+ infos2.add(new TermInfo("发展", 6, 8, 2, 2));
+ WeightedPhraseInfo wpi2 = new WeightedPhraseInfo(infos2, 3.0f);
+
+ FieldPhraseList fpl = new FieldPhraseList(new FieldPhraseList[0]);
+ fpl.getPhraseList().add(wpi1);
+
+ // This will execute: existWpi.boost += wpi.getBoost();
+ fpl.addIfNoOverlap(wpi2);
+
+ assertEquals(1, fpl.getPhraseList().size());
+
+ WeightedPhraseInfo merged = fpl.getPhraseList().get(0);
+
+ assertEquals(5.0f, merged.getBoost(), 0.0001f);
+ }
}
(lucene) 03/04: Minor refactor in SegmentTermsEnum.java (#15624)
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jainankitk pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit 0423a521d8bac6117d193eb2954721297bb151c5
Author: Shubham Sharma <sh...@gmail.com>
AuthorDate: Fri Jan 30 07:39:56 2026 +0000
Minor refactor in SegmentTermsEnum.java (#15624)
---
.../lucene103/blocktree/SegmentTermsEnum.java | 27 +++++-----------------
1 file changed, 6 insertions(+), 21 deletions(-)
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene103/blocktree/SegmentTermsEnum.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene103/blocktree/SegmentTermsEnum.java
index 99acaae560d..c0c0991dfce 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene103/blocktree/SegmentTermsEnum.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene103/blocktree/SegmentTermsEnum.java
@@ -434,27 +434,7 @@ final class SegmentTermsEnum extends BaseTermsEnum {
return null;
}
- if (prefetch) {
- currentFrame.prefetchBlock();
- }
-
- return () -> {
- currentFrame.loadBlock();
-
- final SeekStatus result = currentFrame.scanToTerm(target, true);
- if (result == SeekStatus.FOUND) {
- // if (DEBUG) {
- // System.out.println(" return FOUND term=" + term.utf8ToString() + " " + term);
- // }
- return true;
- } else {
- // if (DEBUG) {
- // System.out.println(" got " + result + "; return NOT_FOUND term=" +
- // ToStringUtils.bytesRefToString(term));
- // }
- return false;
- }
- };
+ return getIOBooleanSupplier(target, prefetch);
} else {
// Follow this node
node = nextNode;
@@ -491,6 +471,11 @@ final class SegmentTermsEnum extends BaseTermsEnum {
return null;
}
+ return getIOBooleanSupplier(target, prefetch);
+ }
+
+ private IOBooleanSupplier getIOBooleanSupplier(BytesRef target, boolean prefetch)
+ throws IOException {
if (prefetch) {
currentFrame.prefetchBlock();
}