FileDocCategorySizeDatePackage
IndexSchema.javaAPI DocApache Lucene 2.1.015639Wed Feb 14 10:46:06 GMT 2007org.apache.lucene.gdata.search.config

IndexSchema

public class IndexSchema extends Object
This class is used to configure the indexing and search component. Each service on the GData server will have an own search index. For this purpose one single index schema will be configured in the gdata-config.xml file. This file will be mapped on this class on startup.

This class breaks some encapsulation of general java classes to be configurable via the xml configuration file. The will be very less type and value checking of the properties inside this file. Mandatory values must be set in the configuration file. The server won't start up if these values are missing. See definition in the xml schema file. If this class is instantiated manually the value for the name of the schema should be set before this is passed to the IndexController.

One IndexSchema consists of multiple instances of {@link org.apache.lucene.gdata.search.config.IndexSchemaField} each of this instances describes a single field in the index and all schema informations about the field.

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

Fields Summary
private final Set
searchableFieldNames
private static final Log
LOG
public static final int
NOT_SET_VALUE
a static final value for properties are not set by the configuration file this value will be set to all long and int properties by default
private static final int
DEFAULT_OPTIMIZE_COUNT
private static final int
DEFAULT_COMMIT_COUNT
private String
indexLocation
private String
name
private boolean
useTimedIndexer
private long
indexerIdleTime
private Analyzer
serviceAnalyzer
private String
defaultSearchField
private PerFieldAnalyzerWrapper
perFieldAnalyzer
private Collection
schemaFields
private int
maxBufferedDocs
private int
maxMergeDocs
private int
mergeFactor
private int
maxFieldLength
private long
writeLockTimeout
private long
commitLockTimeout
private int
commitAfterDocuments
private int
optimizeAfterCommit
private boolean
useCompoundFile
Constructors Summary
public IndexSchema()
Creates a new IndexSchema and initialize the standard service analyzer to {@link StandardAnalyzer}


                       
      
        this.schemaFields = new ArrayList<IndexSchemaField>();
        /*
         * keep as standard if omitted in the configuration
         */
        this.serviceAnalyzer = new StandardAnalyzer();

    
Methods Summary
public voidaddSchemaField(IndexSchemaField field)
Adds a new {@link IndexSchemaField} to the schema. if the fields name equals {@link IndexDocument#FIELD_ENTRY_ID} or the field is null it will simply ignored

param
field - the index schema field to add as a field of this schema.

        if (field == null)
            return;
        /*
         * skip fields configured in the gdata-config.xml file if their names
         * match a primary key field id of the IndexDocument
         */
        if (field.getName().equals(IndexDocument.FIELD_ENTRY_ID)
                || field.getName().equals(IndexDocument.FIELD_FEED_ID))
            return;
        if (field.getAnalyzerClass() != null) {
            /*
             * enable per field analyzer if one is set.
             */
            Analyzer analyzer = getAnalyzerInstance(field.getAnalyzerClass());
            /*
             * null values will be omitted here
             */
            buildPerFieldAnalyzerWrapper(analyzer, field.getName());
        }
        this.schemaFields.add(field);
        this.searchableFieldNames.add(field.getName());
    
private voidbuildPerFieldAnalyzerWrapper(org.apache.lucene.analysis.Analyzer anazlyer, java.lang.String field)

        if (anazlyer == null || field == null || field.length() == 0)
            return;
        if (this.perFieldAnalyzer == null)
            this.perFieldAnalyzer = new PerFieldAnalyzerWrapper(
                    this.serviceAnalyzer);
        this.perFieldAnalyzer.addAnalyzer(field, anazlyer);
    
public booleanequals(java.lang.Object object)

see
java.lang.Object#equals(java.lang.Object)

        if (this == object)
            return true;
        if (object == null)
            return false;
        if (object instanceof IndexSchema) {
           if(this.name ==null)
               return super.equals(object);
            return this.name.equals(((IndexSchema) object).getName());
        }
        return false;
    
private static org.apache.lucene.analysis.AnalyzergetAnalyzerInstance(java.lang.Class clazz)

        if (!ReflectionUtils.extendsType(clazz, Analyzer.class)) {
            LOG.warn("Can not create analyzer for class " + clazz.getName());
            return null;
        }
        try {
            return clazz.newInstance();
        } catch (Exception e) {
            LOG.warn("Can not create analyzer for class " + clazz.getName());
        }
        return null;
    
public intgetCommitAfterDocuments()
Defines after how many added,removed or updated document the indexer should commit.

return
Returns the commitAfterDocuments.

        return this.commitAfterDocuments;
    
public longgetCommitLockTimeout()

return
Returns the commitLockTimout.

        return this.commitLockTimeout;
    
public java.lang.StringgetDefaultSearchField()

return
Returns the defaultField.

        return this.defaultSearchField;
    
public java.util.CollectiongetFields()

return
Returns the fieldConfiguration.

        return this.schemaFields;
    
public java.lang.StringgetIndexLocation()

return
Returns the indexLocation.

        return this.indexLocation;
    
public longgetIndexerIdleTime()

return
Returns the indexerIdleTime.

        return this.indexerIdleTime;
    
public intgetMaxBufferedDocs()

return
Returns the maxBufferedDocs.


        return this.maxBufferedDocs;
    
public intgetMaxFieldLength()

return
Returns the maxFieldLength.

        return this.maxFieldLength;
    
public intgetMaxMergeDocs()

return
Returns the maxMergeDocs.

        return this.maxMergeDocs;
    
public intgetMergeFactor()

return
Returns the mergeFactor.

        return this.mergeFactor;
    
public java.lang.StringgetName()

return
Returns the name.

        return this.name;
    
public intgetOptimizeAfterCommit()
Defines after how many commits the indexer should optimize the index

return
Returns the optimizeAfterCommit.

        
        return this.optimizeAfterCommit;
    
public org.apache.lucene.analysis.AnalyzergetSchemaAnalyzer()

return
- the analyzer instance to be used for this schema

        if (this.perFieldAnalyzer == null)
            return this.serviceAnalyzer;
        return this.perFieldAnalyzer;
    
public java.util.SetgetSearchableFieldNames()

return
Returns the searchableFieldNames.

        return this.searchableFieldNames;
    
public org.apache.lucene.analysis.AnalyzergetServiceAnalyzer()

return
Returns the serviceAnalyzer.

        return this.serviceAnalyzer;
    
public longgetWriteLockTimeout()

return
Returns the writeLockTimeout.

        return this.writeLockTimeout;
    
public inthashCode()

see
java.lang.Object#hashCode()

        if (this.name == null)
            return super.hashCode();
        return this.name.hashCode();
    
public voidinitialize()
Initialize the schema and checks all required values

        for (IndexSchemaField field : this.schemaFields) {
            if (!field.checkRequieredValues())
                throw new RuntimeException("Required Value for field: "
                        + field.getName() + " is missing");
        }
        if (this.defaultSearchField == null)
            throw new RuntimeException("DefaulSearchField must not be null");
        if (this.name == null)
            throw new RuntimeException(
                    "Schema field is not set -- must not be null");
        if (this.indexLocation == null)
            throw new RuntimeException("IndexLocation must not be null");
        if(!this.searchableFieldNames.contains(this.defaultSearchField)){
            throw new RuntimeException("the default search field: "+this.defaultSearchField+" is registered as a field");
        }

    
public booleanisUseCompoundFile()

return
Returns the useCompoundFile.

        return this.useCompoundFile;
    
public booleanisUseTimedIndexer()

return
Returns the useTimedIndexer.

        return this.useTimedIndexer;
    
public voidsetCommitAfterDocuments(int commitAfterDocuments)

param
commitAfterDocuments The commitAfterDocuments to set.

        if(commitAfterDocuments < DEFAULT_COMMIT_COUNT)
            return;
        this.commitAfterDocuments = commitAfterDocuments;
    
public voidsetCommitLockTimeout(long commitLockTimeout)

param
commitLockTimeout The commitLockTimeout to set.

        // TODO enable this in config
        this.commitLockTimeout = commitLockTimeout;
    
public voidsetDefaultSearchField(java.lang.String defaultField)

param
defaultField The defaultField to set.

        this.defaultSearchField = defaultField;
    
public voidsetIndexLocation(java.lang.String indexLocation)

param
indexLocation The indexLocation to set.

        this.indexLocation = indexLocation;
    
public voidsetIndexerIdleTime(long indexerIdleTime)

param
indexerIdleTime The indexerIdleTime to set.

        this.indexerIdleTime = indexerIdleTime;
    
public voidsetMaxBufferedDocs(int maxBufferedDocs)

param
maxBufferedDocs The maxBufferedDocs to set.

        this.maxBufferedDocs = maxBufferedDocs;
    
public voidsetMaxFieldLength(int maxFieldLength)

param
maxFieldLength The maxFieldLength to set.

        this.maxFieldLength = maxFieldLength;
    
public voidsetMaxMergeDocs(int maxMergeDocs)

param
maxMergeDocs The maxMergeDocs to set.

        this.maxMergeDocs = maxMergeDocs;
    
public voidsetMergeFactor(int mergeFactor)

param
mergeFactor The mergeFactor to set.

        this.mergeFactor = mergeFactor;
    
public voidsetName(java.lang.String name)

param
name The name to set.

        this.name = name;
    
public voidsetOptimizeAfterCommit(int optimizeAfterCommit)

param
optimizeAfterCommit The optimizeAfterCommit to set.

        if(optimizeAfterCommit < DEFAULT_OPTIMIZE_COUNT )
            return;
        this.optimizeAfterCommit = optimizeAfterCommit;
    
public voidsetSchemaFields(java.util.Collection fields)

param
fields The fieldConfiguration to set.

        this.schemaFields = fields;
    
public voidsetServiceAnalyzer(org.apache.lucene.analysis.Analyzer serviceAnalyzer)

param
serviceAnalyzer The serviceAnalyzer to set.

        if (serviceAnalyzer == null)
            return;
        this.serviceAnalyzer = serviceAnalyzer;

    
public voidsetUseCompoundFile(boolean useCompoundFile)

param
useCompoundFile The useCompoundFile to set.

        this.useCompoundFile = useCompoundFile;
    
public voidsetUseTimedIndexer(boolean useTimedIndexer)

param
useTimedIndexer The useTimedIndexer to set.

        this.useTimedIndexer = useTimedIndexer;
    
public voidsetWriteLockTimeout(long writeLockTimeout)

param
writeLockTimeout The writeLockTimeout to set.

        this.writeLockTimeout = writeLockTimeout;
    
public java.lang.StringtoString()

see
java.lang.Object#toString()

        StringBuilder builder = new StringBuilder(this.getClass().getName())
                .append(" ");
        builder.append("Name: ").append(this.name).append(" ");
        builder.append("MaxBufferedDocs: ").append(this.maxBufferedDocs)
                .append(" ");
        builder.append("MaxFieldLength: ").append(this.maxFieldLength).append(
                " ");
        builder.append("MaxMergeDocs: ").append(this.maxMergeDocs).append(" ");
        builder.append("MergeFactor: ").append(this.mergeFactor).append(" ");
        builder.append("CommitLockTimeout: ").append(this.commitLockTimeout)
                .append(" ");
        builder.append("WriteLockTimeout: ").append(this.writeLockTimeout)
                .append(" ");
        builder.append("indexerIdleTime: ").append(this.indexerIdleTime)
                .append(" ");
        builder.append("useCompoundFile: ").append(this.useCompoundFile)
                .append(" ");
        builder.append("Added SchemaField instances: ").append(
                this.schemaFields.size()).append(" ");

        builder.append("IndexLocation: ").append(this.indexLocation)
                .append(" ");
        return builder.toString();