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


##########
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:
   while it passes, it's probably ok, until it fails.  



-- 
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