-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VUFIND-1710 Add support for custom delimiters in topic browse
Ostensibly this just required a new TopicNormalizer, but the specific use case added a small complication. What want is to have our topic headings contain a UTF-8 marker (an en-space) to act as a delimiter between different terms. They'll be stripped out by the new TopicNormalizer for the purposes of searching and sorting, but VuFind will use the delimiter to display a user-selectable delimiter when showing topics. But, this extra delimiter would cause the lookup against the authority index to fail, since the authority index is always space-delimited. Further, we can't change the authority index to use the same delimiter as topics, because the authority index is a mixture of topics and names. So, in addition to the new TopicNormalizer, this commit extends the Normalizer interface to add a `headingForAuthQuery` method. By default this is a no-op (so existing code doesn't change), but the TopicNormalizer uses this to replace the UTF-8 delimiter with a regular space to allow the authority index lookup to succeed.
- Loading branch information
1 parent
61f367b
commit 1214786
Showing
4 changed files
with
45 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.vufind.util; | ||
|
||
public class TopicNormalizer implements Normalizer | ||
{ | ||
private Normalizer defaultNormalizer; | ||
|
||
public TopicNormalizer() { | ||
defaultNormalizer = new ICUCollatorNormalizer(); | ||
} | ||
|
||
// Separator defined by VuFind's marc.properties for topic_browse field. | ||
final static String TOPIC_TERM_SEPARATOR = "\u2002"; | ||
|
||
@Override | ||
public byte[] normalize(String s) | ||
{ | ||
// Treat topic term separators as spaces when producing a sort key | ||
return defaultNormalizer.normalize(s.replace(TOPIC_TERM_SEPARATOR, " ")); | ||
} | ||
|
||
@Override | ||
public String headingForAuthQuery(String heading) { | ||
// Auth DB uses single spaces as delimiters while topics use em spaces | ||
return heading.replace(TOPIC_TERM_SEPARATOR, " "); | ||
} | ||
|
||
} |