Skip to content

Fix for issue 294 (definitions search displays comment lines) #681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/org/opensolaris/opengrok/search/QueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ public int getSize() {
return queries.size();
}

/**
* Used to tell if this search only has the "definitions" field filled in
*
* @return whether above statement is true or false
*/
public boolean isDefSearch() {

return ((getQueryText(FULL) == null) &&
(getQueryText(REFS) == null) &&
(getQueryText(PATH) == null) &&
(getQueryText(HIST) == null) &&
(getQueryText(DEFS) != null))
? true : false;
}

/**
* Build a new query based on the query text that has been passed in to this
* builder.
Expand Down
4 changes: 2 additions & 2 deletions src/org/opensolaris/opengrok/search/Results.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ public static void prettyPrint(Writer out, SearchHelper sh, int start,
FileReader r = genre == Genre.PLAIN
? new FileReader(new File(sh.sourceRoot, rpath))
: null;
sh.sourceContext.getContext(r, out, xrefPrefix,
morePrefix, rpath, tags, true, null);
sh.sourceContext.getContext(r, out, xrefPrefix, morePrefix,
rpath, tags, true, sh.builder.isDefSearch(), null);
}
}
if (sh.historyContext != null) {
Expand Down
6 changes: 3 additions & 3 deletions src/org/opensolaris/opengrok/search/SearchEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public void results(int start, int end, List<Hit> ret) {
if (Genre.PLAIN == genre && (source != null)) {
hasContext = sourceContext.getContext(new InputStreamReader(new FileInputStream(source
+ filename)), null, null, null, filename,
tags, nhits > 100, ret);
tags, nhits > 100, false, ret);
} else if (Genre.XREFABLE == genre && data != null && summarizer != null) {
int l = 0;
try (Reader r = RuntimeEnvironment.getInstance().isCompressXref() ?
Expand All @@ -377,11 +377,11 @@ public void results(int start, int end, List<Hit> ret) {
}
} else {
OpenGrokLogger.getLogger().log(Level.WARNING, "Unknown genre: {0} for {1}", new Object[]{genre, filename});
hasContext |= sourceContext.getContext(null, null, null, null, filename, tags, false, ret);
hasContext |= sourceContext.getContext(null, null, null, null, filename, tags, false, false, ret);
}
} catch (FileNotFoundException exp) {
OpenGrokLogger.getLogger().log(Level.WARNING, "Couldn''t read summary from {0} ({1})", new Object[]{filename, exp.getMessage()});
hasContext |= sourceContext.getContext(null, null, null, null, filename, tags, false, ret);
hasContext |= sourceContext.getContext(null, null, null, null, filename, tags, false, false, ret);
}
}
if (historyContext != null) {
Expand Down
6 changes: 4 additions & 2 deletions src/org/opensolaris/opengrok/search/context/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void buildQueryAsURI(Map<String, String> subqueries) {
*/
public boolean getContext(Reader in, Writer out, String urlPrefix,
String morePrefix, String path, Definitions tags,
boolean limit, List<Hit> hits) {
boolean limit, boolean isDefSearch, List<Hit> hits) {
alt = !alt;
if (m == null) {
IOUtils.close(in);
Expand Down Expand Up @@ -250,7 +250,9 @@ public boolean getContext(Reader in, Writer out, String urlPrefix,
for (int i = 0; i < m.length; i++) {
matchState = m[i].match(token);
if (matchState == LineMatcher.MATCHED) {
tokens.printContext();
if (!isDefSearch) {
tokens.printContext();
}
matchedLines++;
//out.write("<br> <i>Matched " + token + " maxlines = " + matchedLines + "</i><br>");
break;
Expand Down
2 changes: 1 addition & 1 deletion web/more.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ file="mast.jsp"
<pre><%
sourceContext.getContext(new FileReader(cfg.getResourceFile()), out,
request.getContextPath() + Prefix.XREF_P, null, cfg.getPath(),
null, false, null);
null, false, false, null);
%></pre>
</div><%
}
Expand Down