dsmiley commented on code in PR #14448: URL: https://github.com/apache/lucene/pull/14448#discussion_r2033180408
########## lucene/queries/src/test/org/apache/lucene/queries/function/TestLongNormValueSource.java: ########## @@ -16,99 +16,70 @@ */ package org.apache.lucene.queries.function; -import org.apache.lucene.analysis.Analyzer; +import java.util.function.Function; import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; +import org.apache.lucene.document.Field.Store; +import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; -import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.queries.function.valuesource.NormValueSource; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Sort; -import org.apache.lucene.search.SortField; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.similarities.ClassicSimilarity; import org.apache.lucene.search.similarities.Similarity; -import org.apache.lucene.store.Directory; import org.apache.lucene.tests.analysis.MockAnalyzer; import org.apache.lucene.tests.index.RandomIndexWriter; import org.apache.lucene.tests.search.CheckHits; import org.apache.lucene.tests.util.LuceneTestCase; -import org.junit.AfterClass; -import org.junit.BeforeClass; public class TestLongNormValueSource extends LuceneTestCase { - static Directory dir; - static IndexReader reader; - static IndexSearcher searcher; - static Analyzer analyzer; - - private static final Similarity sim = new ClassicSimilarity(); - - @BeforeClass - public static void beforeClass() throws Exception { - dir = newDirectory(); - analyzer = new MockAnalyzer(random()); + public void testNorm() throws Exception { + Similarity sim = new ClassicSimilarity(); + final var field = "text"; + var analyzer = new MockAnalyzer(random()); + var dir = newDirectory(); IndexWriterConfig iwConfig = newIndexWriterConfig(analyzer); iwConfig.setMergePolicy(newLogMergePolicy()); iwConfig.setSimilarity(sim); - RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwConfig); - Document doc = new Document(); - doc.add(new TextField("text", "this is a test test test", Field.Store.NO)); - iw.addDocument(doc); + try (RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwConfig)) { - doc = new Document(); - doc.add(new TextField("text", "second test", Field.Store.NO)); - iw.addDocument(doc); + // the leading number is the number of terms / positions for that value + final var store = Store.YES; + Document doc = new Document(); + doc.add(new StringField("id", "6", store)); + doc.add(new TextField(field, "this is a test test test", store)); + iw.addDocument(doc); - reader = iw.getReader(); - searcher = newSearcher(reader); - iw.close(); - } + doc = new Document(); + doc.add(new StringField("id", "2", store)); + doc.add(new TextField(field, "second test", store)); + iw.addDocument(doc); - @AfterClass - public static void afterClass() throws Exception { - searcher = null; - reader.close(); - reader = null; - dir.close(); - dir = null; - analyzer.close(); - analyzer = null; - } + IndexSearcher searcher; + try (var reader = iw.getReader()) { + searcher = newSearcher(reader); + searcher.setSimilarity(sim); - public void testNorm() throws Exception { - Similarity saved = searcher.getSimilarity(); - try { - // no norm field (so agnostic to indexed similarity) - searcher.setSimilarity(sim); - assertHits(new FunctionQuery(new NormValueSource("text")), new float[] {0f, 0f}); + Query q = + new FunctionQuery(((Function<String, ValueSource>) NormValueSource::new).apply(field)); Review Comment: Oops; a left-over from a refactoring. Fixed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org