@@ -101,6 +101,9 @@ public struct ImportPipeline: Sendable {
101101 if let existing = try repository. liveDocumentNeedingPDF ( doi: doi, arxivId: arxivId) {
102102 var updated = existing
103103 record? . apply ( to: & updated)
104+ if updated. abstract? . isEmpty != false {
105+ updated. abstract = extracted? . abstract
106+ }
104107 updated. fileHash = hash
105108 updated. fileName = url. lastPathComponent
106109 let details = try repository. update (
@@ -113,6 +116,7 @@ public struct ImportPipeline: Sendable {
113116
114117 var document = Document (
115118 title: extracted? . embeddedTitle ?? url. deletingPathExtension ( ) . lastPathComponent,
119+ abstract: extracted? . abstract,
116120 doi: doi,
117121 arxivId: arxivId,
118122 fileHash: hash,
@@ -157,7 +161,11 @@ public struct ImportPipeline: Sendable {
157161 let hash = try store. ingest ( data: data)
158162 document. fileHash = hash
159163 document. fileName = name
160- fullText = PDFTextExtractor . extract ( from: store. url ( forHash: hash) ) ? . fullText
164+ let extracted = PDFTextExtractor . extract ( from: store. url ( forHash: hash) )
165+ fullText = extracted? . fullText
166+ if document. abstract? . isEmpty != false {
167+ document. abstract = extracted? . abstract
168+ }
161169 }
162170
163171 let details = try repository. insert (
@@ -172,8 +180,11 @@ public struct ImportPipeline: Sendable {
172180 var updated = document
173181 updated. fileHash = hash
174182 updated. fileName = url. lastPathComponent
175- let fullText = PDFTextExtractor . extract ( from: store. url ( forHash: hash) ) ? . fullText
176- return try repository. update ( updated, fullText: fullText)
183+ let extracted = PDFTextExtractor . extract ( from: store. url ( forHash: hash) )
184+ if updated. abstract? . isEmpty != false {
185+ updated. abstract = extracted? . abstract
186+ }
187+ return try repository. update ( updated, fullText: extracted? . fullText)
177188 }
178189
179190 /// Downloads and attaches an open-access PDF to an existing document.
@@ -187,8 +198,11 @@ public struct ImportPipeline: Sendable {
187198 var updated = document
188199 updated. fileHash = hash
189200 updated. fileName = name
190- let fullText = PDFTextExtractor . extract ( from: store. url ( forHash: hash) ) ? . fullText
191- return try repository. update ( updated, fullText: fullText)
201+ let extracted = PDFTextExtractor . extract ( from: store. url ( forHash: hash) )
202+ if updated. abstract? . isEmpty != false {
203+ updated. abstract = extracted? . abstract
204+ }
205+ return try repository. update ( updated, fullText: extracted? . fullText)
192206 }
193207
194208 /// Finds a downloadable PDF, preferring the arXiv copy and falling back to
@@ -215,11 +229,13 @@ public struct ImportPipeline: Sendable {
215229 if record == nil , let arxivId = document. arxivId {
216230 record = try ? await arXiv. resolve ( arxivId: arxivId)
217231 }
218- guard let record else { return nil }
219-
220232 var updated = document
221- record. apply ( to: & updated)
222- let authors = record. authors. isEmpty ? nil : record. authorRecords
233+ record? . apply ( to: & updated)
234+ if updated. abstract? . isEmpty != false , let hash = updated. fileHash {
235+ updated. abstract = PDFTextExtractor . extract ( from: store. url ( forHash: hash) ) ? . abstract
236+ }
237+ guard record != nil || updated. abstract != document. abstract else { return nil }
238+ let authors = record. flatMap { $0. authors. isEmpty ? nil : $0. authorRecords }
223239 return try repository. update ( updated, authors: authors)
224240 }
225241}
0 commit comments