FileDocCategorySizeDatePackage
ContentStrategy.javaAPI DocApache Lucene 2.1.07036Wed Feb 14 10:46:06 GMT 2007org.apache.lucene.gdata.search.analysis

ContentStrategy

public abstract class ContentStrategy extends Object
Creating Indexable document requires processing of incoming entities as GData Entries. Entries in the GData protocol might have very different structures and content. They all have on thing in common as they are atom xml format. To retrieve the configured elements of the atom format and process the actual content might differ from element to element.

Each predefined ContentStrategy can be used to retrieve certain content from the defined element. Which element to process is defined using a XPath expression in the gdata-config.xml file.

ContentStrategy implementation should not be accessed directly. To get a ContentStrategy for a specific {@link org.apache.lucene.gdata.search.config.IndexSchemaField.ContentType} use the {@link ContentStrategy#getFieldStrategy} factory method. This method expects a IndexSchemaField instance with a set ContentType. The return value is a new ContentStrategy instance for the defined ContentType.

see
org.apache.lucene.gdata.search.config.IndexSchemaField.ContentType
see
org.apache.lucene.gdata.search.index.IndexDocumentBuilder
author
Simon Willnauer

Fields Summary
protected final org.apache.lucene.document.Field.Store
store
protected final org.apache.lucene.document.Field.Index
index
protected final org.apache.lucene.gdata.search.config.IndexSchemaField
config
protected String
content
protected String
fieldName
Constructors Summary
protected ContentStrategy(org.apache.lucene.gdata.search.config.IndexSchemaField fieldConfiguration)

        this(null, null, fieldConfiguration);
    
protected ContentStrategy(org.apache.lucene.document.Field.Index index, org.apache.lucene.document.Field.Store store, org.apache.lucene.gdata.search.config.IndexSchemaField fieldConfig)

        if(fieldConfig == null)
            throw new IllegalArgumentException("IndexSchemaField must not be null");
        this.config = fieldConfig;
        this.fieldName = fieldConfig.getName();
        if (index != null) {
            this.index = index;
        } else {
            this.index = fieldConfig.getIndex() == null ? IndexSchemaField.DEFAULT_INDEX_STRATEGY
                    : fieldConfig.getIndex();
        }
        if (store != null) {
            this.store = store;
        } else {
            this.store = fieldConfig.getStore() == null ? IndexSchemaField.DEFAULT_STORE_STRATEGY
                    : fieldConfig.getStore();
        }

    
Methods Summary
public org.apache.lucene.document.Field[]createLuceneField()
This method creates a lucene field from the retrieved content of the entity. Values for Field.Index, Field.Store, the field name and the boost factor are configured in the IndexSchemaField passed by the constructor e.g the factory method. This method might be overwritten by subclasses.

return
the Lucene {@link Field}

        /*
         * should I test the content for being empty?!
         * does that make any difference if empty fields are indexed?!
         */
        if(this.fieldName==null|| this.content == null)
            throw new GdataIndexerException("Required field not set fieldName: "+this.fieldName+" content: "+this.content);
        if(this.content.length()==0){
            return new Field[0];
        }
        Field retValue = new Field(this.fieldName, this.content, this.store,
                this.index);
        float boost = this.config.getBoost();
        if (boost != 1.0f)
            retValue.setBoost(boost);
        return new Field[]{retValue};
        
    
public static org.apache.lucene.gdata.search.analysis.ContentStrategygetFieldStrategy(org.apache.lucene.gdata.search.config.IndexSchemaField fieldConfig)
This factory method creates the ContentStrategy corresponding to the set ContentType value in the IndexSchemaField passed to the method as the single parameter.

The ContentType must not be null

param
fieldConfig - the field config to use to identify the corresponding ContentStrategy
return
- a new ContentStrategy instance

        if (fieldConfig == null)
            throw new IllegalArgumentException(
                    "field configuration must not be null");
        ContentType type = fieldConfig.getContentType();
        if (type == null)
            throw new IllegalArgumentException(
                    "ContentType in IndexSchemaField must not be null");
        fieldConfig.getAnalyzerClass();

        switch (type) {
        case CATEGORY:
            return new GdataCategoryStrategy(fieldConfig);
        case HTML:
            return new HTMLStrategy(fieldConfig);
        case XHTML:
            return new XHtmlStrategy(fieldConfig);
        case GDATADATE:
            return new GdataDateStrategy(fieldConfig);
        case TEXT:
            return new PlainTextStrategy(fieldConfig);
        case KEYWORD:
            return new KeywordStrategy(fieldConfig);
        case CUSTOM:
            /*
             * check if this class can be created with default constructor is checked
             * in IndexSchemaField#setFieldClass and throws RuntimeEx if not. So
             * server can not start up.
             */
            return ReflectionUtils.getDefaultInstance(fieldConfig
                    .getFieldClass());
        case MIXED:
            return new MixedContentStrategy(fieldConfig);
        default:
            throw new RuntimeException("No content strategy found for " + type);
        }

    
public abstract voidprocessIndexable(Indexable indexable)

param
indexable
throws
NotIndexableException