org.apache.solr.schema
Class FieldType

java.lang.Object
  extended by org.apache.solr.schema.FieldType
Direct Known Subclasses:
BCDIntField, BoolField, CompressableField, DateField, DoubleField, FloatField, IntField, LongField, SortableDoubleField, SortableFloatField, SortableIntField, SortableLongField

public abstract class FieldType
extends java.lang.Object

Base class for all field types used by an index schema.

Version:
$Id: FieldType.java 542679 2007-05-29 22:28:21Z ryan $
Author:
yonik

Nested Class Summary
protected  class FieldType.DefaultAnalyzer
          Default analyzer for types that only produce 1 verbatim token...
 
Field Summary
protected  org.apache.lucene.analysis.Analyzer analyzer
          Analyzer set by schema for text types to use when indexing fields of this type, subclasses can set analyzer themselves or override getAnalyzer()
protected  java.util.Map<java.lang.String,java.lang.String> args
          additional arguments specified in the field type declaration
protected  int falseProperties
          properties explicitly set to false
static java.util.logging.Logger log
           
protected  org.apache.lucene.analysis.Analyzer queryAnalyzer
          Analyzer set by schema for text types to use when searching fields of this type, subclasses can set analyzer themselves or override getAnalyzer()
protected  int trueProperties
          properties explicitly set to true
protected  java.lang.String typeName
          The name of the type (not the name of the field)
 
Constructor Summary
FieldType()
           
 
Method Summary
 org.apache.lucene.document.Field createField(SchemaField field, java.lang.String externalVal, float boost)
          Used for adding a document when a field needs to be created from a type and a string.
 org.apache.lucene.analysis.Analyzer getAnalyzer()
          Returns the Analyzer to be used when indexing fields of this type.
protected  org.apache.lucene.document.Field.Index getFieldIndex(SchemaField field, java.lang.String internalVal)
           
protected  org.apache.lucene.document.Field.Store getFieldStore(SchemaField field, java.lang.String internalVal)
           
protected  org.apache.lucene.document.Field.TermVector getFieldTermVec(SchemaField field, java.lang.String internalVal)
           
 org.apache.lucene.analysis.Analyzer getQueryAnalyzer()
          Returns the Analyzer to be used when searching fields of this type.
abstract  org.apache.lucene.search.SortField getSortField(SchemaField field, boolean top)
          Returns the SortField instance that should be used to sort fields of this type.
protected  org.apache.lucene.search.SortField getStringSort(SchemaField field, boolean reverse)
          Utility usable by subclasses when they want to get basic String sorting.
 java.lang.String getTypeName()
          The Name of this FieldType as specified in the schema file
 ValueSource getValueSource(SchemaField field)
          called to get the default value source (normally, from the Lucene FieldCache.)
 java.lang.String indexedToReadable(java.lang.String indexedForm)
          :TODO: document this method
protected  void init(IndexSchema schema, java.util.Map<java.lang.String,java.lang.String> args)
          subclasses should initialize themselves with the args provided and remove valid arguments.
 boolean isTokenized()
          Returns true if fields of this type should be tokenized
protected  void restrictProps(int props)
          :TODO: document this method
 void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
          Sets the Analyzer to be used when indexing fields of this type.
 void setQueryAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
          Sets the Analyzer to be used when querying fields of this type.
 java.lang.String storedToIndexed(org.apache.lucene.document.Fieldable f)
          :TODO: document this method
 java.lang.String storedToReadable(org.apache.lucene.document.Fieldable f)
          :TODO: document this method
 java.lang.String toExternal(org.apache.lucene.document.Fieldable f)
          Convert the stored-field format to an external (string, human readable) value
 java.lang.String toInternal(java.lang.String val)
          Convert an external value (from XML update command or from query string) into the internal format.
 java.lang.String toString()
           
abstract  void write(TextResponseWriter writer, java.lang.String name, org.apache.lucene.document.Fieldable f)
          calls back to TextResponseWriter to write the field value
abstract  void write(XMLWriter xmlWriter, java.lang.String name, org.apache.lucene.document.Fieldable f)
          Renders the specified field as XML
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

public static final java.util.logging.Logger log

typeName

protected java.lang.String typeName
The name of the type (not the name of the field)


args

protected java.util.Map<java.lang.String,java.lang.String> args
additional arguments specified in the field type declaration


trueProperties

protected int trueProperties
properties explicitly set to true


falseProperties

protected int falseProperties
properties explicitly set to false


analyzer

protected org.apache.lucene.analysis.Analyzer analyzer
Analyzer set by schema for text types to use when indexing fields of this type, subclasses can set analyzer themselves or override getAnalyzer()

See Also:
getAnalyzer()

queryAnalyzer

protected org.apache.lucene.analysis.Analyzer queryAnalyzer
Analyzer set by schema for text types to use when searching fields of this type, subclasses can set analyzer themselves or override getAnalyzer()

See Also:
getQueryAnalyzer()
Constructor Detail

FieldType

public FieldType()
Method Detail

isTokenized

public boolean isTokenized()
Returns true if fields of this type should be tokenized


init

protected void init(IndexSchema schema,
                    java.util.Map<java.lang.String,java.lang.String> args)
subclasses should initialize themselves with the args provided and remove valid arguments. leftover arguments will cause an exception. Common boolean properties have already been handled.


restrictProps

protected void restrictProps(int props)
:TODO: document this method


getTypeName

public java.lang.String getTypeName()
The Name of this FieldType as specified in the schema file


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

createField

public org.apache.lucene.document.Field createField(SchemaField field,
                                                    java.lang.String externalVal,
                                                    float boost)
Used for adding a document when a field needs to be created from a type and a string.

By default, the indexed value is the same as the stored value (taken from toInternal()). Having a different representation for external, internal, and indexed would present quite a few problems given the current Lucene architecture. An analyzer for adding docs would need to translate internal->indexed while an analyzer for querying would need to translate external->indexed.

The only other alternative to having internal==indexed would be to have internal==external. In this case, toInternal should convert to the indexed representation, toExternal() should do nothing, and createField() should *not* call toInternal, but use the external value and set tokenized=true to get Lucene to convert to the internal(indexed) form.

:TODO: clean up and clarify this explanation.

See Also:
toInternal(java.lang.String)

getFieldTermVec

protected org.apache.lucene.document.Field.TermVector getFieldTermVec(SchemaField field,
                                                                      java.lang.String internalVal)

getFieldStore

protected org.apache.lucene.document.Field.Store getFieldStore(SchemaField field,
                                                               java.lang.String internalVal)

getFieldIndex

protected org.apache.lucene.document.Field.Index getFieldIndex(SchemaField field,
                                                               java.lang.String internalVal)

toInternal

public java.lang.String toInternal(java.lang.String val)
Convert an external value (from XML update command or from query string) into the internal format.

See Also:
toExternal(org.apache.lucene.document.Fieldable)

toExternal

public java.lang.String toExternal(org.apache.lucene.document.Fieldable f)
Convert the stored-field format to an external (string, human readable) value

See Also:
toInternal(java.lang.String)

indexedToReadable

public java.lang.String indexedToReadable(java.lang.String indexedForm)
:TODO: document this method


storedToReadable

public java.lang.String storedToReadable(org.apache.lucene.document.Fieldable f)
:TODO: document this method


storedToIndexed

public java.lang.String storedToIndexed(org.apache.lucene.document.Fieldable f)
:TODO: document this method


getAnalyzer

public org.apache.lucene.analysis.Analyzer getAnalyzer()
Returns the Analyzer to be used when indexing fields of this type.

This method may be called many times, at any time.

See Also:
getQueryAnalyzer()

getQueryAnalyzer

public org.apache.lucene.analysis.Analyzer getQueryAnalyzer()
Returns the Analyzer to be used when searching fields of this type.

This method may be called many times, at any time.

See Also:
getAnalyzer()

setAnalyzer

public void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
Sets the Analyzer to be used when indexing fields of this type.

See Also:
getAnalyzer()

setQueryAnalyzer

public void setQueryAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
Sets the Analyzer to be used when querying fields of this type.

See Also:
getQueryAnalyzer()

write

public abstract void write(XMLWriter xmlWriter,
                           java.lang.String name,
                           org.apache.lucene.document.Fieldable f)
                    throws java.io.IOException
Renders the specified field as XML

Throws:
java.io.IOException

write

public abstract void write(TextResponseWriter writer,
                           java.lang.String name,
                           org.apache.lucene.document.Fieldable f)
                    throws java.io.IOException
calls back to TextResponseWriter to write the field value

Throws:
java.io.IOException

getSortField

public abstract org.apache.lucene.search.SortField getSortField(SchemaField field,
                                                                boolean top)
Returns the SortField instance that should be used to sort fields of this type.


getStringSort

protected org.apache.lucene.search.SortField getStringSort(SchemaField field,
                                                           boolean reverse)
Utility usable by subclasses when they want to get basic String sorting.


getValueSource

public ValueSource getValueSource(SchemaField field)
called to get the default value source (normally, from the Lucene FieldCache.)



Copyright © 2006 - 2008 The Apache Software Foundation