This documentation is for WSO2 API Manager 1.7.0 View documentation for the latest release.
Adding Apache Solr-Based Indexing - API Manager 1.7.0 - WSO2 Documentation

All docs This doc
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

The API Manager has Apache Solr based indexing for API documentation content. It provides both the API Publisher and Store full-text search facility to search through API documentation, find documents and related APIs. The search syntax is doc:keyword. Search criteria looks for the keyword in any word/phrase in the documentation content and returns both the matching documents and associated APIs.

Configuring the index

The following media types have Apache Solr based indexers by default, configured using the <Indexers> element in <APIM_HOME>/repository/conf/registry.xml.

  • Text : text/plain
  • PDF : application/pdf
  • MS word : application/msword
  • MS Powerpoint : application/vnd.ms-powerpoint
  • MS Excel : application/vnd.ms-excel
  • XML : application/xml

In addition to the default ones, you can write your own indexer implementation and register it. When a new resource is added to the registry with the relevant media type in an indexer, the content is indexed using that. Given below is a sample indexer code:

package org.wso2.indexing.sample;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Arrays;
import org.apache.solr.common.SolrException;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.utils.RegistryUtils;
import org.wso2.carbon.registry.indexing.IndexingConstants;
import org.wso2.carbon.registry.indexing.AsyncIndexer.File2Index;
import org.wso2.carbon.registry.indexing.indexer.Indexer;
import org.wso2.carbon.registry.indexing.solr.IndexDocument;

public class PlainTextIndexer implements Indexer {
    public IndexDocument getIndexedDocument(File2Index fileData) throws SolrException,
            RegistryException {
             
             /* Create index document with resource path and raw content*/
             IndexDocument indexDoc = new IndexDocument(fileData.path, RegistryUtils.decodeBytes(fileData.data), null);
             
             /* You can specify required field/value pairs for this indexing document.
              * When searching we can query on these fields  */
             Map<String, List<String>> fields = new HashMap<String, List<String>>();
             fields.put("path", Arrays.asList(fileData.path));
                                     
             if (fileData.mediaType != null) {
                         fields.put(IndexingConstants.FIELD_MEDIA_TYPE, Arrays.asList(fileData.mediaType));
             } else {
                         fields.put(IndexingConstants.FIELD_MEDIA_TYPE, Arrays.asList("text/plain"));
             }
             
             /* set fields for index document*/
             indexDoc.setFields(fields);             
             return indexDoc;
    }    
}

 

 

 

 

 

 

Writing custom indexer

 

 

 

Sample Indexer Code. (Refer complete source sample-indexer.zip)

 

 

 

 

1. You can write the custom indexer and include the relevant jar file to APIM_HOME/repository/components/lib directory.

 

2. Then add the new indexer to APIM_HOME/repository/conf/registry.xml under <Indexers>

 

ex:

 

<indexer class="org.wso2.indexing.sample.PlainTextIndexer" mediaTypeRegEx="text/plain" profiles ="default,api-store,api-publisher"/>

 

 

class

indexer class name

 

mefiaTypeRegEx

A regex pattern to match media type

 

profiles

APIM profiles in which indexer should be available

 

 

3. restart the server

 

4. Now if you add an API documentation from the newly added media type, it will be indexed and you will be able to search for content using ‘doc’ search term.

  • No labels