5.5. Integrating a Different Search Engine

This section describes the necessary steps to make the CAE Feeder feed content bean data to a different search engine or another external system. The default integration uses Apache Solr but the CAE Feeder provides an Indexer interface that can be implemented to feed other external systems such as a search engine that is integrated in your company's IT infrastructure.

The following simple example explains how you can replace the standard Apache Solr indexer with a custom indexer that just writes messages to the log file.

  1. Create a new Maven module, for example caefeeder-custom-component with the following pom.xml:

      <?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">
  <parent>
    ...
  </parent>

  <modelVersion>4.0.0</modelVersion>
  <artifactId>caefeeder-custom-component</artifactId>

  <dependencies>
    <dependency>
      <groupId>com.coremedia.cms</groupId>
      <artifactId>caefeeder-base-component</artifactId>
      <scope>runtime</scope>
    </dependency>

    <dependency>
      <groupId>com.coremedia.cms</groupId>
      <artifactId>cap-search-api</artifactId>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>

  </dependencies>
</project>

    

  1. Create a new source folder src/main/java in the module.

  2. Create the java class LogIndexer for the new indexer in package com/customer:

      package com.customer;
 
import com.coremedia.cap.feeder.Feedable;
import com.coremedia.cap.feeder.FeedableElement;
import com.coremedia.cap.feeder.index.IndexException;
import com.coremedia.cap.feeder.index.IndexerResult;
import com.coremedia.cap.feeder.index.direct.DirectIndexerBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
 
public class LogIndexer extends DirectIndexerBase {
  private static final Logger LOG 
    = LoggerFactory.getLogger(LogIndexer.class);
  
  public IndexerResult index(
      Collection<? extends Feedable> feedables, 
      Collection<String> removeIds) throws IndexException {
 
    if (LOG.isInfoEnabled()) {
      for (Feedable feedable: feedables) {
        Collection<FeedableElement> elements
          = feedable.getElements();
        Map<String, Object> values
          = new HashMap<>(elements.size());
        for (FeedableElement element: elements) {
          values.put(element.getName(), element.getValue());
        }
        LOG.info("Updating {} with {}", 
          feedable.getId(), values);
      }
      if (!removeIds.isEmpty()) {
        LOG.info("Removing {}", removeIds);
      }
    }
    return IndexerResult.persisted();
  }
 
  public String getDocumentInfo(String s) throws IndexException {
    return null;
  }
}


    
  1. Create a new source folder src/main/resources/META-INF/coremedia in the module.

  2. Create a Spring configuration file for the component named component-caefeeder-custom.xml in this folder

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
">
 
  <bean id="feederIndexer" class="com.customer.LogIndexer"/>
</beans>
  1. In the file pom.xml of the CAE Feeder web application replace the dependency on caefeeder-solr-component with a dependency to your new component: caefeeder-custom-component.

  1. Add a corresponding logger to the logback configuration of the CAE Feeder web application.

<logger name="com.customer" additivity="false" level="debug">
<appender-ref ref="file"/>
</logger>