现场配置

将自定义字段添加到 Lucene 索引时,可以使用以下配置将新字段添加到索引中:

 <configuration ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration">
  <indexAllfields>false</indexAllfields>
  <fieldNames hint="raw:AddFieldByFieldName">
      <field fieldName="title" storageType="YES" indexType="TOKENIZED"   vectorType="NO" boost="1f" type="System.String" 
             settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider"/>
  </fieldNames>
</configuration>

字段有几个可能的属性:

  • storageType
  • indexType
  • vectorType
  • boost

Tjhese 字段直接与 Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration 类的内容相关。如果我们反映出这个类的价值,我们可以看到它们的可能值等。

StorageType

/// <summary>Specifies whether and how a field should be stored. </summary>
public enum Store
{
    /// <summary>Store the original field value in the index. This is useful for short texts
    /// like a document's title which should be displayed with the results. The
    /// value is stored in its original form, i.e. no analyzer is used before it is
    /// stored.
    /// </summary>
    YES,
    /// <summary>Do not store the field value in the index. </summary>
    NO
}

IndexType

/// <summary>Specifies whether and how a field should be indexed. </summary>
public enum Index
{
    /// <summary>Do not index the field value. This field can thus not be searched,
    /// but one can still access its contents provided it is
    /// <see cref="T:Lucene.Net.Documents.Field.Store">stored</see>. 
    /// </summary>
    NO,
    /// <summary>Index the tokens produced by running the field's
    /// value through an Analyzer.  This is useful for
    /// common text. 
    /// </summary>
    ANALYZED,
    /// <summary>Index the field's value without using an Analyzer, so it can be searched.
    /// As no analyzer is used the value will be stored as a single term. This is
    /// useful for unique Ids like product numbers.
    /// </summary>
    NOT_ANALYZED,
    /// <summary>Expert: Index the field's value without an Analyzer,
    /// and also disable the storing of norms.  Note that you
    /// can also separately enable/disable norms by calling
    /// <see cref="!:AbstractField.SetOmitNorms" />.  No norms means that
    /// index-time field and document boosting and field
    /// length normalization are disabled.  The benefit is
    /// less memory usage as norms take up one byte of RAM
    /// per indexed field for every document in the index,
    /// during searching.  Note that once you index a given
    /// field <i>with</i> norms enabled, disabling norms will
    /// have no effect.  In other words, for this to have the
    /// above described effect on a field, all instances of
    /// that field must be indexed with NOT_ANALYZED_NO_NORMS
    /// from the beginning. 
    /// </summary>
    NOT_ANALYZED_NO_NORMS,
    /// <summary>Expert: Index the tokens produced by running the
    /// field's value through an Analyzer, and also
    /// separately disable the storing of norms.  See
    /// <see cref="F:Lucene.Net.Documents.Field.Index.NOT_ANALYZED_NO_NORMS" /> for what norms are
    /// and why you may want to disable them. 
    /// </summary>
    ANALYZED_NO_NORMS
}

VectorType

/// <summary>Specifies whether and how a field should have term vectors. </summary>
public enum TermVector
{
    /// <summary>Do not store term vectors. </summary>
    NO,
    /// <summary>Store the term vectors of each document. A term vector is a list
    /// of the document's terms and their number of occurrences in that document. 
    /// </summary>
    YES,
    /// <summary> Store the term vector + token position information
    ///
    /// </summary>
    /// <seealso cref="F:Lucene.Net.Documents.Field.TermVector.YES">
    /// </seealso>
    WITH_POSITIONS,
    /// <summary> Store the term vector + Token offset information
    ///
    /// </summary>
    /// <seealso cref="F:Lucene.Net.Documents.Field.TermVector.YES">
    /// </seealso>
    WITH_OFFSETS,
    /// <summary> Store the term vector + Token position and offset information
    ///
    /// </summary>
    /// <seealso cref="F:Lucene.Net.Documents.Field.TermVector.YES">
    /// </seealso>
    /// <seealso cref="F:Lucene.Net.Documents.Field.TermVector.WITH_POSITIONS">
    /// </seealso>
    /// <seealso cref="F:Lucene.Net.Documents.Field.TermVector.WITH_OFFSETS">
    /// </seealso>
    WITH_POSITIONS_OFFSETS
}

促进

为此项添加一个提升值到 Lucene 索引