Skip to content

Commit 84769d7

Browse files
committed
fix silly exception when highlightQuery is provided but there are no hits; improve verbosity of build.py to list specific sources it is compiling; remove useless DateTimeUtil that was always being compiled because of mismatch package name & its source location
1 parent fe698dc commit 84769d7

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

build.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,16 @@ def compileChangedSources(srcPath, destPath, classPath):
353353
classFileName = 'build/classes/%s.class' % ('%s/%s' % (root, fileName))[4:-5]
354354
if not os.path.exists(classFileName) or os.path.getmtime(classFileName) < os.path.getmtime('%s/%s' % (root, fileName)):
355355
changedSources.append('%s/%s' % (root, fileName))
356+
print(f'{fileName} {classFileName}')
356357

357358
if len(changedSources) > 0:
358359
cmd = ['javac', '-Xmaxerrs', '10000', '-d', destPath]
359360
cmd.append('-cp')
360361
cmd.append(':'.join(classPath))
361362
cmd.extend(changedSources)
362-
if False:
363-
print('compile sources:')
364-
for fileName in changedSources:
365-
print(' %s' % fileName)
366-
else:
367-
print('compile %d sources' % len(changedSources))
363+
print(f'compile {len(changedSources)} sources:')
364+
for fileName in changedSources:
365+
print(' %s' % fileName)
368366
run(' '.join(cmd))
369367

370368
def getCompileClassPath():

src/java/org/apache/lucene/server/handlers/SearchHandler.java

+4
Original file line numberDiff line numberDiff line change
@@ -2773,7 +2773,11 @@ protected boolean scoreSubDocsAtOnce() {
27732773
queryForHighlights,
27742774
highlightDocIDs,
27752775
maxPassages);
2776+
} else {
2777+
// #26: so we consume the parameter even if there are no hits
2778+
r.clearParam("highlightQuery");
27762779
}
2780+
27772781
diagnostics.put("highlightTimeMS", (System.nanoTime() - t0)/1000000.);
27782782

27792783
t0 = System.nanoTime();

src/java/org/apache/lucene/server/util/DateTimeUtil.java

-18
This file was deleted.

src/test/org/apache/lucene/server/TestHighlight.java

+23
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,29 @@ public void testContentWithSep() throws Exception {
202202
}
203203
}
204204

205+
public void testHighlightQueryWithHit() throws Exception {
206+
deleteAllDocs();
207+
208+
long gen = addDocument("{fields: {authors: ['Dr. Seuss', 'Bob Smith', 'Seuss is Fun. Some extra content.']}}");
209+
JSONObject result = send("search", "{queryText: 'authors:seuss', retrieveFields: [{field: authors, highlight: snippets, maxPassages: 1}], " +
210+
"highlightQuery: {class: TermQuery, field: authors, term: seuss}, " +
211+
"searcher: {indexGen: " + gen + "}}");
212+
assertEquals(1, getInt(result, "hits.length"));
213+
assertEquals(1, getInt(result, "hits[0].fields.authors.length"));
214+
assertEquals("<b>Seuss</b> Bob Smith <b>Seuss</b> is Fun. ", renderSingleHighlight(getArray(result, "hits[0].fields.authors[0].parts")));
215+
}
216+
217+
// #26: do not throw exception if highlightQuery is provided and there are no hits!
218+
public void testHighlightQueryNoHits() throws Exception {
219+
deleteAllDocs();
220+
221+
long gen = addDocument("{fields: {authors: ['Dr. Seuss', 'Bob Smith', 'Seuss is Fun. Some extra content.']}}");
222+
JSONObject result = send("search", "{queryText: 'authors:foobar', retrieveFields: [{field: authors}], " +
223+
"highlightQuery: {class: TermQuery, field: authors, term: seuss}, " +
224+
"searcher: {indexGen: " + gen + "}}");
225+
assertEquals(0, getInt(result, "hits.length"));
226+
}
227+
205228
// nocommit fixme
206229
/*
207230
public void testNonDefaultOffsetGap() throws Exception {

0 commit comments

Comments
 (0)