Skip to content

Commit a907c98

Browse files
committed
Merge pull request #681 from acdevlin/master
Fix for issue 294 (definitions search displays comment lines)
2 parents 385ebf3 + d39e00d commit a907c98

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

src/org/opensolaris/opengrok/search/QueryBuilder.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,21 @@ public int getSize() {
200200
return queries.size();
201201
}
202202

203+
/**
204+
* Used to tell if this search only has the "definitions" field filled in
205+
*
206+
* @return whether above statement is true or false
207+
*/
208+
public boolean isDefSearch() {
209+
210+
return ((getQueryText(FULL) == null) &&
211+
(getQueryText(REFS) == null) &&
212+
(getQueryText(PATH) == null) &&
213+
(getQueryText(HIST) == null) &&
214+
(getQueryText(DEFS) != null))
215+
? true : false;
216+
}
217+
203218
/**
204219
* Build a new query based on the query text that has been passed in to this
205220
* builder.

src/org/opensolaris/opengrok/search/Results.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ public static void prettyPrint(Writer out, SearchHelper sh, int start,
202202
FileReader r = genre == Genre.PLAIN
203203
? new FileReader(new File(sh.sourceRoot, rpath))
204204
: null;
205-
sh.sourceContext.getContext(r, out, xrefPrefix,
206-
morePrefix, rpath, tags, true, null);
205+
sh.sourceContext.getContext(r, out, xrefPrefix, morePrefix,
206+
rpath, tags, true, sh.builder.isDefSearch(), null);
207207
}
208208
}
209209
if (sh.historyContext != null) {

src/org/opensolaris/opengrok/search/SearchEngine.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ public void results(int start, int end, List<Hit> ret) {
354354
if (Genre.PLAIN == genre && (source != null)) {
355355
hasContext = sourceContext.getContext(new InputStreamReader(new FileInputStream(source
356356
+ filename)), null, null, null, filename,
357-
tags, nhits > 100, ret);
357+
tags, nhits > 100, false, ret);
358358
} else if (Genre.XREFABLE == genre && data != null && summarizer != null) {
359359
int l = 0;
360360
try (Reader r = RuntimeEnvironment.getInstance().isCompressXref() ?
@@ -377,11 +377,11 @@ public void results(int start, int end, List<Hit> ret) {
377377
}
378378
} else {
379379
OpenGrokLogger.getLogger().log(Level.WARNING, "Unknown genre: {0} for {1}", new Object[]{genre, filename});
380-
hasContext |= sourceContext.getContext(null, null, null, null, filename, tags, false, ret);
380+
hasContext |= sourceContext.getContext(null, null, null, null, filename, tags, false, false, ret);
381381
}
382382
} catch (FileNotFoundException exp) {
383383
OpenGrokLogger.getLogger().log(Level.WARNING, "Couldn''t read summary from {0} ({1})", new Object[]{filename, exp.getMessage()});
384-
hasContext |= sourceContext.getContext(null, null, null, null, filename, tags, false, ret);
384+
hasContext |= sourceContext.getContext(null, null, null, null, filename, tags, false, false, ret);
385385
}
386386
}
387387
if (historyContext != null) {

src/org/opensolaris/opengrok/search/context/Context.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private void buildQueryAsURI(Map<String, String> subqueries) {
127127
*/
128128
public boolean getContext(Reader in, Writer out, String urlPrefix,
129129
String morePrefix, String path, Definitions tags,
130-
boolean limit, List<Hit> hits) {
130+
boolean limit, boolean isDefSearch, List<Hit> hits) {
131131
alt = !alt;
132132
if (m == null) {
133133
IOUtils.close(in);
@@ -250,7 +250,9 @@ public boolean getContext(Reader in, Writer out, String urlPrefix,
250250
for (int i = 0; i < m.length; i++) {
251251
matchState = m[i].match(token);
252252
if (matchState == LineMatcher.MATCHED) {
253-
tokens.printContext();
253+
if (!isDefSearch) {
254+
tokens.printContext();
255+
}
254256
matchedLines++;
255257
//out.write("<br> <i>Matched " + token + " maxlines = " + matchedLines + "</i><br>");
256258
break;

web/more.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ file="mast.jsp"
5050
<pre><%
5151
sourceContext.getContext(new FileReader(cfg.getResourceFile()), out,
5252
request.getContextPath() + Prefix.XREF_P, null, cfg.getPath(),
53-
null, false, null);
53+
null, false, false, null);
5454
%></pre>
5555
</div><%
5656
}

0 commit comments

Comments
 (0)