Skip to content

XPathFilter: skip blank values and try the next expression - #2258

Merged
jnioche merged 1 commit into
mainfrom
xpathfilter-skip-blank
Oct 24, 2026
Merged

jnioche merged 1 commit into
mainfrom
xpathfilter-skip-blank

Conversation

@jnioche

@jnioche jnioche commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Follow-up to the review comment #2256 (comment), kept separate from #2256.

Problem

Both XPathFilter implementations in core keep the first expression that matches for a key:

  • org.apache.stormcrawler.jsoup.XPathFilter, used by the JSoupFilters
  • org.apache.stormcrawler.parse.filter.XPathFilter, used by the ParseFilters

They keep it even when its value is empty or whitespace-only. With the usual configuration for parse.title (//TITLE first, then a META fallback), a page with an empty <title> gets an empty parse.title, and the fallback never runs. This already happens with HTML pages. It will be more common once #2256 runs the JSoupFilters on documents parsed by Tika, because Tika always writes a <title> element, even for an untitled PDF.

Change

  • Blank values are dropped. If an expression gives only blank values, the next expression for that key is tried.
  • If every expression for a key gives a blank value, nothing is stored for that key.

Behaviour change

Blank values are no longer stored at all, even next to non-blank ones. For example, //SCRIPT[@type='text/javascript'] on the test page used to return two values: an empty one for the external <script src=...> and the inline script. It now returns only the inline script. testScriptExtraction in both test classes is updated to match.

Tests

New tests in JSoupFiltersTest and XPathFilterTest:

  • A page with an empty <title> and a <meta name="title"> fallback stores the fallback.
  • A page where every expression gives a blank value stores nothing.

mvn -pl core test -Dtest='XPathFilterTest,JSoupFiltersTest': 18 tests, all pass. Without the change to the filters, the new tests fail.

🤖 Generated with Claude Code

Both XPathFilter implementations (JSoup and DOM) kept the first expression
that matched for a key, even when its value was empty or whitespace-only.
An empty <title> therefore stopped the META fallback for parse.title and
stored an empty title. Blank values are now dropped; when an expression
only gives blank values, the next expression for that key is tried, and
nothing is stored if they are all blank.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rzo1 rzo1 added this to the 4.0.0 milestone Oct 23, 2026
@rzo1

rzo1 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

lgtm, thx.

@jnioche
jnioche merged commit 55b2d83 into main Oct 24, 2026
2 checks passed
@jnioche
jnioche deleted the xpathfilter-skip-blank branch October 24, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants