Upgrade to Tika 4.0.0 - #2118
Open
abhinav-phi wants to merge 1 commit into
Open
Conversation
Closes apache#2063 Tika 4.0.0 requires several API and configuration changes: - core: TikaConfig has been removed - JSoupParserBolt now uses DefaultDetector for mime type detection; Detector.detect takes a TikaInputStream and a ParseContext; the CONTENT_TYPE and CONTENT_LENGTH constants moved from Metadata to HttpHeaders. - external/tika: ParserBolt loads configurations with TikaLoader (tika-serialization) since XML configurations are no longer supported, and the bundled tika-config.xml has been migrated to JSON. Config resources bundled in a jar are copied to a temporary file as TikaLoader reads configs from the filesystem only. - external/tika: tika-parsers-standard-package is now a POM aggregating the individual parser modules and is consumed as such. - the default value of parser.tika.config.file is now tika-config.json - THIRD-PARTY.txt regenerated
Contributor
|
From my 🤖 One area where the bot is wrong is that configurations around timeouts don't affect us because we aren't using tika pipes (we on Tika need to improve our documentation around that). If you want process isolation and want to avoid a couple of PDFs infinitely looping on a node and/or OOM'ing it, consider the |
Contributor
|
Other subtlety, and we should have a unit test for this is that I think we should invert this to put in the |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upgrade to Apache Tika 4.0.0 — Closes #2063
This PR upgrades StormCrawler from Tika 3.3.2 to the first stable release of the Tika 4.x line (announcement), tracking the 4.0.0 milestone. Tika 4.0 ships a number of breaking changes; this PR migrates the codebase, the bundled configuration and the documentation accordingly. No behaviour change is intended for users of the
JSoupParserBoltand the TikaParserBoltbeyond the Tika upgrade itself.Dependency changes
tika.version3.3.2→4.0.0in the root POM. Tika 4.x requires Java 17+, which StormCrawler already targets (the project builds on JDK 17-25, CI runs JDK 25), so no compiler settings were needed.tika-parsers-standard-packagechanged from a jar to a POM that aggregates the individualtika-parser-*-moduleartifacts.external/tikanow consumes it with<type>pom</type>, which pulls in all standard parser modules transitively — same effective set of parsers as before, including the OCR module.tika-coreandtika-serializationdependencies toexternal/tika:tika-serializationprovides the newTikaLoaderused to read the JSON configuration (see below). The existing exclusions (asm,slf4j-log4j12, and the BSD-licensedjai-imageio-core, still a compile dependency of the image parser module) are preserved.THIRD-PARTY.txtregenerated withlicense:aggregate-add-third-party(Tika modules now 4.0.0; new Tika artifacts:tika-serialization,tika-encoding-detector-html,tika-encoding-detector-mojibuster,tika-ml-core,tika-ml-junkdetect,tika-parser-datauri-commons; removals:tika-parsers-standard-packagejar,vorbis-java-tika, POIpoi-ooxml-full, PDFBoxjempbox/xmpbox3.0.8,org.tukaani:xz— replaced by Tika 4's internal dependencies).Code migration
core/JSoupParserBolt.java(only core module using Tika, viatika-core):TikaConfigwas removed in Tika 4. The mime-type detector, previously obtained fromTikaConfig.getDefaultConfig().getDetector(), is now built withnew DefaultDetector(), which is exactly what the removed default configuration wired (bytecode of Tika 4'sTika()facade confirms it constructsnew DefaultDetector()).Detector.detect()now takes(TikaInputStream, Metadata, ParseContext);guessMimeType()wraps the content bytes withTikaInputStream.get(content)and passes an emptyParseContext.Metadatano longer implementsHttpHeaders, so theMetadata.CONTENT_TYPE/Metadata.CONTENT_LENGTHconstants are now taken fromorg.apache.http.HttpHeaders. Code referencingTikaCorePropertiesconstants is unaffected (theRESOURCE_NAME_KEYusage stays).external/tika/ParserBolt.java:instantiateTika()now loads the configuration throughTikaLoader.load(path, classLoader)(from the newtika-serializationmodule) and wires the result into theTikafacade vianew Tika(loader.loadDetectors(), loader.loadAutoDetectParser())— the equivalent of the removednew TikaConfig(url, classLoader)+new Tika(tikaConfig)pair. On failure the bolt still falls back to the default configuration.TikaLoadercan only read configuration files from the filesystem. When the configuration is bundled inside a jar (the common case for topologies built as fat jars),urlToPath()copies it to a temporary file first.TikaInputStream.get(content)in a try-with-resources block, replacing the manualByteArrayInputStream+finallyclose (Tika 4'sParser.parse()requires aTikaInputStream, andTikaInputStreamholdsTemporaryResourcesthat must be released).parser.tika.config.fileis nowtika-config.json.Configuration migration
external/tika/src/main/resources/tika-config.xml→tika-config.json. The old XML only (a) excludedTesseractOCRParserfromDefaultParserand (b) setservice-loaderwarning handlers, which are the Tika 4 defaults. Using Tika's ownXmlToJsonConfigConvertersemantics, this becomes:{ "parsers": [ { "default-parser": { "exclude": ["tesseract-ocr-parser"] } } ] }(OCR stays disabled by default in StormCrawler — Tesseract is an optional native dependency.)
Archetype
crawler-conf.yamlfiles (core, OpenSearch, Solr) updated toparse.tika.config.file: "tika-config.json".Documentation
external/tika/README.mdanddocs/configuration.adocupdated for the JSON configuration and the new default file name.Testing
mvn verifywithCI_ENV=true:stormcrawler-core: 415 tests, 0 failures (includesJSoupParserBoltTestmime-type detection).stormcrawler-tika: ParserBoltTest green — parses a recursive embedded.docx(TIKA-2096 scenario) through the newTikaLoader/JSON-config path, and exercises the mime-type whitelist.stormcrawler-urlfrontier,stormcrawler-langid, archetypes, docs: green.-Prat -DskipTests verify -Dskip.format.code=false(CI's license + format job): the newtika-config.jsonis approved by RAT; google-java-format validation passes on all touched Java files.mainand unrelated to this change:HttpRobotRulesParserRedirectTest(WireMock cannot bind port 8089 on Windows) andWARCHdfsBoltTest(Hadoop requireswinutils.exeon Windows); Testcontainers-based tests (OpenSearch/Solr/SQL) require Docker, unavailable locally. CI runs on Ubuntu with Docker where these all pass.Notes for reviewers
tk:prefix) only affect keys emitted by parsers, which this bolt copies with aparse.prefix into StormCrawler metadata. Users with ParseFilters/indexing rules matching specificparse.*Tika keys may be affected by the renames; the upstream migration guide documents an opt-in legacy-key filter (metadata-migration-3x-4x.json) for that case.JSoupParserBolt; the "default content handler is now Markdown" change does not affect StormCrawler, which always supplies its ownBodyContentHandler/LinkContentHandler.