krickert commented on code in PR #2921: URL: https://github.com/apache/tika/pull/2921#discussion_r3538982722
########## tika-grpc-mapper/src/main/java/org/apache/tika/grpc/mapper/transform/PdfDocumentTransformer.java: ########## @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tika.grpc.mapper.transform; + +import java.util.Locale; +import java.util.Set; + +import org.apache.tika.grpc.v1.Document; +import org.apache.tika.grpc.v1.DocumentMetadata; +import org.apache.tika.metadata.Metadata; +import org.apache.tika.metadata.Office; +import org.apache.tika.metadata.PagedText; +import org.apache.tika.metadata.TikaCoreProperties; + +/** + * PDF. Maps the common, cross-format facts into typed DocumentMetadata. + * + * PDF-specific properties (encryption flags, XMP, permissions, incremental updates, ...) + * are NOT given their own proto fields. They flow into the tagged tail, typed where Tika + * declares the type and string otherwise. That is the whole point: format richness lives + * in code plus the tail, not in the wire contract - so the schema stays small and stable + * and clients never rebuild when we add or change a PDF property. + */ +public final class PdfDocumentTransformer implements DocumentTransformer { + + @Override + public boolean appliesTo(Metadata tika) { + String contentType = tika.get(Metadata.CONTENT_TYPE); + return contentType != null && contentType.toLowerCase(Locale.ROOT).contains("pdf"); + } + + @Override + public void transform(Metadata tika, Document.Builder document, Set<String> consumed) { + DocumentMetadata.Builder meta = document.getMetadataBuilder(); + + // Common, cross-format fields -> typed (a date is a Timestamp, a count is an int). + TransformSupport.setString(tika, TikaCoreProperties.TITLE, meta::setTitle, consumed); Review Comment: Done. Factored into `TransformSupport.mapCommonFields(tika, meta, consumed)`, with an overload taking the keywords `Property` since Office/RTF use `Office.KEYWORDS` instead of `TikaCoreProperties.SUBJECT`. Six transformers now call it. `ImageDocumentTransformer` intentionally doesn't (its fields come from IPTC/EXIF, not the core properties) and has a comment saying so. ########## tika-grpc/src/main/java/org/apache/tika/pipes/grpc/TikaGrpcServerImpl.java: ########## @@ -312,16 +318,21 @@ private void fetchAndParseImpl(FetchAndParseRequest request, if (pipesResult.status().equals(PipesResult.RESULT_STATUS.FETCH_EXCEPTION)) { fetchReplyBuilder.setErrorMessage(pipesResult.message()); } + long parseTimeMs = (System.nanoTime() - parseStart) / 1_000_000L; Review Comment: Went with the rename, since fetch and parse happen together inside the forked pipes worker and aren't separable from the server's vantage point. The proto field is now `fetch_parse_time_ms` with a comment spelling out what's measured, and the server/mapper/tests are renamed to match. Safe to rename rather than reserve the tag since nothing has shipped with this proto yet. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
