Class PreAnalyzedField

All Implemented Interfaces:
HasImplicitIndexAnalyzer

public class PreAnalyzedField extends TextField implements HasImplicitIndexAnalyzer
Pre-analyzed field type provides a way to index a serialized token stream, optionally with an independent stored value of a field.
  • Field Details

  • Constructor Details

    • PreAnalyzedField

      public PreAnalyzedField()
  • Method Details

    • init

      public void init(IndexSchema schema, Map<String,String> args)
      Description copied from class: FieldType
      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.
      Overrides:
      init in class TextField
    • getIndexAnalyzer

      public org.apache.lucene.analysis.Analyzer getIndexAnalyzer()
      Overridden to return an analyzer consisting of a PreAnalyzedField.PreAnalyzedTokenizer. NOTE: If an index analyzer is specified in the schema, it will be ignored.
      Overrides:
      getIndexAnalyzer in class FieldType
      See Also:
    • getQueryAnalyzer

      public org.apache.lucene.analysis.Analyzer getQueryAnalyzer()
      Returns the query analyzer defined via the schema, unless there is none, in which case the index-time pre-analyzer is returned.

      Note that if the schema specifies an index-time analyzer via either <analyzer> or <analyzer type="index">, but no query-time analyzer, the query analyzer returned here will be the index-time analyzer specified in the schema rather than the pre-analyzer.

      Overrides:
      getQueryAnalyzer in class FieldType
      See Also:
    • createField

      public org.apache.lucene.index.IndexableField createField(SchemaField field, Object value)
      Description copied from class: FieldType
      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.

      Overrides:
      createField in class FieldType
      See Also:
    • getSortField

      public org.apache.lucene.search.SortField getSortField(SchemaField field, boolean top)
      Description copied from class: FieldType
      Returns the SortField instance that should be used to sort fields of this type.
      Overrides:
      getSortField in class TextField
      See Also:
    • getValueSource

      public org.apache.lucene.queries.function.ValueSource getValueSource(SchemaField field, QParser parser)
      Description copied from class: FieldType
      called to get the default value source (normally, from the Lucene FieldCache.)
      Overrides:
      getValueSource in class TextField
    • getUninversionType

      public UninvertingReader.Type getUninversionType(SchemaField sf)
      Description copied from class: FieldType
      If DocValues is not enabled for a field, but it's indexed, docvalues can be constructed on the fly (uninverted, aka fieldcache) on the first request to sort, facet, etc. This specifies the structure to use.

      This method will not be used if the field is (effectively) uninvertible="false"

      Overrides:
      getUninversionType in class TextField
      Parameters:
      sf - field instance
      Returns:
      type to uninvert, or null (to disallow uninversion for the field)
      See Also:
    • write

      public void write(TextResponseWriter writer, String name, org.apache.lucene.index.IndexableField f) throws IOException
      Description copied from class: FieldType
      calls back to TextResponseWriter to write the field value

      Sub-classes should prefer using FieldType.toExternal(IndexableField) or FieldType.toObject(IndexableField) to get the writeable external value of f instead of directly using f.stringValue() or f.binaryValue()

      Overrides:
      write in class TextField
      Throws:
      IOException
    • toFormattedString

      public String toFormattedString(org.apache.lucene.document.Field f) throws IOException
      Utility method to convert a field to a string that is parse-able by this class.
      Parameters:
      f - field to convert
      Returns:
      string that is compatible with the serialization format
      Throws:
      IOException - If there is a low-level I/O error.
    • createFieldType

      public static org.apache.lucene.document.FieldType createFieldType(SchemaField field)
      Utility method to create a FieldType based on the SchemaField
    • fromString

      public org.apache.lucene.index.IndexableField fromString(SchemaField field, String val) throws Exception
      Throws:
      Exception