Copilot commented on code in PR #5224:
URL: https://github.com/apache/solr/pull/5224#discussion_r4368757262


##########
solr/core/src/test/org/apache/solr/search/TestScriptFilterIntervalsSource.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search;
+
+import java.io.IOException;
+import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.analysis.MockTokenizer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.TextField;
+import org.apache.lucene.expressions.Expression;
+import org.apache.lucene.expressions.js.JavascriptCompiler;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.queries.intervals.IntervalMatchesIterator;
+import org.apache.lucene.queries.intervals.Intervals;
+import org.apache.lucene.store.Directory;
+import org.apache.solr.SolrTestCase;
+
+/** Tests {@link ScriptFilterIntervalsSource#matches}, which highlighting and 
explain rely on. */
+public class TestScriptFilterIntervalsSource extends SolrTestCase {
+
+  private static final String FIELD = "f";
+
+  private static ScriptFilterIntervalsSource filter(String script) throws 
Exception {
+    Expression expression = JavascriptCompiler.compile(script);
+    return new ScriptFilterIntervalsSource(
+        Intervals.term("a"), expression, new 
ScriptFilterIntervalsSource.IntervalBindings());
+  }
+
+  private static IntervalMatchesIterator matches(
+      Directory dir, ScriptFilterIntervalsSource source, int doc) throws 
IOException {
+    try (DirectoryReader reader = DirectoryReader.open(dir)) {
+      LeafReaderContext ctx = reader.leaves().get(0);
+      return source.matches(FIELD, ctx, doc);

Review Comment:
   The try-with-resources closes the DirectoryReader before the caller consumes 
the returned IntervalMatchesIterator. The iterator still delegates to the 
reader's postings when next() advances, so these tests use reader-backed state 
after it has been closed and can fail with closed-input errors depending on the 
codec/directory. Keep the reader open around the iterator assertions in each 
test and pass its context into this helper.



##########
solr/core/src/test/org/apache/solr/search/TestScriptFilterIntervalsSource.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search;
+
+import java.io.IOException;
+import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.analysis.MockTokenizer;

Review Comment:
   These test utilities are in `org.apache.lucene.tests.analysis`, not 
`org.apache.lucene.analysis` (see the imports in `TestSolrCoreParser.java`). 
Both imports are unresolved, so the core test sources cannot compile and none 
of the new tests can run. Import the classes from the Lucene test-framework 
package.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to