Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1475 -- Regular crawling should work when autodiscovery of sitemaps is turned off #1477

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
*/
package org.apache.stormcrawler.filtering.sitemap;

import com.fasterxml.jackson.databind.JsonNode;
import java.net.URL;
import java.util.Map;
import org.apache.stormcrawler.Metadata;
import org.apache.stormcrawler.bolt.SiteMapParserBolt;
import org.apache.stormcrawler.filtering.URLFilter;
import org.apache.stormcrawler.util.ConfUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -35,22 +38,50 @@
* }
* </pre>
*
* Will be replaced by <a href=
* <p>Will be replaced by <a href=
* "https://github.com/apache/incubator-stormcrawler/issues/711">MetadataFilter to filter based on
* multiple key values</a>
*
* @since 1.14
*/
public class SitemapFilter extends URLFilter {

private static final String SITEMAP_DISCOVERY_PARAM_KEY = "sitemap.discovery";

private boolean sitemapsAutoDiscovery = false;

@Override
public void configure(
@NotNull Map<String, Object> stormConf,
@NotNull JsonNode filtersConf,
@NotNull String name) {
super.configure(stormConf, filtersConf);
sitemapsAutoDiscovery = ConfUtils.getBoolean(stormConf, SITEMAP_DISCOVERY_PARAM_KEY, false);
}

@Override
public @Nullable String filter(
@Nullable URL sourceUrl,
@Nullable Metadata sourceMetadata,
@NotNull String urlToFilter) {
if (sourceMetadata == null) {
return urlToFilter;
}
boolean smautodisco = false;
// check in the metadata if discovery setting has been
// overridden
String localSitemapDiscoveryVal = sourceMetadata.getFirstValue(SITEMAP_DISCOVERY_PARAM_KEY);

if (sourceMetadata != null
&& !Boolean.parseBoolean(
if ("true".equalsIgnoreCase(localSitemapDiscoveryVal)) {
smautodisco = true;
} else if ("false".equalsIgnoreCase(localSitemapDiscoveryVal)) {
smautodisco = false;
} else {
smautodisco = sitemapsAutoDiscovery;
}
if (!smautodisco) {
return urlToFilter;
} else if (!Boolean.parseBoolean(
sourceMetadata.getFirstValue(SiteMapParserBolt.isSitemapKey))
&& Boolean.parseBoolean(
sourceMetadata.getFirstValue(SiteMapParserBolt.foundSitemapKey))) {
Expand Down