Skip to content

Commit 974067d

Browse files
idodeclareVladimir Kotal
authored andcommitted
Redirect when 1 hit for query of just PATH
1 parent c199a91 commit 974067d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/search/QueryBuilder.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,19 @@ public boolean isDefSearch() {
346346
&& (getQueryText(DEFS) != null));
347347
}
348348

349+
/**
350+
* Gets a value indicating if this search only has defined the {@link #PATH}
351+
* query field.
352+
*/
353+
public boolean isPathSearch() {
354+
return ((getQueryText(FULL) == null)
355+
&& (getQueryText(REFS) == null)
356+
&& (getQueryText(PATH) != null)
357+
&& (getQueryText(HIST) == null)
358+
&& (getQueryText(DIRPATH) == null)
359+
&& (getQueryText(DEFS) == null));
360+
}
361+
349362
/**
350363
* Build a new query based on the query text that has been passed in to this
351364
* builder.

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,11 @@ public SearchHelper executeQuery() {
400400
if (isCrossRefSearch && query instanceof TermQuery && builder.getDefs() != null) {
401401
maybeRedirectToDefinition(docID, (TermQuery) query);
402402
} else if (isGuiSearch) {
403-
maybeRedirectToMatchOffset(docID, builder.getContextFields());
403+
if (builder.isPathSearch()) {
404+
redirectToFile(docID);
405+
} else {
406+
maybeRedirectToMatchOffset(docID, builder.getContextFields());
407+
}
404408
}
405409
}
406410
} catch (IOException | ClassNotFoundException e) {
@@ -477,6 +481,11 @@ private void maybeRedirectToMatchOffset(int docID, List<String> contextFields)
477481
}
478482
}
479483

484+
private void redirectToFile(int docID) throws IOException {
485+
Document doc = searcher.doc(docID);
486+
redirect = contextPath + Prefix.XREF_P + Util.URIEncodePath(doc.get(QueryBuilder.PATH));
487+
}
488+
480489
private static final Pattern TABSPACE = Pattern.compile("[\t ]+");
481490

482491
private void getSuggestion(Term term, IndexReader ir,

0 commit comments

Comments
 (0)