Skip to content
Snippets Groups Projects
Commit e9f8d968 authored by Julien's avatar Julien
Browse files

Template commit

parent e7b7d231
No related branches found
No related tags found
No related merge requests found
/target/
/.classpath
/.project
/.settings/
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.francelabs.datafari</groupId>
<artifactId>CustomUpdateProcessor</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<solr.version>7.4.0</solr.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solr.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>${solr.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<excludeScope>provided</excludeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
/*******************************************************************************
/*******************************************************************************
* * Copyright 2020 France Labs
* *
* * Licensed 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 com.francelabs.datafari.updateprocessor;
import java.io.IOException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.update.AddUpdateCommand;
import org.apache.solr.update.processor.UpdateRequestProcessor;
public class ReplaceUrlUpdateProcessor extends UpdateRequestProcessor {
private final String SOURCE_FIELD_PARAM = "source.field";
private final String sourceField;
public ReplaceUrlUpdateProcessor(final SolrParams params, final UpdateRequestProcessor next) {
super(next);
// Try to retrieve the parameter "source.field"
if (params != null) {
sourceField = params.get(SOURCE_FIELD_PARAM, "");
} else {
sourceField = "";
}
}
@Override
public void processAdd(final AddUpdateCommand cmd) throws IOException {
final SolrInputDocument doc = cmd.getSolrInputDocument();
// If the sourceField parameter is set and that the doc contains it, extract its value and replace the url field value by this one
if (sourceField != null && !sourceField.isEmpty() && doc.containsKey(sourceField) && doc.getFieldValue(sourceField) != null && !doc.getFieldValue(sourceField).toString().isEmpty()) {
doc.remove("url");
final String newUrl = doc.getFieldValue(sourceField).toString();
doc.addField("url", newUrl);
}
super.processAdd(cmd);
}
}
/*******************************************************************************
* * Copyright 2020 France Labs
* *
* * Licensed 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 com.francelabs.datafari.updateprocessor;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
public class ReplaceUrlUpdateProcessorFactory extends UpdateRequestProcessorFactory {
private SolrParams params = null;
@Override
public void init(final NamedList args) {
// Retrieve the parameters if any
if (args != null) {
params = args.toSolrParams();
}
}
@Override
public UpdateRequestProcessor getInstance(final SolrQueryRequest req, final SolrQueryResponse rsp, final UpdateRequestProcessor next) {
// Pass the parameters retrieved in the init (if any) to the update processor
return new ReplaceUrlUpdateProcessor(params, next);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment