|
45 | 45 | import org.apache.lucene.document.Document;
|
46 | 46 | import org.apache.lucene.index.DirectoryReader;
|
47 | 47 | import org.apache.lucene.index.IndexReader;
|
| 48 | +import org.apache.lucene.index.IndexableField; |
48 | 49 | import org.apache.lucene.index.Term;
|
49 | 50 | import org.apache.lucene.queryparser.classic.ParseException;
|
50 | 51 | import org.apache.lucene.search.BooleanQuery;
|
@@ -401,21 +402,24 @@ public SearchHelper executeQuery() {
|
401 | 402 | // one single definition term AND we have exactly one match AND there
|
402 | 403 | // is only one definition of that symbol in the document that matches.
|
403 | 404 | boolean uniqueDefinition = false;
|
| 405 | + Document doc = null; |
| 406 | + String symbol = null; |
404 | 407 | 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; |
408 | 412 | Definitions tags = Definitions.deserialize(rawTags);
|
409 |
| - String symbol = ((TermQuery) query).getTerm().text(); |
| 413 | + symbol = ((TermQuery) query).getTerm().text(); |
410 | 414 | if (tags.occurrences(symbol) == 1) {
|
411 | 415 | uniqueDefinition = true;
|
412 | 416 | }
|
413 | 417 | }
|
414 | 418 | }
|
415 | 419 | if (uniqueDefinition) {
|
416 |
| - String anchor = Util.URIEncode(((TermQuery) query).getTerm().text()); |
| 420 | + String anchor = Util.URIEncode(symbol); |
417 | 421 | redirect = contextPath + Prefix.XREF_P
|
418 |
| - + Util.URIEncodePath(searcher.doc(hits[0].doc).get(QueryBuilder.PATH)) |
| 422 | + + Util.URIEncodePath(doc.get(QueryBuilder.PATH)) |
419 | 423 | + '?' + QueryParameters.FRAGMENT_IDENTIFIER_PARAM_EQ + anchor
|
420 | 424 | + '#' + anchor;
|
421 | 425 | }
|
|
0 commit comments