博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FieldType in Lucene
阅读量:7055 次
发布时间:2019-06-28

本文共 11810 字,大约阅读时间需要 39 分钟。

hot3.png

Field在lucene中改变的还是比较大的, Field主要的实现都在FieldType中了。

package org.apache.lucene.document;/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */import org.apache.lucene.analysis.Analyzer; // javadocsimport org.apache.lucene.index.FieldInfo.DocValuesType;import org.apache.lucene.index.FieldInfo.IndexOptions;import org.apache.lucene.index.IndexableFieldType;import org.apache.lucene.search.NumericRangeQuery; // javadocsimport org.apache.lucene.util.NumericUtils;/** * Describes the properties of a field. */public class FieldType implements IndexableFieldType {  /** Data type of the numeric value   * @since 3.2   */  public static enum NumericType {    /** 32-bit integer numeric type */    INT,     /** 64-bit long numeric type */    LONG,     /** 32-bit float numeric type */    FLOAT,     /** 64-bit double numeric type */    DOUBLE  }  private boolean indexed;  private boolean stored;  private boolean tokenized = true;  private boolean storeTermVectors;  private boolean storeTermVectorOffsets;  private boolean storeTermVectorPositions;  private boolean storeTermVectorPayloads;  private boolean omitNorms;  private IndexOptions indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;  private NumericType numericType;  private boolean frozen;  private int numericPrecisionStep = NumericUtils.PRECISION_STEP_DEFAULT;  private DocValuesType docValueType;  /**   * Create a new mutable FieldType with all of the properties from ref   */  public FieldType(FieldType ref) {    this.indexed = ref.indexed();    this.stored = ref.stored();    this.tokenized = ref.tokenized();    this.storeTermVectors = ref.storeTermVectors();    this.storeTermVectorOffsets = ref.storeTermVectorOffsets();    this.storeTermVectorPositions = ref.storeTermVectorPositions();    this.storeTermVectorPayloads = ref.storeTermVectorPayloads();    this.omitNorms = ref.omitNorms();    this.indexOptions = ref.indexOptions();    this.docValueType = ref.docValueType();    this.numericType = ref.numericType();    // Do not copy frozen!  }    /**   * Create a new FieldType with default properties.   */  public FieldType() {  }  private void checkIfFrozen() {    if (frozen) {      throw new IllegalStateException("this FieldType is already frozen and cannot be changed");    }  }  /**   * Prevents future changes. Note, it is recommended that this is called once   * the FieldTypes's properties have been set, to prevent unintentional state   * changes.   */  public void freeze() {    this.frozen = true;  }    /**   * {@inheritDoc}   * 

* The default is false. * @see #setIndexed(boolean) */ @Override public boolean indexed() { return this.indexed; } /** * Set to true to index (invert) this field. * @param value true if this field should be indexed. * @throws IllegalStateException if this FieldType is frozen against * future modifications. * @see #indexed() */ public void setIndexed(boolean value) { checkIfFrozen(); this.indexed = value; } /** * {@inheritDoc} *

* The default is false. * @see #setStored(boolean) */ @Override public boolean stored() { return this.stored; } /** * Set to true to store this field. * @param value true if this field should be stored. * @throws IllegalStateException if this FieldType is frozen against * future modifications. * @see #stored() */ public void setStored(boolean value) { checkIfFrozen(); this.stored = value; } /** * {@inheritDoc} *

* The default is true. * @see #setTokenized(boolean) */ @Override public boolean tokenized() { return this.tokenized; } /** * Set to true to tokenize this field's contents via the * configured {@link Analyzer}. * @param value true if this field should be tokenized. * @throws IllegalStateException if this FieldType is frozen against * future modifications. * @see #tokenized() */ public void setTokenized(boolean value) { checkIfFrozen(); this.tokenized = value; } /** * {@inheritDoc} *

* The default is false. * @see #setStoreTermVectors(boolean) */ @Override public boolean storeTermVectors() { return this.storeTermVectors; } /** * Set to true if this field's indexed form should be also stored * into term vectors. * @param value true if this field should store term vectors. * @throws IllegalStateException if this FieldType is frozen against * future modifications. * @see #storeTermVectors() */ public void setStoreTermVectors(boolean value) { checkIfFrozen(); this.storeTermVectors = value; } /** * {@inheritDoc} *

* The default is false. * @see #setStoreTermVectorOffsets(boolean) */ @Override public boolean storeTermVectorOffsets() { return this.storeTermVectorOffsets; } /** * Set to true to also store token character offsets into the term * vector for this field. * @param value true if this field should store term vector offsets. * @throws IllegalStateException if this FieldType is frozen against * future modifications. * @see #storeTermVectorOffsets() */ public void setStoreTermVectorOffsets(boolean value) { checkIfFrozen(); this.storeTermVectorOffsets = value; } /** * {@inheritDoc} *

* The default is false. * @see #setStoreTermVectorPositions(boolean) */ @Override public boolean storeTermVectorPositions() { return this.storeTermVectorPositions; } /** * Set to true to also store token positions into the term * vector for this field. * @param value true if this field should store term vector positions. * @throws IllegalStateException if this FieldType is frozen against * future modifications. * @see #storeTermVectorPositions() */ public void setStoreTermVectorPositions(boolean value) { checkIfFrozen(); this.storeTermVectorPositions = value; } /** * {@inheritDoc} *

* The default is false. * @see #setStoreTermVectorPayloads(boolean) */ @Override public boolean storeTermVectorPayloads() { return this.storeTermVectorPayloads; } /** * Set to true to also store token payloads into the term * vector for this field. * @param value true if this field should store term vector payloads. * @throws IllegalStateException if this FieldType is frozen against * future modifications. * @see #storeTermVectorPayloads() */ public void setStoreTermVectorPayloads(boolean value) { checkIfFrozen(); this.storeTermVectorPayloads = value; } /** * {@inheritDoc} *

* The default is false. * @see #setOmitNorms(boolean) */ @Override public boolean omitNorms() { return this.omitNorms; } /** * Set to true to omit normalization values for the field. * @param value true if this field should omit norms. * @throws IllegalStateException if this FieldType is frozen against * future modifications. * @see #omitNorms() */ public void setOmitNorms(boolean value) { checkIfFrozen(); this.omitNorms = value; } /** * {@inheritDoc} *

* The default is {@link IndexOptions#DOCS_AND_FREQS_AND_POSITIONS}. * @see #setIndexOptions(org.apache.lucene.index.FieldInfo.IndexOptions) */ @Override public IndexOptions indexOptions() { return this.indexOptions; } /** * Sets the indexing options for the field: * @param value indexing options * @throws IllegalStateException if this FieldType is frozen against * future modifications. * @see #indexOptions() */ public void setIndexOptions(IndexOptions value) { checkIfFrozen(); this.indexOptions = value; } /** * Specifies the field's numeric type. * @param type numeric type, or null if the field has no numeric type. * @throws IllegalStateException if this FieldType is frozen against * future modifications. * @see #numericType() */ public void setNumericType(NumericType type) { checkIfFrozen(); numericType = type; } /** * NumericType: if non-null then the field's value will be indexed * numerically so that {@link NumericRangeQuery} can be used at * search time. *

* The default is null (no numeric type) * @see #setNumericType(NumericType) */ public NumericType numericType() { return numericType; } /** * Sets the numeric precision step for the field. * @param precisionStep numeric precision step for the field * @throws IllegalArgumentException if precisionStep is less than 1. * @throws IllegalStateException if this FieldType is frozen against * future modifications. * @see #numericPrecisionStep() */ public void setNumericPrecisionStep(int precisionStep) { checkIfFrozen(); if (precisionStep < 1) { throw new IllegalArgumentException("precisionStep must be >= 1 (got " + precisionStep + ")"); } this.numericPrecisionStep = precisionStep; } /** * Precision step for numeric field. *

* This has no effect if {@link #numericType()} returns null. *

* The default is {@link NumericUtils#PRECISION_STEP_DEFAULT} * @see #setNumericPrecisionStep(int) */ public int numericPrecisionStep() { return numericPrecisionStep; } /** Prints a Field for human consumption. */ @Override public final String toString() { StringBuilder result = new StringBuilder(); if (stored()) { result.append("stored"); } if (indexed()) { if (result.length() > 0) result.append(","); result.append("indexed"); if (tokenized()) { result.append(",tokenized"); } if (storeTermVectors()) { result.append(",termVector"); } if (storeTermVectorOffsets()) { result.append(",termVectorOffsets"); } if (storeTermVectorPositions()) { result.append(",termVectorPosition"); if (storeTermVectorPayloads()) { result.append(",termVectorPayloads"); } } if (omitNorms()) { result.append(",omitNorms"); } if (indexOptions != IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) { result.append(",indexOptions="); result.append(indexOptions); } if (numericType != null) { result.append(",numericType="); result.append(numericType); result.append(",numericPrecisionStep="); result.append(numericPrecisionStep); } } if (docValueType != null) { if (result.length() > 0) result.append(","); result.append("docValueType="); result.append(docValueType); } return result.toString(); } /** * {@inheritDoc} *

* The default is null (no docValues) * @see #setDocValueType(org.apache.lucene.index.FieldInfo.DocValuesType) */ @Override public DocValuesType docValueType() { return docValueType; } /** * Set's the field's DocValuesType * @param type DocValues type, or null if no DocValues should be stored. * @throws IllegalStateException if this FieldType is frozen against * future modifications. * @see #docValueType() */ public void setDocValueType(DocValuesType type) { checkIfFrozen(); docValueType = type; }}

 

 

转载于:https://my.oschina.net/u/138995/blog/179209

你可能感兴趣的文章
bootstrap提供了六种列表效果
查看>>
解决RPM包依赖的几种方法
查看>>
LAMP+LogAnalyzer日志服务器环境搭建
查看>>
访问控制列表(ACL)的应用实例
查看>>
split、replace、indexof、substr 用法 (获取后台富文本框内容,截取图片)
查看>>
怎样在 ubuntu 上安装 Linux 3.11 内核
查看>>
struts2配置
查看>>
bzoj 1067: [SCOI2007]降雨量
查看>>
我的友情链接
查看>>
ArcGIS 基础1-打开地图文档并浏览
查看>>
我的友情链接
查看>>
php 字符串分割函数split
查看>>
Bex5自动编号相关函数和用法
查看>>
机柜就是数据中心
查看>>
详解NetAppFAS3220数据恢复操作方法
查看>>
容器与依赖注入
查看>>
老男孩Linux运维决心书
查看>>
VIM常用快捷键
查看>>
网络交换机对无线网络中安全威胁的防御和缓解
查看>>
我的友情链接
查看>>