aboutsummaryrefslogtreecommitdiffstats
path: root/skate/map.go
diff options
context:
space:
mode:
Diffstat (limited to 'skate/map.go')
-rw-r--r--skate/map.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/skate/map.go b/skate/map.go
index b647480..17d9ed2 100644
--- a/skate/map.go
+++ b/skate/map.go
@@ -278,6 +278,40 @@ func MapperReleaseResolvedContainerName(p []byte) (fields [][]byte, err error) {
return [][]byte{key, p}, nil
}
+func MapperOpenLibraryReleaseNormalizedISBN(p []byte) (fields [][]byte, err error) {
+ var (
+ doc Release
+ key []byte
+ isbn13 string
+ )
+ if err := json.Unmarshal(p, &doc); err != nil {
+ return nil, err
+ }
+ // There can be 10 and 13 variants in the data, we always want 13.
+ for _, isbn := range doc.ExtIDs.ISBN {
+ if len(isbn) == 13 {
+ isbn13 = isbn
+ break
+ }
+ }
+ if isbn13 == "" {
+ // This is rarer, more expensive.
+ for _, isbn := range doc.ExtIDs.ISBN {
+ parsed := ParseIsbn(isbn)
+ if len(parsed) > 0 {
+ isbn13 = parsed[0]
+ break
+ }
+ }
+ }
+ if isbn13 == "" {
+ return nil, nil
+ } else {
+ key = []byte(isbn13)
+ }
+ return [][]byte{key, p}, nil
+}
+
// MapperPartial works on partial documents.
func MapperPartial(p []byte) (fields [][]byte, err error) {
// TODO: Group by some normlized container name or identifier.