下面列出了怎么用org.apache.lucene.index.IndexableFieldType的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Create a new mutable FieldType with all of the properties from <code>ref</code>
*/
public FieldType(IndexableFieldType ref) {
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.docValuesType = ref.docValuesType();
this.dimensionCount = ref.pointDimensionCount();
this.indexDimensionCount = ref.pointIndexDimensionCount();
this.dimensionNumBytes = ref.pointNumBytes();
if (ref.getAttributes() != null) {
this.attributes = new HashMap<>(ref.getAttributes());
}
// Do not copy frozen!
}
/**
* Create field with Reader value.
* @param name field name
* @param reader reader value
* @param type field type
* @throws IllegalArgumentException if either the name or type
* is null, or if the field's type is stored(), or
* if tokenized() is false.
* @throws NullPointerException if the reader is null
*/
public Field(String name, Reader reader, IndexableFieldType type) {
if (name == null) {
throw new IllegalArgumentException("name must not be null");
}
if (type == null) {
throw new IllegalArgumentException("type must not be null");
}
if (reader == null) {
throw new NullPointerException("reader must not be null");
}
if (type.stored()) {
throw new IllegalArgumentException("fields with a Reader value cannot be stored");
}
if (type.indexOptions() != IndexOptions.NONE && !type.tokenized()) {
throw new IllegalArgumentException("non-tokenized fields must use String values");
}
this.name = name;
this.fieldsData = reader;
this.type = type;
}
/**
* Create field with TokenStream value.
* @param name field name
* @param tokenStream TokenStream value
* @param type field type
* @throws IllegalArgumentException if either the name or type
* is null, or if the field's type is stored(), or
* if tokenized() is false, or if indexed() is false.
* @throws NullPointerException if the tokenStream is null
*/
public Field(String name, TokenStream tokenStream, IndexableFieldType type) {
if (name == null) {
throw new IllegalArgumentException("name must not be null");
}
if (tokenStream == null) {
throw new NullPointerException("tokenStream must not be null");
}
if (type.indexOptions() == IndexOptions.NONE || !type.tokenized()) {
throw new IllegalArgumentException("TokenStream fields must be indexed and tokenized");
}
if (type.stored()) {
throw new IllegalArgumentException("TokenStream fields cannot be stored");
}
this.name = name;
this.fieldsData = null;
this.tokenStream = tokenStream;
this.type = type;
}
/**
* Create field with String value.
* @param name field name
* @param value string value
* @param type field type
* @throws IllegalArgumentException if either the name, value or type
* is null, or if the field's type is neither indexed() nor stored(),
* or if indexed() is false but storeTermVectors() is true.
*/
public Field(String name, CharSequence value, IndexableFieldType type) {
if (name == null) {
throw new IllegalArgumentException("name must not be null");
}
if (value == null) {
throw new IllegalArgumentException("value must not be null");
}
if (type == null) {
throw new IllegalArgumentException("type must not be null");
}
if (!type.stored() && type.indexOptions() == IndexOptions.NONE) {
throw new IllegalArgumentException("it doesn't make sense to have a field that "
+ "is neither indexed nor stored");
}
this.name = name;
this.fieldsData = value;
this.type = type;
}
/**
* Expert: creates a field with no initial value.
* Intended only for custom Field subclasses.
* @param name field name
* @param type field type
* @throws IllegalArgumentException if either the name or type
* is null.
*/
protected Field(String name, IndexableFieldType type) {
if (name == null) {
throw new IllegalArgumentException("name must not be null");
}
this.name = name;
if (type == null) {
throw new IllegalArgumentException("type must not be null");
}
this.type = type;
}
/**
* Create field with binary value.
*
* <p>NOTE: the provided BytesRef is not copied so be sure
* not to change it until you're done with this field.
* @param name field name
* @param bytes BytesRef pointing to binary content (not copied)
* @param type field type
* @throws IllegalArgumentException if the field name, bytes or type
* is null, or the field's type is indexed().
*/
public Field(String name, BytesRef bytes, IndexableFieldType type) {
if (name == null) {
throw new IllegalArgumentException("name must not be null");
}
if (bytes == null) {
throw new IllegalArgumentException("bytes must not be null");
}
if (type == null) {
throw new IllegalArgumentException("type must not be null");
}
this.name = name;
this.fieldsData = bytes;
this.type = type;
}
/** Expert API */
public BinaryPoint(String name, byte[] packedPoint, IndexableFieldType type) {
super(name, packedPoint, type);
if (packedPoint.length != type.pointDimensionCount() * type.pointNumBytes()) {
throw new IllegalArgumentException("packedPoint is length=" + packedPoint.length + " but type.pointDimensionCount()=" + type.pointDimensionCount() + " and type.pointNumBytes()=" + type.pointNumBytes());
}
}
@Override
protected IndexableField createField(String name, String val, IndexableFieldType type) {
if (val == null || val.isEmpty()) {
return null;
}
float featureValue;
try {
featureValue = Float.parseFloat(val);
} catch (NumberFormatException nfe) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error while creating field '" + name + "' from value '" + val + "'. Expecting float.", nfe);
}
// Internally, we always use the same field
return new FeatureField(INTERNAL_RANK_FIELD_NAME, name, featureValue);
}
@Override
public IndexableFieldType fieldType() {
return TYPE;
}
public IndexableFieldType getFieldType() {
return fieldType;
}
public void setNewField(NewField nf) {
this.nf = nf;
storedCB.setSelected(nf.isStored());
IndexableFieldType fieldType = nf.getFieldType();
tokenizedCB.setSelected(fieldType.tokenized());
omitNormsCB.setSelected(fieldType.omitNorms());
idxOptCombo.setSelectedItem(fieldType.indexOptions().name());
storeTVCB.setSelected(fieldType.storeTermVectors());
storeTVPosCB.setSelected(fieldType.storeTermVectorPositions());
storeTVOffCB.setSelected(fieldType.storeTermVectorOffsets());
storeTVPayCB.setSelected(fieldType.storeTermVectorPayloads());
dvTypeCombo.setSelectedItem(fieldType.docValuesType().name());
dimCountTF.setText(String.valueOf(fieldType.pointDimensionCount()));
dimNumBytesTF.setText(String.valueOf(fieldType.pointNumBytes()));
if (nf.getType().equals(org.apache.lucene.document.TextField.class) ||
nf.getType().equals(StringField.class) ||
nf.getType().equals(Field.class)) {
storedCB.setEnabled(true);
} else {
storedCB.setEnabled(false);
}
if (nf.getType().equals(Field.class)) {
tokenizedCB.setEnabled(true);
omitNormsCB.setEnabled(true);
idxOptCombo.setEnabled(true);
storeTVCB.setEnabled(true);
storeTVPosCB.setEnabled(true);
storeTVOffCB.setEnabled(true);
storeTVPosCB.setEnabled(true);
} else {
tokenizedCB.setEnabled(false);
omitNormsCB.setEnabled(false);
idxOptCombo.setEnabled(false);
storeTVCB.setEnabled(false);
storeTVPosCB.setEnabled(false);
storeTVOffCB.setEnabled(false);
storeTVPayCB.setEnabled(false);
}
// TODO
dvTypeCombo.setEnabled(false);
dimCountTF.setEnabled(false);
dimNumBytesTF.setEnabled(false);
}
@Override
public IndexableFieldType fieldType() {
return getRealValue().fieldType();
}
@Override
public IndexableFieldType fieldType() {
return StoredField.TYPE;
}
/** Returns the {@link FieldType} for this field. */
@Override
public IndexableFieldType fieldType() {
return type;
}
@Override
public IndexableFieldType fieldType() {
return searcher.getSchema().getField(name());
}
@Override
public IndexableFieldType fieldType() {
return TYPE;
}
private ObjectField(String name, Object object, IndexableFieldType type, float boost) {
this.name = name;
this.object = object;
this.type = type;
this.boost = boost;
}
@Override
public IndexableFieldType fieldType() {
return type;
}
@Override
public IndexableFieldType fieldType() {
return TYPE;
}
/**
* Create field with binary value.
*
* <p>NOTE: the provided byte[] is not copied so be sure
* not to change it until you're done with this field.
* @param name field name
* @param value byte array pointing to binary content (not copied)
* @param type field type
* @throws IllegalArgumentException if the field name, value or type
* is null, or the field's type is indexed().
*/
public Field(String name, byte[] value, IndexableFieldType type) {
this(name, value, 0, value.length, type);
}
/**
* Create field with binary value.
*
* <p>NOTE: the provided byte[] is not copied so be sure
* not to change it until you're done with this field.
* @param name field name
* @param value byte array pointing to binary content (not copied)
* @param offset starting position of the byte array
* @param length valid length of the byte array
* @param type field type
* @throws IllegalArgumentException if the field name, value or type
* is null, or the field's type is indexed().
*/
public Field(String name, byte[] value, int offset, int length, IndexableFieldType type) {
this(name, value != null ? new BytesRef(value, offset, length) : null, type);
}