Skip to content

Commit 9916763

Browse files
committed
Add hidden #xrd to manage redirect/no-redirect
1 parent fe7b53d commit 9916763

File tree

6 files changed

+21
-3
lines changed

6 files changed

+21
-3
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/web/PageConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,8 @@ public SearchHelper prepareInternalSearch() {
15271527
sh.isGuiSearch = sh.isCrossRefSearch || getPrefix() == Prefix.SEARCH_P;
15281528
sh.desc = getEftarReader();
15291529
sh.sourceRoot = new File(getSourceRootPath());
1530+
String xrValue = req.getParameter(QueryParameters.NO_REDIRECT_PARAM);
1531+
sh.noRedirect = xrValue != null && !xrValue.isEmpty();
15301532
return sh;
15311533
}
15321534

opengrok-indexer/src/main/java/org/opengrok/indexer/web/QueryParameters.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ public class QueryParameters {
117117
*/
118118
public static final String MATCH_OFFSET_PARAM_EQ = MATCH_OFFSET_PARAM + "=";
119119

120+
/**
121+
* Parameter name to specify a value indicating if redirection should be
122+
* short-circuited when state or query result would have an indicated
123+
* otherwise.
124+
*/
125+
public static final String NO_REDIRECT_PARAM = "xrd";
126+
120127
/**
121128
* Parameter name to specify an OpenGrok search of paths.
122129
*/

opengrok-indexer/src/main/java/org/opengrok/indexer/web/Scripts.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public String toHtml() {
110110
putjs("jquery-ui", "js/jquery-ui-1.12.1-custom", 11);
111111
putjs("jquery-tablesorter", "js/jquery-tablesorter-2.26.6", 12);
112112
putjs("tablesorter-parsers", "js/tablesorter-parsers-0.0.2", 13, true);
113-
putjs("searchable-option-list", "js/searchable-option-list-2.0.11", 14);
113+
putjs("searchable-option-list", "js/searchable-option-list-2.0.12", 14);
114114
putjs("utils", "js/utils-0.0.34", 15, true);
115115
putjs("repos", "js/repos-0.0.2", 20, true);
116116
putjs("diff", "js/diff-0.0.4", 20, true);

opengrok-indexer/src/main/java/org/opengrok/indexer/web/SearchHelper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ public class SearchHelper {
156156
* set via {@link #prepareExec(SortedSet)} and {@link #executeQuery()}.
157157
*/
158158
public String redirect;
159+
/**
160+
* A value indicating if redirection should be short-circuited when state or
161+
* query result would have indicated otherwise.
162+
*/
163+
public boolean noRedirect;
159164
/**
160165
* if not {@code null}, the UI should show this error message and stop
161166
* processing the search. Automatically set via
@@ -404,7 +409,7 @@ public SearchHelper executeQuery() {
404409
* Determine if possibly a single-result redirect to xref is
405410
* eligible and applicable. If history query is active, then nope.
406411
*/
407-
if (hits != null && hits.length == 1 && builder.getHist() == null) {
412+
if (!noRedirect && hits != null && hits.length == 1 && builder.getHist() == null) {
408413
int docID = hits[0].doc;
409414
if (isCrossRefSearch && query instanceof TermQuery && builder.getDefs() != null) {
410415
maybeRedirectToDefinition(docID, (TermQuery) query);

opengrok-web/src/main/webapp/js/searchable-option-list-2.0.11.js renamed to opengrok-web/src/main/webapp/js/searchable-option-list-2.0.12.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,7 @@
10941094
* Modified for OpenGrok in 2017.
10951095
*/
10961096
if (isOnSearchPage()) {
1097+
$('#xrd').val("1"); // no redirect
10971098
$('#sbox').submit();
10981099
}
10991100
})

opengrok-web/src/main/webapp/menu.jspf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ document.domReady.push(function() { domReadyMenu(); });
230230
</tbody>
231231
</table>
232232
<div id="form-controls">
233-
<input tabindex="9" class="submit btn" type="submit" value="Search"/>
233+
<input tabindex="9" class="submit btn" onclick="$('#xrd').val(''); $('#sbox').submit()"
234+
type="button" value="Search"/>
234235
<input tabindex="10" class="submit btn" onclick="javascript: clearSearchFrom();"
235236
type="button" value="Clear"/>
236237
<input tabindex="11" class="submit btn" onclick="window.open('help.jsp', '_blank');"
@@ -240,6 +241,8 @@ document.domReady.push(function() { domReadyMenu(); });
240241
<div id="ltbl">
241242
<!-- filled with javascript -->
242243
</div>
244+
<input type="hidden" id="<%= QueryParameters.NO_REDIRECT_PARAM %>"
245+
name="<%= QueryParameters.NO_REDIRECT_PARAM %>" value=""/>
243246
</form>
244247
<div class="clearfix"></div>
245248
<%

0 commit comments

Comments
 (0)