Skip to content

Commit c1c3545

Browse files
committed
Remove a bit of old redundancy
1 parent 0561895 commit c1c3545

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.apache.lucene.document.Document;
4646
import org.apache.lucene.index.DirectoryReader;
4747
import org.apache.lucene.index.IndexReader;
48+
import org.apache.lucene.index.IndexableField;
4849
import org.apache.lucene.index.Term;
4950
import org.apache.lucene.queryparser.classic.ParseException;
5051
import org.apache.lucene.search.BooleanQuery;
@@ -401,21 +402,24 @@ public SearchHelper executeQuery() {
401402
// one single definition term AND we have exactly one match AND there
402403
// is only one definition of that symbol in the document that matches.
403404
boolean uniqueDefinition = false;
405+
Document doc = null;
406+
String symbol = null;
404407
if (isCrossRefSearch && isSingleDefinitionSearch && hits != null && hits.length == 1) {
405-
Document doc = searcher.doc(hits[0].doc);
406-
if (doc.getField(QueryBuilder.TAGS) != null) {
407-
byte[] rawTags = doc.getField(QueryBuilder.TAGS).binaryValue().bytes;
408+
doc = searcher.doc(hits[0].doc);
409+
IndexableField tagsField = doc.getField(QueryBuilder.TAGS);
410+
if (tagsField != null) {
411+
byte[] rawTags = tagsField.binaryValue().bytes;
408412
Definitions tags = Definitions.deserialize(rawTags);
409-
String symbol = ((TermQuery) query).getTerm().text();
413+
symbol = ((TermQuery) query).getTerm().text();
410414
if (tags.occurrences(symbol) == 1) {
411415
uniqueDefinition = true;
412416
}
413417
}
414418
}
415419
if (uniqueDefinition) {
416-
String anchor = Util.URIEncode(((TermQuery) query).getTerm().text());
420+
String anchor = Util.URIEncode(symbol);
417421
redirect = contextPath + Prefix.XREF_P
418-
+ Util.URIEncodePath(searcher.doc(hits[0].doc).get(QueryBuilder.PATH))
422+
+ Util.URIEncodePath(doc.get(QueryBuilder.PATH))
419423
+ '?' + QueryParameters.FRAGMENT_IDENTIFIER_PARAM_EQ + anchor
420424
+ '#' + anchor;
421425
}

0 commit comments

Comments
 (0)